Example #1
0
        public static IPoint4 GetPoint4Property(this IIPropertyContainer propertyContainer, int indexProperty)
        {
            IPoint4 value = Loader.Global.Point4.Create(0, 0, 0, 0);

            propertyContainer.GetProperty(indexProperty).GetPropertyValue(value, 0);
            return(value);
        }
Example #2
0
        public static string GetStringProperty(this IIPropertyContainer propertyContainer, int indexProperty)
        {
            string value = "";

            propertyContainer.GetProperty(indexProperty).GetPropertyValue(ref value, 0);
            return(value);
        }
Example #3
0
        public static int GetIntProperty(this IIPropertyContainer propertyContainer, int indexProperty)
        {
            int value = 0;

            propertyContainer.GetProperty(indexProperty).GetPropertyValue(ref value, 0);
            return(value);
        }
Example #4
0
        public static float GetFloatProperty(this IIPropertyContainer propertyContainer, int indexProperty)
        {
            float value = 0.0f;

            propertyContainer.GetProperty(indexProperty).GetPropertyValue(ref value, 0, true);
            return(value);
        }
Example #5
0
        public void Print(IIPropertyContainer propertyContainer, int logRank)
        {
            RaiseVerbose("propertyContainer=" + propertyContainer, logRank);
            if (propertyContainer != null)
            {
                RaiseVerbose("propertyContainer.NumberOfProperties=" + propertyContainer.NumberOfProperties, logRank + 1);
                for (int i = 0; i < propertyContainer.NumberOfProperties; i++)
                {
                    var prop = propertyContainer.GetProperty(i);
                    if (prop != null)
                    {
                        RaiseVerbose("propertyContainer.GetProperty(" + i + ")=" + prop.Name, logRank + 1);
                        switch (prop.GetType_)
                        {
                        case PropType.StringProp:
                            string propertyString = "";
                            RaiseVerbose("prop.GetPropertyValue(ref propertyString, 0)=" + prop.GetPropertyValue(ref propertyString, 0), logRank + 2);
                            RaiseVerbose("propertyString=" + propertyString, logRank + 2);
                            break;

                        case PropType.IntProp:
                            int propertyInt = 0;
                            RaiseVerbose("prop.GetPropertyValue(ref propertyInt, 0)=" + prop.GetPropertyValue(ref propertyInt, 0), logRank + 2);
                            RaiseVerbose("propertyInt=" + propertyInt, logRank + 2);
                            break;

                        case PropType.FloatProp:
                            float propertyFloat = 0;
                            RaiseVerbose("prop.GetPropertyValue(ref propertyFloat, 0, true)=" + prop.GetPropertyValue(ref propertyFloat, 0, true), logRank + 2);
                            RaiseVerbose("propertyFloat=" + propertyFloat, logRank + 2);
                            RaiseVerbose("prop.GetPropertyValue(ref propertyFloat, 0, false)=" + prop.GetPropertyValue(ref propertyFloat, 0, false), logRank + 2);
                            RaiseVerbose("propertyFloat=" + propertyFloat, logRank + 2);
                            break;

                        case PropType.Point3Prop:
                            IPoint3 propertyPoint3 = Loader.Global.Point3.Create(0, 0, 0);
                            RaiseVerbose("prop.GetPropertyValue(ref propertyPoint3, 0)=" + prop.GetPropertyValue(propertyPoint3, 0), logRank + 2);
                            RaiseVerbose("propertyPoint3=" + Point3ToString(propertyPoint3), logRank + 2);
                            break;

                        case PropType.Point4Prop:
                            IPoint4 propertyPoint4 = Loader.Global.Point4.Create(0, 0, 0, 0);
                            RaiseVerbose("prop.GetPropertyValue(ref propertyPoint4, 0)=" + prop.GetPropertyValue(propertyPoint4, 0), logRank + 2);
                            RaiseVerbose("propertyPoint4=" + Point4ToString(propertyPoint4), logRank + 2);
                            break;

                        case PropType.UnknownProp:
                        default:
                            RaiseVerbose("Unknown property type", logRank + 2);
                            break;
                        }
                    }
                    else
                    {
                        RaiseVerbose("propertyContainer.GetProperty(" + i + ") IS NULL", logRank + 1);
                    }
                }
            }
        }
Example #6
0
 public static bool GetBoolProperty(this IIPropertyContainer propertyContainer, int indexProperty)
 {
     return(propertyContainer.GetIntProperty(indexProperty) == 1);
 }
Example #7
0
 public static IPoint4 GetPoint4Property(this IIPropertyContainer propertyContainer, int indexProperty)
 {
     return(propertyContainer.GetProperty(indexProperty).GetPoint4Property());
 }
Example #8
0
 public static float GetFloatProperty(this IIPropertyContainer propertyContainer, int indexProperty)
 {
     return(propertyContainer.GetProperty(indexProperty).GetFloatValue());
 }
Example #9
0
 public static bool GetBoolProperty(this IIPropertyContainer propertyContainer, int indexProperty)
 {
     return(propertyContainer.GetProperty(indexProperty).GetBoolValue());
 }
Example #10
0
 public static string GetStringProperty(this IIPropertyContainer propertyContainer, int indexProperty)
 {
     return(propertyContainer.GetProperty(indexProperty).GetStringProperty());
 }
Example #11
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);
        }