コード例 #1
0
        public static IPoint4 GetPoint4Property(this IIGameProperty property)
        {
            IPoint4 value = Loader.Global.Point4.Create(0, 0, 0, 0);

            property.GetPropertyValue(value, 0);
            return(value);
        }
コード例 #2
0
        public static string GetStringProperty(this IIGameProperty property)
        {
            string value = "";

            property.GetPropertyValue(ref value, 0);
            return(value);
        }
コード例 #3
0
        private BabylonCamera ExportCameraAnimations(BabylonCamera babylonCamera, IIGameCamera camera, BabylonExporter exporter)
        {
            var animations = new List <BabylonAnimation>();

            int numProps = camera.IPropertyContainer.NumberOfProperties;

            for (int i = 0; i < numProps; ++i)
            {
                IIGameProperty property = camera.IPropertyContainer.GetProperty(i);

                if (property == null)
                {
                    continue;
                }

                IParamDef paramDef     = property.MaxParamBlock2?.GetParamDef(property.ParamID);
                string    propertyName = property.Name.ToUpperInvariant();

                switch (propertyName)
                {
                default:
                    break;
                }
            }

            babylonCamera.animations = animations.ToArray();
            return(babylonCamera);
        }
コード例 #4
0
        public static float GetFloatValue(this IIGameProperty property)
        {
            float value = 0.0f;

            property.GetPropertyValue(ref value, 0, true);
            return(value);
        }
コード例 #5
0
        public static int GetIntValue(this IIGameProperty property)
        {
            int value = 0;

            property.GetPropertyValue(ref value, 0);
            return(value);
        }
コード例 #6
0
        private IIGameMaterial GetRenderMaterialFromDirectXShader(IIGameMaterial materialNode)
        {
            IIGameMaterial renderMaterial = null;

            if (isDirectXShaderMaterial(materialNode))
            {
                var            gameScene = Loader.Global.IGameInterface;
                IIGameProperty property  = materialNode.IPropertyContainer.GetProperty(35);
                if (property != null)
                {
                    IMtl renderMtl = materialNode.IPropertyContainer.GetProperty(35).MaxParamBlock2.GetMtl(4, 0, 0);
                    if (renderMtl != null)
                    {
                        renderMaterial = gameScene.GetIGameMaterial(renderMtl);
                    }
                }
                else
                {
                    RaiseWarning($"DirectX material property for {materialNode.MaterialName} is null...", 2);
                }
            }

            return(renderMaterial);
        }
コード例 #7
0
        public static float GetFloatMaterialProperty(this IIGameMaterial material, string propName, int key, IInterval interval)
        {
            float result = 0;

            for (int i = 0; i < material.IPropertyContainer.NumberOfProperties; ++i)
            {
                IIGameProperty property = material.IPropertyContainer.GetProperty(i);

                if (property == null)
                {
                    continue;
                }


                string propertyName = property.Name.ToUpperInvariant();
                string targetProp   = propName.ToUpperInvariant();
                if (propertyName == targetProp)
                {
                    property.GetPropertyValue(ref result, key, true);
                }
            }

            return(result);
        }
コード例 #8
0
 public static bool GetBoolValue(this IIGameProperty property)
 {
     return(property.GetIntValue() == 1);
 }
