function isInRange ( _val, _min, _max ) { return ( _val >= _min && _val <= _max ); }; //disable logging var prefs = Application.Preferences; prefs.SetPreferenceValue( "scripting.cmdlog", false ); slctGlob = Application.selection; slct = slctGlob(0); if ( ( slct != null) && ( slct.Type.toString() == "polymsh")) { // first check fog geometry size var attr_nbFaces = slct.ActivePrimitive.Geometry.GetICEAttributeFromName("NbPolygons"); var nbFaces = new VBArray( attr_nbFaces.DataArray ).toArray(); if ( nbFaces > 3 ) { var baked = GetPrim( "EmptyPolygonMesh" , null, null, null); SetValue ( baked + ".Name" , slct + "_Baked_ICE_Data" , null ); // copy topology (DO NOT use extraction - sometimes this works unstable without the freezing original geometry ) var actTree = Application.ApplyOp("ICETree", baked , "siNode", "", "", siConstructionModeModeling); var getT = AddICECompoundNode("Get Topology", actTree); SetValue( getT + ".Transform_Mode", 1, null); application.logmessage ( getT + ".Reference" ); SetValue( getT + ".Reference", slct.name, null); var setT = AddICECompoundNode("Set Topology", actTree); ConnectICENodes( actTree + ".port1", setT + ".Execute"); ConnectICENodes( setT + ".Topology", getT + ".Topology"); FreezeObj ( baked,null,null ); // create UVs Create2DMapWithProjection(baked, null, siDefaultPropagation, siTxtCubic, null, null); FreezeObj ( baked,null,null ); SetValue( baked + ".polymsh.cls.Texture_Coordinates_AUTO.Name", "ILT_UV_Cluster", null); // create UNorms CreateUserNormals( baked + ".sample[*]", null); SetValue(baked + ".polymsh.cls.User_Normal_Cluster.Name" , "ILT_USerNormals_Cluster", null); // set ICEtree to update node clusters var actTree = Application.ApplyOp("ICETree", baked , "siNode", "", "", siConstructionModeModeling); AddPortToICENode(actTree + ".port1", siNodePortDataInsertionLocationAfter); var updUN = AddICECompoundNode("Set Data", actTree); SetValue( updUN + ".Reference", "self.cls.ILT_USerNormals_Cluster.User_Normal_Property.Normals", null); var updUV = AddICECompoundNode("Set Data", actTree); SetValue( updUV + ".Reference", "self.cls.ILT_UV_Cluster.Texture_Projection.UVWs", null); ConnectICENodes(actTree + ".port1", updUN + ".Execute"); ConnectICENodes(actTree + ".port2", updUV + ".Execute"); var getUN = AddICENode("$XSI_DSPRESETS\\ICENodes\\GetDataNode.Preset", actTree); var getUV = AddICENode("$XSI_DSPRESETS\\ICENodes\\GetDataNode.Preset", actTree); var sw_ctxtUV = AddICENode("$XSI_DSPRESETS\\ICENodes\\SwitchContextNode.Preset", actTree); var sw_ctxtUN = AddICENode("$XSI_DSPRESETS\\ICENodes\\SwitchContextNode.Preset", actTree); SetValue( getUV + ".reference", slct + ".texture_projection", null); SetValue( getUN + ".reference", slct + ".NodeUserNormal", null); ConnectICENodes( sw_ctxtUV + ".value", getUV + ".value"); ConnectICENodes(updUV + ".Value", sw_ctxtUV + ".result"); ConnectICENodes( sw_ctxtUN + ".value", getUN + ".value"); ConnectICENodes(updUN + ".Value", sw_ctxtUN + ".result"); FreezeObj ( baked,null,null ); // create mat clusters // pass global mat var globMatFullName = slct.Materials.item(0).Library + "." + slct.Materials.item(0).name; AssignMaterial(globMatFullName + "," + slct , siLetLocalMaterialsOverlap); var attr_matID = slct.ActivePrimitive.Geometry.GetICEAttributeFromName("MaterialID"); if ( attr_matID.IsDefined ) { //logmessage ( "mat ID attr definition is: " +attr_matID.IsDefined ); var matID = new VBArray( attr_matID.DataArray ).toArray(); var attr_matList = slct.ActivePrimitive.Geometry.GetICEAttributeFromName("Materials"); if ( attr_matList.IsDefined ) { //logmessage ( "mat list attr definition is: " + attr_matList.IsDefined ); var si_matList = new VBArray( attr_matList.DataArray2D ).toArray(); var clsIDs = new Array(si_matList[0].ubound(1)+1 + 2); //logmessage ( "si_matList length=" + si_matList[0].ubound(1) ); //logmessage ( "cls length=" + clsIDs.length ); // init sub arrays for ( var j = 0;j0 && si_matList[0].getItem(k).length >0) ? CopyPaste(si_matList[0].getItem(k), null, baked + ".poly["+ clsIDs[j] +"]", 1) : null; ActivateObjectSelTool(null); ActivateObjectSelTool(null); DeselectAll(); }; // and create cluster with undefined matID ( inner faces ) var innFaceCls; if( clsIDs[clsIDs.length-1].length>0 ) { innFaceCls = createcluster( baked + ".poly["+ clsIDs[clsIDs.length-1] +"]"); SetValue( innFaceCls + ".Name", "IFX_Sliced_faces", null); prefs.SetPreferenceValue( "scripting.cmdlog", true ); logmessage ( "[IFX][ICEBAKER]: Created cluster with sliced faces" ); ActivateObjectSelTool(null); ActivateObjectSelTool(null); DeselectAll(); }; prefs.SetPreferenceValue( "scripting.cmdlog", true ); }; }; }; // end of geo-size checking } // global end else Application.LogMessage ( "Select a valid polymesh for baking!" , siWarningMsg );