Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added camera export #153

Closed
wants to merge 2 commits into from
Closed

Conversation

ziedbha
Copy link
Contributor

@ziedbha ziedbha commented Mar 30, 2018

Started to add the camera export feature.
I had a few questions though: for orthographic projection, what do we mean by the x and y magnifications? I am unsure how to map the Unity orthographicSize and Viewport settings for the camera to the xMag and yMag. Any thoughts?

In addition, Unity seems to add other options to the camera model: rendering depth, occlusion culling, clear flags, background, target display, etc.. Do we handle those in the Extra/Extensions, or do we just export what is required from the specs?

Thanks for reviewing this!

@@ -97,7 +99,8 @@ public void SaveGLTFandBin(string path, string fileName)
binFile.Close();
#endif

foreach (var image in _images)
GL.sRGBWrite = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit- spaces

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't commit your changes from your other PR as part of this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the rookie mistake of committing the other PR into master. Will fix this. Thanks for pointing this out!!

UnityEngine.Camera unityCamera = nodeTransform.GetComponent<UnityEngine.Camera>();
if (unityCamera != null)
{
//should we only export enabled cameras?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment. I think we should export all cameras

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!

@@ -179,6 +191,49 @@ private NodeId ExportNode(Transform nodeTransform)
return id;
}

private CameraId exportCamera(UnityEngine.Camera unityCamera)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize ExportCamera

//matrix
if (isOrthographic)
{
GLTF.Schema.CameraOrthographic ortho = new GLTF.Schema.CameraOrthographic();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Unity doesn't directly show the properties, and since scripts can still modify properties of the matrix, I recommend just getting values of the matrix directly:
https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#projection-matrices

May as well do this for both perspective and orthographic. This is likely the solution for camera import as well (which you should feel free to tackle :D) #2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! Sounds like a safer way to do it :)

ortho.ZNear = unityCamera.nearClipPlane;
//x and y magnifications: Unity uses a combination of viewport size and origin, as well as "orthographic size"
//unsure how to combine these to get the xMag and yMag
ortho.XMag = unityCamera.orthographicSize;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the raw matrix and xMag is not equal to orthographic size. yMag is though. xMag is being set based on viewport variables. Like I said above, we should just calculate the values specified from the standard based on the camera.perspectiveMatrix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, your idea is definitely the safest!! Thanks for this.

@jasperdrescher
Copy link
Contributor

I would like to point to this issue on the Camera classes: (#156).

@ziedbha ziedbha closed this Apr 6, 2018
@ziedbha ziedbha deleted the camera-export branch April 6, 2018 01:10
@ziedbha
Copy link
Contributor Author

ziedbha commented Apr 6, 2018

See #158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants