Ejemplo n.º 1
0
        public object ExportGLTFExtension <T1, T2>(T1 babylonObject, ref T2 gltfObject, ref GLTF gltf, GLTFExporter exporter, ExtensionInfo info)
        {
            var babylonCamera = babylonObject as BabylonCamera;
            var gltfAnimation = gltfObject as GLTFAnimation;
            AnimationExtensionInfo animationExtensionInfo = info as AnimationExtensionInfo;

            if (babylonCamera == null)
            {
                return(null);
            }

            Guid guid = Guid.Empty;

            Guid.TryParse(babylonCamera.id, out guid);
            IINode camNode = Tools.GetINodeByGuid(guid);

            var maxCamera = CameraUtilities.GetGenCameraFromNode(camNode, exporter.logger);

            if (maxCamera == null)
            {
                exporter.logger.RaiseError($"Impossible to export {FlightSimAsoboPropertyAnimationExtension.SerializedName} for {camNode.Name}, camera node must be a TargetCamera type");
                return(null);
            }

            if (babylonCamera != null && gltfAnimation != null && FlightSimCameraUtilities.class_ID.Equals(new MaterialUtilities.ClassIDWrapper(maxCamera.ClassID)))
            {
                GLTFNode   gltfNode   = null;
                GLTFCamera gltfCamera = null;
                if (!exporter.nodeToGltfNodeMap.TryGetValue(babylonCamera, out gltfNode))
                {
                    return(gltfObject);
                }
                if (gltfNode != null && gltfNode.camera >= 0)
                {
                    gltfCamera = gltf.CamerasList[gltfNode.camera.GetValueOrDefault()];
                }

                int samplerIndex = AddParameterSamplerAnimation(babylonCamera, gltfAnimation, exporter, gltf, animationExtensionInfo.startFrame, animationExtensionInfo.endFrame);
                if (samplerIndex > -1)
                {
                    GLTFExtensionAsoboPropertyAnimation gltfExtension             = new GLTFExtensionAsoboPropertyAnimation();
                    List <GLTFAnimationPropertyChannel> animationPropertyChannels = new List <GLTFAnimationPropertyChannel>();

                    //TODO: for each animated property in the camera
                    //TODO: this should be generated based on the property itself
                    GLTFAnimationPropertyChannel propertyChannel = new GLTFAnimationPropertyChannel();
                    propertyChannel.sampler = samplerIndex;

                    propertyChannel.target = $"cameras/{gltfCamera.index}/perspective/yfov";

                    animationPropertyChannels.Add(propertyChannel);

                    gltfExtension.channels = animationPropertyChannels.ToArray();
                    return(gltfExtension);
                }
            }

            return(null);
        }