/// <summary> /// 循环处理web请求 /// </summary> public void ListenLoop() { try { while (listener.IsListening) { var context = listener.GetContext(); var request = context.Request; var url = request.Url; //判断是否是服务终止请求 if (url.PathAndQuery == "/exit") { string res = BuildResponseText(200, "success", "stop"); WriteResponse(context, res); listener.Stop(); } else if (context != null && listener.IsListening) { if (url.PathAndQuery == "/healthz") { string res = BuildResponseText(200, "success", "healthy"); WriteResponse(context, res); } else { //获取请求文本(maxscript code) //var code = GetFormData(request, "code"); var body = request.InputStream; var encoding = request.ContentEncoding; var reader = new System.IO.StreamReader(body, encoding); var text = reader.ReadToEnd(); body.Close(); reader.Close(); var queryVars = HttpUtility.ParseQueryString(text, encoding); // var maxcode = queryVars["maxcode"]; var esspath = queryVars["esspath"]; // 执行maxscript code Action a = () => global.ExecuteMAXScriptScript(maxcode, false, null); dispatcher.Invoke(a); //执行完返回信息 string res = BuildResponseText(200, "success", esspath); WriteResponse(context, res); } } } } catch (Exception e) { Debug.WriteLine(e.Message); } }
/// <summary> /// Web request handling loop. Terminated when the user /// makes a request to http://localhost:{{port}}/exit /// </summary> public void ListenLoop() { try { while (listener.IsListening) { var context = listener.GetContext(); var request = context.Request; var url = request.Url; // Check for the special shutdown URL http://localhost:8080/exit if (url.PathAndQuery == "/exit") { string res = BuildResponseText(0, "success", "Shutting down!"); WriteResponse(context, res); listener.Stop(); } else if (context != null && listener.IsListening) { if (url.PathAndQuery == "/healthz") { string res = BuildResponseText(0, "success", "The service is healthy"); WriteResponse(context, res); } else { // Get the HTML request text from the form. // This should be pure MAXScript var code = GetFormData(request, "code"); // We return the HTML constant string, embedding the request body. var responseText = HtmlResponseTextTemplate.Replace("{{PORT}}", port); responseText = responseText.Replace("{{REQUEST}}", code); WriteResponse(context, responseText); // Execute the evaluation of the code as MAXScript on the main thread. Action a = () => global.ExecuteMAXScriptScript(code, false, null); dispatcher.Invoke(a); } } } } catch (Exception e) { Debug.WriteLine(e.Message); } }
static public string UpdateNodes(float vertexPercent, bool keepNormals, bool collapseStack) { IGlobal globalInterface = Autodesk.Max.GlobalInterface.Instance; IInterface14 coreInterface = globalInterface.COREInterface14; // start the scene process globalInterface.TheHold.Begin(); IINode nodeRoot = coreInterface.RootNode; m_sceneNodes.Clear(); GetSceneNodes(nodeRoot); List <IINode> optimizedNodes = new List <IINode> { }; // Iterate each node in the scene file and process all meshes into ProOptimized meshes. foreach (IINode node in m_sceneNodes) { // Check for object assigned to node (could be something other than object) if (node.ObjectRef != null) { IObjectState os = node.ObjectRef.Eval(coreInterface.Time); IObject objOriginal = os.Obj; if (!objOriginal.IsSubClassOf(globalInterface.TriObjectClassID)) { // If it is NOT, see if we can convert it... if (objOriginal.CanConvertToType(globalInterface.TriObjectClassID) == 1) { objOriginal = objOriginal.ConvertToType(coreInterface.Time, globalInterface.TriObjectClassID); } else { RuntimeExecute.LogTrace("\nNode {0} Object Not Converted Error: {1}", node.NodeName, objOriginal.ObjectName); continue; } } ITriObject tri = objOriginal as ITriObject; if (tri == null) { RuntimeExecute.LogTrace("\nNode {0} Object Not Converted Error: {1}", node.NodeName, objOriginal.ObjectName); continue; } int val = tri.Mesh.NumVerts; AddOsmProoptimizer(node, vertexPercent, keepNormals); // get new mesh state os = node.ObjectRef.Eval(coreInterface.Time); tri = os.Obj as ITriObject; // ** after modifier operation we can see if success by checking if the mesh size is different than before if (val != tri.Mesh.NumVerts) { if (collapseStack) { coreInterface.CollapseNode(node, true); } optimizedNodes.Add(node); } } } int status; if (optimizedNodes.Count() > 0) { // Build result file name based on percentage used string full_filename = coreInterface.CurFilePath; string filename = coreInterface.CurFileName; vertexPercent = vertexPercent * 100; string stringVertexPercent = vertexPercent.ToString("F1"); stringVertexPercent = stringVertexPercent.Replace('.', '_'); string output = "outputFile-" + stringVertexPercent + ".max"; string new_filename = full_filename.Replace(filename, output); status = coreInterface.SaveToFile(new_filename, true, false); // setup to export as FBX as well string outputFBX = new_filename.Replace(".max", ".fbx"); string msCmdFbxExport = "exportFile \"" + outputFBX + "\" #noPrompt using:FBXEXP"; bool fbxOk = globalInterface.ExecuteMAXScriptScript(msCmdFbxExport, false, null, false); // If we changed something, put scene back for next iteration globalInterface.TheHold.Cancel(); if ((status == 0) || (fbxOk == false)) // error saving max or fbx file { return(null); } return(new_filename); } return(null); }
private bool GetNodes() { IINode characterNode = i.GetINodeByName(Character.Name); IINode bipedNode = i.GetINodeByName(Character.BipedName); if (characterNode != null && bipedNode != null) { Character.Node = characterNode; Character.BipedNode = bipedNode; global.ExecuteMAXScriptScript("animationRange = interval 0 " + (Character.StepLength - 1), false, null); groupAnimation.Enabled = true; groupCreateAnimation.Enabled = true; return(true); } else { return(false); } }
public void Apply(Character character) { if (character != null) { string charName = character.Name; string modifier = ".modifiers[#Hair_and_Fur]"; global.ExecuteMAXScriptScript("$" + charName + modifier + ".MaterialRootColor = color " + RootColor.R + " " + RootColor.G + " " + RootColor.B, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".MaterialTipColor = color " + TipColor.R + " " + TipColor.G + " " + TipColor.B, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".MaterialMutantHairColor = color " + MutantColor.R + " " + MutantColor.G + " " + MutantColor.B, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".HairScale = " + Scale, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".HairSegments = " + Segments, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".HairRandScale = " + RandomScale, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".HairRootThickness = " + RootThick, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".MaterialHueVariation = " + HueVariation, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".MaterialValueVariation = " + ValueVariation, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".MaterialPercentMutantHair = " + Mutant, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".MaterialSpecular = " + Specular, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".MaterialGlossness = " + Glossiness, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".FlyawayStren = " + Flyaway / 100, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".ClumpsStren = " + Clump / 100, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".KinkTip = " + Kink, false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".FlyawayPerc = 100", false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".Clumps = 300", false, null); global.ExecuteMAXScriptScript("$" + charName + modifier + ".KinkRoot = 0", false, null); } else { MessageBox.Show("Can't find 'WalkingCharacterBody'"); } }
public bool PreImport() { IFPValue importQuery = global.FPValue.Create(); IFPValue errorQuery = global.FPValue.Create(); bool result = true; if (Utility.uniqueParts.Count > 50) { global.ExecuteMAXScriptScript("qB_LongImport()", false, importQuery); result = importQuery.B; } if (result != false && Utility.missingParts.Count > 0) { global.ExecuteMAXScriptScript("qB_MissingParts()", false, errorQuery); result = errorQuery.B; } return(result); }