コード例 #9
0
        /// <summary>
        /// Return custom attributes retreive from a max object named "obj"
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="propertyContainer"></param>
        /// <param name="babylonScene"></param>
        /// <param name="excludeAttributes">Attribute names to not export</param>
        private Dictionary <string, object> _ExportExtraAttributes(IIPropertyContainer propertyContainer, BabylonScene babylonScene, List <string> excludeAttributes = null)
        {
            logger?.RaiseMessage("ExportExtraAttributes", 2);

            // Return a string encoded with 2 separators
            // Parameter separator: _$€PParam_
            // Name/Type separator: _$€PType_
            string cmd = "s = \"\""
                         + "\r\n" + "for objDef in (custAttributes.getDefs obj) do"
                         + "\r\n" + "("
                         + "\r\n" + "pbArray = custAttributes.getPBlockDefs objdef"
                         + "\r\n" + "for indexPBlock = 1 to pbArray.count do"
                         + "\r\n" + "("
                         + "\r\n" + "itms = pbArray[indexPBlock]"
                         + "\r\n" + "for y = 5 to itms.Count do"
                         + "\r\n" + "("
                         + "\r\n" + "s = s + \"_$€PParam_\" + itms[y][1]"
                         + "\r\n" + "for z = 1 to itms[y][2].Count by 2 do"
                         + "\r\n" + "("
                         + "\r\n" + "key = itms[y][2][z] as string"
                         + "\r\n" + "if (findString key \"type\") != undefined then"
                         + "\r\n" + "("
                         + "\r\n" + "s = s + \"_$€PType_\" + itms[y][2][z+1]"
                         + "\r\n" + ")"
                         + "\r\n" + ")"
                         + "\r\n" + ")"
                         + "\r\n" + ")"
                         + "\r\n" + ")"
                         + "\r\n" + "s";
            string result = ScriptsUtilities.ExecuteMaxScriptQuery(cmd);

            if (result == null || result == "")
            {
                return(null);
            }

            // Parse the result into a dictionary
            string[] parameters = result.Split(new string[] { "_$€PParam_" }, StringSplitOptions.RemoveEmptyEntries);
            Dictionary <string, string> customAttributesTypeByName = new Dictionary <string, string>();

            foreach (string parameter in parameters)
            {
                string[] customAttribute = parameter.Split(new string[] { "_$€PType_" }, StringSplitOptions.RemoveEmptyEntries);
                string   key             = customAttribute[0];
                if (customAttributesTypeByName.ContainsKey(key) == false)
                {
                    customAttributesTypeByName.Add(key, customAttribute[1]);
                }
            }

            // Remove preset custom attributes
            customAttributesTypeByName.Remove("presetName_str");
            customAttributesTypeByName.Remove("preset_str");
            customAttributesTypeByName.Remove("rampOn");

            // Remove specified attributes
            if (excludeAttributes != null)
            {
                foreach (string excludeAttribute in excludeAttributes)
                {
                    customAttributesTypeByName.Remove(excludeAttribute);
                }
            }

            // Handle each attribute type
            Dictionary <string, object> metadata = new Dictionary <string, object>();

            foreach (KeyValuePair <string, string> entry in customAttributesTypeByName)
            {
                object obj = null;

                logger?.RaiseMessage(entry.Key + "=" + entry.Value, 2);

                switch (entry.Value.ToLowerInvariant())
                {
                case "float":
                case "angle":     // in rad units
                case "worldunits":
                    obj = propertyContainer.GetFloatProperty(entry.Key);
                    break;

                case "percent":     // in base 1 (80% => 0.8)
                    obj = propertyContainer.GetFloatProperty(entry.Key) / 100f;
                    break;

                case "boolean":
                    obj = propertyContainer.GetBoolProperty(entry.Key);
                    break;

                case "integer":
                case "array":     // selected enum value expressed as int starting from 1
                    obj = propertyContainer.GetIntProperty(entry.Key);
                    break;

                case "string":
                    obj = propertyContainer.GetStringProperty(entry.Key);
                    break;

                case "color":     // Color RGB in base 1 (not 255)
                    obj = propertyContainer.GetPoint3Property(entry.Key).ToArray();
                    break;

                case "frgba":     // Color RGBA in base 1 (not 255)
                    obj = propertyContainer.GetPoint4Property(entry.Key).ToArray();
                    break;

                case "texturemap":
                    IIGameProperty gameProperty = propertyContainer.QueryProperty(entry.Key);
                    ITexmap        texmap       = gameProperty.MaxParamBlock2.GetTexmap(gameProperty.ParamID, 0, 0);
                    obj = ExportTexture(texmap, babylonScene);
                    break;

                case "node":
                    // Currently not exported
                    break;

                case "material":
                    // Currently not exported
                    break;

                default:
                    logger?.RaiseWarning("Unknown type '" + entry.Value + "' for custom attribute named '" + entry.Key + "'", 2);
                    break;
                }

                if (obj != null)
                {
                    metadata.Add(entry.Key, obj);
                }
            }

            // Print all extra attributes
            foreach (KeyValuePair <string, object> entry in metadata)
            {
                logger?.RaiseVerbose(entry.Key + "=" + entry.Value, 2);
            }

            return(metadata);
        }
コード例 #10
0
        private BabylonMaterial ExportMaterialAnimations(BabylonMaterial babylonMaterial, IIGameMaterial material, BabylonExporter exporter)
        {
            var animations = new List <BabylonAnimation>();

            int numProps = material.IPropertyContainer.NumberOfProperties;

            for (int i = 0; i < numProps; ++i)
            {
                IIGameProperty property = material.IPropertyContainer.GetProperty(i);

                if (property == null)
                {
                    continue;
                }

                if (!property.IsPropAnimated)
                {
                    continue;
                }

                IParamDef paramDef     = property.MaxParamBlock2?.GetParamDef(property.ParamID);
                string    propertyName = property.Name.ToUpperInvariant();

                switch (propertyName)
                {
                case "BASECOLOR":
                {
                    if (property.IGameControl.GetMaxControl(IGameControlType.Point4).NumKeys > 0)
                    {
                        exporter.ExportColor4Animation(property.Name, animations,
                                                       key => material.IPropertyContainer.GetPoint4Property(property.Name, key).ToArray());
                    }
                    break;
                }

                case "EMISSIVE":
                {
                    if (property.IGameControl.GetMaxControl(IGameControlType.Point3).NumKeys > 0)
                    {
                        exporter.ExportColor3Animation(property.Name, animations,
                                                       key => material.IPropertyContainer.GetPoint3Property(property.Name, key).ToArray());
                    }
                    break;
                }

                case "WIPERANIMSTATE1":
                case "WIPERANIMSTATE2":
                case "WIPERANIMSTATE3":
                case "WIPERANIMSTATE4":
                case "METALLIC":
                case "ROUGHNESS":
                case "UVOFFSETU":
                case "UVOFFSETV":
                case "UVTILINGU":
                case "UVTILINGV":
                case "UVROTATION":
                {
                    if (property.IGameControl.GetMaxControl(IGameControlType.Float).NumKeys > 0)
                    {
                        exporter.ExportFloatAnimation(property.Name, animations,
                                                      key => new[] { material.IPropertyContainer.GetFloatProperty(property.Name, key, 0) });
                    }
                    break;
                }

                default:
                    break;
                }
            }

            babylonMaterial.animations = animations.ToArray();
            return(babylonMaterial);
        }
コード例 #11
0
        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);
        }