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); }
public object ExportGLTFExtension <T1, T2>(T1 babylonObject, ref T2 gltfObject, ref GLTF gltf, GLTFExporter exporter, ExtensionInfo info) { var babylonMaterial = babylonObject as BabylonMaterial; var gltfAnimation = gltfObject as GLTFAnimation; AnimationExtensionInfo animationExtensionInfo = info as AnimationExtensionInfo; if (babylonMaterial == null) { return(null); } if (gltfAnimation != null && FlightSimMaterialUtilities.class_ID.Equals(new MaterialUtilities.ClassIDWrapper(babylonMaterial.maxGameMaterial.MaxMaterial.ClassID))) { GLTFMaterial gltfMaterial; if (!exporter.materialToGltfMaterialMap.TryGetValue(babylonMaterial, out gltfMaterial)) { return(gltfObject); } int samlerIndex = gltfAnimation.SamplerList.Count; AddParameterSamplerAnimation(babylonMaterial, gltfAnimation, exporter, gltf, animationExtensionInfo.startFrame, animationExtensionInfo.endFrame); GLTFExtensionAsoboPropertyAnimation gltfExtension = new GLTFExtensionAsoboPropertyAnimation(); //in case more material are animated in the same animation group // the extension used on the animation need to be stored if (gltfAnimation.extensions != null && gltfAnimation.extensions.Count > 0) { foreach (KeyValuePair <string, object> ext in gltfAnimation.extensions) { if (ext.Key == FlightSimAsoboPropertyAnimationExtension.SerializedName) { gltfExtension = (GLTFExtensionAsoboPropertyAnimation)ext.Value; } } } List <GLTFAnimationPropertyChannel> matAnimationsPropertyChannels = new List <GLTFAnimationPropertyChannel>(); if (gltfExtension.channels != null) { matAnimationsPropertyChannels.AddRange(gltfExtension.channels); } IIGameProperty property = babylonMaterial.maxGameMaterial.IPropertyContainer.QueryProperty("materialType"); int material_value = 0; if (!property.GetPropertyValue(ref material_value, 0)) { return(null); } MaterialType materialType = FlightSimMaterialHelper.GetMaterialType(material_value); foreach (BabylonAnimation anim in babylonMaterial.animations) { GLTFAnimationPropertyChannel propertyChannel = new GLTFAnimationPropertyChannel(); propertyChannel.sampler = samlerIndex; if (materialType == MaterialType.Windshield && anim.property == "wiperAnimState1") { propertyChannel.target = $"materials/{gltfMaterial.index}/extensions/{GLTFExtensionAsoboWindshield.SerializedName}/wiper1State"; } else if (materialType == MaterialType.Windshield && anim.property == "wiperAnimState2") { propertyChannel.target = $"materials/{gltfMaterial.index}/extensions/{GLTFExtensionAsoboWindshield.SerializedName}/wiper2State"; } else if (materialType == MaterialType.Windshield && anim.property == "wiperAnimState3") { propertyChannel.target = $"materials/{gltfMaterial.index}/extensions/{GLTFExtensionAsoboWindshield.SerializedName}/wiper3State"; } else if (materialType == MaterialType.Windshield && anim.property == "wiperAnimState4") { propertyChannel.target = $"materials/{gltfMaterial.index}/extensions/{GLTFExtensionAsoboWindshield.SerializedName}/wiper4State"; } else if (materialType == MaterialType.Standard && anim.property == "emissive") { propertyChannel.target = $"materials/{gltfMaterial.index}/emissiveFactor"; } else if (materialType == MaterialType.Standard && anim.property == "baseColor") { propertyChannel.target = $"materials/{gltfMaterial.index}/pbrMetallicRoughness/baseColorFactor"; } else if (materialType == MaterialType.Standard && anim.property == "roughness") { propertyChannel.target = $"materials/{gltfMaterial.index}/pbrMetallicRoughness/roughnessFactor"; } else if (materialType == MaterialType.Standard && anim.property == "metallic") { propertyChannel.target = $"materials/{gltfMaterial.index}/pbrMetallicRoughness/metallicFactor"; } else if (materialType != MaterialType.EnvironmentOccluder && anim.property == "UVOffsetU") { propertyChannel.target = $"materials/{gltfMaterial.index}/extensions/{GLTFExtensionAsoboMaterialUVOptions.SerializedName}/UVOffsetU"; } else if (materialType != MaterialType.EnvironmentOccluder && anim.property == "UVOffsetV") { propertyChannel.target = $"materials/{gltfMaterial.index}/extensions/{GLTFExtensionAsoboMaterialUVOptions.SerializedName}/UVOffsetV"; } else if (materialType != MaterialType.EnvironmentOccluder && anim.property == "UVTilingU") { propertyChannel.target = $"materials/{gltfMaterial.index}/extensions/{GLTFExtensionAsoboMaterialUVOptions.SerializedName}/UVTilingU"; } else if (materialType != MaterialType.EnvironmentOccluder && anim.property == "UVTilingV") { propertyChannel.target = $"materials/{gltfMaterial.index}/extensions/{GLTFExtensionAsoboMaterialUVOptions.SerializedName}/UVTilingV"; } else if (materialType != MaterialType.EnvironmentOccluder && anim.property == "UVRotation") { propertyChannel.target = $"materials/{gltfMaterial.index}/extensions/{GLTFExtensionAsoboMaterialUVOptions.SerializedName}/UVRotation"; } if (propertyChannel.isValid()) { matAnimationsPropertyChannels.Add(propertyChannel); samlerIndex += 1; } } gltfExtension.channels = matAnimationsPropertyChannels.ToArray(); return(gltfExtension); } return(null); }