private void import() { if (importDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.propsControl.SelectedNode = null; //Load ASE file ASE.Parser parser = new ASE.Parser(); ASE.Scene scn = parser.loadFilename(importDialog.FileName); Model model = modelView.Scene.Model; model.Clear(); //Get meshes and bones foreach (ASE.GeomObject obj in scn.objs) { //If the mesh has only one vertex, it's a bone if (obj.mesh.vertexCount == 1) { model.Add(new Bone(obj)); } else //It's a mesh { model.Add(new Mesh(obj)); } } this.Text = title; currentFile = null; unsaved = true; //Update the modelTreeView this.modelTreeView.Model = model; //Update properties this.propsControl.Model = model; //Update timeline this.timeline.Model = model; modelView.Invalidate(); } }
private bool loadScene(Scene scene) { bool success = true; int nextToken = 0; bool haveNext = false; readBlockStart(); while (haveNext || (nextToken = scanner.yylex()) != (int)TokenType.BlockEnd) { if(nextToken != (int)TokenType.Node) { Console.Error.WriteLine("Expected a node"); } haveNext = false; string text = scanner.yytext; if (text.Equals("*SCENE_FILENAME")) { string blah; readString(out blah); } else if (text.Equals("*SCENE_FIRSTFRAME")) { if (!readInt(out scene.firstFrame)) success = false; } else if (text.Equals("*SCENE_LASTFRAME")) { if (!readInt(out scene.lastFrame)) success = false; } else if (text.Equals("*SCENE_FRAMESPEED")) { if (!readInt(out scene.frameSpeed)) success = false; } else if (text.Equals("*SCENE_TICKSPERFRAME")) { if (!readInt(out scene.ticksPerFrame)) success = false; } else if (text.Equals("*SCENE_BACKGROUND_STATIC")) { if (!readRGB(out scene.backgroundLight)) success = false; } else if (text.Equals("*SCENE_AMBIENT_STATIC")) { if (!readRGB(out scene.ambientLight)) success = false; } else { if ((nextToken = skip()) == (int)TokenType.BlockEnd || nextToken < 1) break; haveNext = true; } } return success; }
private bool loadMaterials(Scene scene) { bool success = true; int nextToken = 0; bool haveNext = false; int materialCount; readBlockStart(); if (scanner.yylex() != (int)TokenType.Node) Console.Error.WriteLine("Expected a node"); if (!scanner.yytext.Equals("*MATERIAL_COUNT")) Console.Error.WriteLine("Expected a *MATERIAL_COUNT node"); readInt(out materialCount); while (haveNext || (nextToken = scanner.yylex()) != (int)TokenType.BlockEnd) { if (nextToken != (int)TokenType.Node) { Console.Error.WriteLine("Expected a node"); } haveNext = false; if (scanner.yytext.Equals("*MATERIAL")) { int m; if (!readInt(out m)) { success = false; continue; } if (m >= materialCount) { Console.Error.WriteLine("File refered to non-existant submaterial"); continue; } Material material = new Material(); if (scene.materials == null) scene.materials = new List<Material>(); if (!loadMaterial(out material)) success = false; scene.materials.Add(material); } else { if ((nextToken = skip()) == (int)TokenType.BlockEnd || nextToken < 1) break; haveNext = true; } } return success; }
private Scene load() { int version; int nextToken; bool haveNext = true; Scene scene = new Scene(); if (scanner.yylex() != (int)TokenType.Node) { Console.Error.WriteLine("Expected a node"); } if (!scanner.yytext.Equals("*3DSMAX_ASCIIEXPORT")) { Console.Error.WriteLine("File must start with *3DSMAX_ASCIIEXPORT"); } readInt(out version); if (version != 200) { Console.Error.WriteLine("Warning: loader has not been tested with this file version {%i}", version); } scene.materials = new List<Material>(); scene.objs = new List<GeomObject>(); scene.lights = new List<Light>(); scene.cameras = new List<Camera>(); while ((nextToken = scanner.yylex()) > (int)Tokens.EOF) { if (nextToken != (int)TokenType.Node) { Console.Error.WriteLine("Expected a node"); } string text = scanner.yytext; if (text.Equals("*SCENE")) { loadScene(scene); } else if (text.Equals("*MATERIAL_LIST")) { loadMaterials(scene); } else if (text.Equals("*GEOMOBJECT")) { loadGeomObject(scene); } else if (text.Equals("*LIGHTOBJECT")) { loadLight(scene); } else if (text.Equals("*CAMERAOBJECT")) { loadCamera(scene); } else if (text.Equals("*COMMENT")) { string str; readString(out str); } else { if ((nextToken = skip()) == (int)TokenType.BlockEnd) break; haveNext = true; } } return scene; }
private bool loadLight(Scene scene) { bool success = true; int nextToken = 0; bool haveNext = false; Light light = new Light(); readBlockStart(); while (haveNext || (nextToken = scanner.yylex()) != (int)TokenType.BlockEnd) { if (nextToken != (int)TokenType.Node) { Console.Error.WriteLine("Expected a node"); } haveNext = false; string str = scanner.yytext; if (str.Equals("*NODE_NAME")) { if (!readString(out light.name)) success = false; } else if (str.Equals("*LIGHT_TYPE")) { if (!readSymbol(out light.type)) success = false; } else if (str.Equals("*NODE_TM")) { if (!loadTransform(out light.transform)) success = false; } else if (str.Equals("*LIGHT_SHADOWS")) { if (!readSymbol(out light.shadows)) success = false; } else if (str.Equals("*LIGHT_USELIGHT")) { if (!readBool(out light.useLight)) success = false; } else if (str.Equals("*LIGHT_SPOTSHAPE")) { if (!readSymbol(out light.spotShape)) success = false; } else if (str.Equals("*LIGHT_USEGLOBAL")) { if (!readBool(out light.useGlobal)) success = false; } else if (str.Equals("*LIGHT_ABSMAPBIAS")) { if (!readInt(out light.absMapBias)) success = false; } else if (str.Equals("*LIGHT_OVERSHOOT")) { if (!readInt(out light.overshoot)) success = false; } else if (str.Equals("*LIGHT_SETTINGS")) { if (!loadLightSettings(out light.settings)) success = false; } else { if ((nextToken = skip()) == (int)TokenType.BlockEnd || nextToken < 1) break; haveNext = true; } } if (scene.lights == null) scene.lights = new List<Light>(); scene.lights.Add(light); return success; }
private bool loadGeomObject(Scene scene) { bool success = true; int nextToken = 0; bool haveNext = false; GeomObject obj = new GeomObject(); readBlockStart(); while (haveNext || (nextToken = scanner.yylex()) != (int)TokenType.BlockEnd) { if (nextToken != (int)TokenType.Node) { Console.Error.WriteLine("Expected a node" + " - " + scanner.yytext); } haveNext = false; string str = scanner.yytext; if (str.Equals("*NODE_NAME")) { if (!readString(out obj.name)) success = false; } else if (str.Equals("*NODE_TM")) { if (!loadTransform(out obj.transform)) success = false; } else if (str.Equals("*MESH")) { if (!loadMesh(out obj.mesh)) success = false; } else if (str.Equals("*PROP_MOTIONBLUR")) { if (!readBool(out obj.motionBlur)) success = false; } else if (str.Equals("*PROP_CASTSHADOW")) { if (!readBool(out obj.castShadow)) success = false; } else if (str.Equals("*PROP_RECVSHADOW")) { if (!readBool(out obj.recieveShadow)) success = false; } else if (str.Equals("*TM_ANIMATION")) { skip(); } else if (str.Equals("*MATERIAL_REF")) { if (!readInt(out obj.material)) success = false; } else { if ((nextToken = skip()) == (int)TokenType.BlockEnd || nextToken < 1) break; haveNext = true; } } scene.objs.Add(obj); return success; }
private bool loadCamera(Scene scene) { bool success = true; int nextToken = 0; bool haveNext = false; Camera camera = new Camera(); readBlockStart(); while (haveNext || (nextToken = scanner.yylex()) != (int)TokenType.BlockEnd) { if (nextToken != (int)TokenType.Node) { Console.Error.WriteLine("Expected a node"); } haveNext = false; string str = scanner.yytext; if (str.Equals("*NODE_NAME")) { if (!readString(out camera.name)) success = false; } else if (str.Equals("*CAMERA_TYPE")) { if (!readSymbol(out camera.type)) success = false; if (camera.type.Equals("Target")) { scanner.yylex(); if (!loadTransform(out camera.camera)) success = false; scanner.yylex(); if (!loadTransform(out camera.target)) success = false; } } else if (str.Equals("*CAMERA_SETTINGS")) { if (!loadCameraSettings(out camera.settings)) success = false; } else { if ((nextToken = skip()) == (int)TokenType.BlockEnd || nextToken < 1) break; haveNext = true; } } if (scene.cameras == null) scene.cameras = new List<Camera>(); scene.cameras.Add(camera); return success; }