-
Notifications
You must be signed in to change notification settings - Fork 494
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
Added camera export #153
Conversation
@@ -97,7 +99,8 @@ public void SaveGLTFandBin(string path, string fileName) | |||
binFile.Close(); | |||
#endif | |||
|
|||
foreach (var image in _images) | |||
GL.sRGBWrite = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit- spaces
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
I would like to point to this issue on the Camera classes: (#156). |
See #158 |
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!