// Use this for initialization public SceneInfo LoadScene(string scene) { if (SceneContainer.LoadDataFromXML() != null) { sceneContainer = SceneContainer.LoadDataFromXML(); foreach (var sceneInfo in sceneContainer.SceneInfos) { if (sceneInfo.name == scene) return sceneInfo; } } sceneContainer = new SceneContainer(); sceneContainer.Add(new SceneInfo(scene, GameObject.FindGameObjectWithTag("Player").transform.position)); return sceneContainer.SceneInfos[0]; }
// Use this for initialization public SceneInfo LoadScene(string scene) { if (SceneContainer.LoadDataFromXML() != null) { sceneContainer = SceneContainer.LoadDataFromXML(); foreach (var sceneInfo in sceneContainer.SceneInfos) { if (sceneInfo.name == scene) { return(sceneInfo); } } } sceneContainer = new SceneContainer(); sceneContainer.Add(new SceneInfo(scene, GameObject.FindGameObjectWithTag("Player").transform.position)); return(sceneContainer.SceneInfos[0]); }
private bool f_import_scene() { if (container == null) { return(false); } var file = new OpenFileDialog(); file.Multiselect = true; file.Filter = ".scn_part|*.scn_part"; if (file.ShowDialog() == DialogResult.OK) { for (int i = 0; i < file.FileNames.Length; i++) { using (var fs = new FileStream(file.FileName, FileMode.Open, FileAccess.Read, FileShare.None)) using (var br = new BinaryReader(fs)) { SceneChunk chunk = null; var type = br.ReadEnum <ChunkType>(); string name = br.ReadCString(); string subname = br.ReadCString(); switch (type) { case ChunkType.Bone: chunk = new BoneChunk(container) { Name = name, SubName = subname, Image = Properties.Resources.bone }; chunk.Deserialize(fs); container.Add(chunk); break; case ChunkType.BoneSystem: chunk = new BoneSystemChunk(container) { Name = name, SubName = subname, Image = Properties.Resources.bone_system }; chunk.Deserialize(fs); container.Add(chunk); break; case ChunkType.Box: chunk = new BoxChunk(container) { Name = name, SubName = subname, Image = Properties.Resources.box }; chunk.Deserialize(fs); container.Add(chunk); break; case ChunkType.ModelData: chunk = new ModelChunk(container) { Name = name, SubName = subname, Image = Properties.Resources.model }; chunk.Deserialize(fs); container.Add(chunk); break; case ChunkType.Shape: chunk = new ShapeChunk(container) { Name = name, SubName = subname, Image = Properties.Resources.shape }; chunk.Deserialize(fs); container.Add(chunk); break; case ChunkType.SkyDirect1: chunk = new SkyDirect1Chunk(container) { Name = name, SubName = subname, Image = Properties.Resources.sky }; chunk.Deserialize(fs); container.Add(chunk); break; default: return(false); } } } return(true); } return(false); }
public void Import(string fileName, string textureName, string sceneName, string sceneSubname, SceneContainer container) { var VertexList = new List <Vector3>(); var NormalList = new List <Vector3>(); var UVList = new List <Vector2>(); var FacesList = new List <Vector3>(); var obj = new Obj(); obj.LoadObj(fileName); if (obj == null) { return; } var model = new ModelChunk(container); for (int index = 0; index < obj.VertexList.Count; index++) { VertexList.Add(new Vector3(float.Parse(obj.VertexList[index].X.ToString()) / 100, float.Parse(obj.VertexList[index].Y.ToString()) / 100, float.Parse(obj.VertexList[index].Z.ToString()) / 100)); } for (int index = 0; index < obj.NormalList.Count; index++) { NormalList.Add(new Vector3(float.Parse(obj.NormalList[index].X.ToString()) / 100, float.Parse(obj.NormalList[index].Y.ToString()) / 100, float.Parse(obj.NormalList[index].Z.ToString()) / 100)); } for (int index = 0; index < obj.TextureList.Count; index++) { UVList.Add(new Vector2(float.Parse(obj.TextureList[index].X.ToString()) / 100, 0.0f - float.Parse(obj.TextureList[index].Y.ToString()) / 100)); } for (int index = 0; index < VertexList.Count; index++) { model.Mesh.Vertices.Add(VertexList[index]); } for (int index = 0; index < obj.FaceList.Count; index++) { string face = obj.FaceList[index].ToString(); string[] face_array = face.Split(' '); string X = Convert.ToString(face_array[1]); string Y = Convert.ToString(face_array[2]); string Z = Convert.ToString(face_array[3]); string[] _X = X.Split('/'); string[] _Y = Y.Split('/'); string[] _Z = Z.Split('/'); FacesList.Add(new Vector3(Convert.ToInt32(_X[0]) - 1, Convert.ToInt32(_Y[0]) - 1, Convert.ToInt32(_Z[0]) - 1)); } var texture = new TextureEntry { FaceCount = obj.FaceList.Count, FaceCounter = 0, FileName = textureName, FileName2 = "" }; if (model.TextureData.Textures.Count != 0) { model.TextureData.Textures[0] = texture; } else { model.TextureData.Textures.Add(texture); } model.Mesh.Normals = NormalList; model.Mesh.UV = UVList; model.Mesh.Faces = FacesList; model.Name = sceneName; model.SubName = sceneSubname; model.Image = Properties.Resources.model; container.Add(model); }