/// <summary>
        /// Adds the Shell modifier to the provided node (by handle).
        /// </summary>
        /// <param name="nodeHandle"> Input the node handle to add the modifier to. </param>
        /// <param name="shellAmount"> Input the amount of shell thickness as float. </param>
        /// <returns> Returns 1 if successful or -1 if not. </returns>
        static public int AddOsmShell(uint nodeHandle, float shellAmount)
        {
            try
            {
                IGlobal      global = Autodesk.Max.GlobalInterface.Instance;
                IInterface14 ip     = global.COREInterface14;

                IClass_ID cidOsmShell = global.Class_ID.Create(0x3b9b1a16, 0x6d84e8d0);
                AddOsmModifier(nodeHandle, cidOsmShell);

                IINode    node = ip.GetINodeByHandle(nodeHandle);
                IModifier mod  = GetModifier(node, cidOsmShell);
                if (mod != null)
                {
                    IIParamBlock2 pb = mod.GetParamBlock(0);
                    pb.SetValue(0, 0, shellAmount, 0); // innerAmount parameter is at index zero of the parameter block.
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
                return(-1);
            }

            return(1);
        }
Beispiel #2
0
        private BabylonFurMaterial ExportFurModifier(IModifier modifier, String sourceMeshName, BabylonScene babylonScene)
        {
            RaiseMessage("Export Fur Modifier", 2);
            var paramBlock = modifier.GetParamBlock(0);

            // 3dsMax "Cut Length" is in percentages - "100%" will be "20" babylon spacing
            // (babylon Fur length means the distance from the obj, while the length of the hair is the spacing)
            var cutLength = paramBlock.GetFloat(CUT_LENGTH_PARAM_ID, 0, 0);
            var spacing   = (int)Math.Round(cutLength / 5);

            // 3dsMax "Root Thick" is in percentages - "100%" will be "1" babylon density
            // (lower density in babylon is thicker hair - lower root thick in 3dsMax is thinner)
            var rootThickness = paramBlock.GetFloat(ROOT_THICKNESS_PARAM_ID, 0, 0);
            var density       = (int)Math.Ceiling((100.1f - rootThickness) / 5);

            var rootColor = paramBlock.GetColor(ROOT_COLOR_PARAM_ID, 0, 0);
            var furColor  = new float[] { rootColor.R, rootColor.G, rootColor.B };

            if (paramBlock.GetTexmap(MAPS_PARAM_ID, 0, 11) != null)
            {
                RaiseWarning("Tip texture is not supported. Use root texture instead", 2);
            }

            BabylonTexture diffuseTexture  = null;
            ITexmap        rootColorTexmap = paramBlock.GetTexmap(MAPS_PARAM_ID, 0, 14);

            if (rootColorTexmap != null)
            {
                diffuseTexture       = ExportTexture(rootColorTexmap, 0f, babylonScene);
                diffuseTexture.level = 1;
            }

            return(new BabylonFurMaterial
            {
                id = modifier.GetGuid().ToString(),
                name = modifier.GetGuid().ToString(),
                sourceMeshName = sourceMeshName,
                furDensity = density,
                furSpacing = spacing,
                diffuseTexture = diffuseTexture,
                furColor = furColor,
            });
        }
        /// <summary>
        /// Adds the Shell modifier to the provided node (by handle).
        /// </summary>
        /// <param name="nodeHandle"> Input the node handle to add the modifier to. </param>
        /// <param name="shellAmount"> Input the amount of shell thickness as float. </param>
        /// <returns> Returns 1 if successful or -1 if not. </returns>
        static public int AddOsmProoptimizer(IINode node, float VertexPercent, bool KeepNormals)
        {
            try
            {
                IGlobal      global = Autodesk.Max.GlobalInterface.Instance;
                IInterface14 ip     = global.COREInterface14;
                int          t      = ip.Time;

                // classID:#(1056067556, 1496462090)
                IClass_ID cidOsmProoptimizer = global.Class_ID.Create(0x3EF24FE4, 0x5932330A);
                AddOsmModifier(node, cidOsmProoptimizer);

                IModifier mod = GetModifier(node, cidOsmProoptimizer);
                if (mod != null)
                {
                    // In order to get the "Calculate" parameter to trigger the modifier to execute, we have to enable some UI elements.
                    ip.CmdPanelOpen = true;      // ensures the command panel in general is open
                    ip.SelectNode(node, true);   // Select the node to make it active
                    ip.CommandPanelTaskMode = 2; // TASK_MODE_MODIFY. This makes the modifier panel active.
                    // Now we can set the parameters on the modifier, and at end "calculate" the results.
                    IIParamBlock2 pb = mod.GetParamBlock(0);
                    pb.SetValue((int)ProOptimizerPBValues.optimizer_main_ratio, t, VertexPercent, 0);
                    pb.SetValue((int)ProOptimizerPBValues.optimizer_options_keep_uv, t, 1, 0);
                    pb.SetValue((int)ProOptimizerPBValues.optimizer_options_keep_normals, t, 0, 0);
                    // There is no true way to know if this was valid/invalid for the mesh, so we check the outer level routine on triobject for changes. **
                    pb.SetValue((int)ProOptimizerPBValues.optimizer_main_calculate, t, 1, 0);
                    ip.ClearNodeSelection(false);
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
                return(-1);
            }

            return(1);
        }