private void WriteRefPoints(CustomWriter writer, ModelRoot model) { var Nodes = model.LogicalNodes.Where(node => node.Name.StartsWith("START") || node.Name.StartsWith("SAFESPOT") || node.Mesh == null ).ToList(); writer.Write(Nodes.Count); foreach (var node in Nodes) { int length = node.Name.LastIndexOf("."); length = length == -1 ? node.Name.Length : length; writer.Write(node.Name.Substring(0, length)); writer.Write(node.WorldMatrix.Translation.X * 50.0f); writer.Write(node.WorldMatrix.Translation.Y * 50.0f); writer.Write(-node.WorldMatrix.Translation.Z * 50.0f); writer.Write(0.0f); writer.Write(0.0f); writer.Write(0.0f); writer.Write(0); } }
private void WriteVertices(CustomWriter writer, ModelRoot model) { List <Vertex> verts = BuildVertList(model, out List <mesh> meshes); writer.Write(verts.Count); foreach (Vertex v in verts) { writer.Write(v); } //Cube writer.Write(-1000000.0f); writer.Write(-1000000.0f); writer.Write(-1000000.0f); writer.Write(1000000.0f); writer.Write(1000000.0f); writer.Write(1000000.0f); writer.Write(meshes.Count); // "submesh" count foreach (mesh m in meshes) { writer.Write(-1000000.0f); writer.Write(-1000000.0f); writer.Write(-1000000.0f); writer.Write(1000000.0f); writer.Write(1000000.0f); writer.Write(1000000.0f); writer.Write(0); // 0 submeshes writer.Write(m.geoms.Count); // geom count foreach (geom g in m.geoms) { writer.Write(m.name ?? ""); writer.Write(Vector4.Zero); //ambient writer.Write(g.diffuse); //diffuse writer.Write(Vector4.One / 4.0f); //spec writer.Write(Vector4.Zero); //emissive writer.Write(1.0f); // power? writer.Write(1); //has reflection writer.Write(0); // TODO: texture writer.Write(g.strips.Count); // strip count foreach (strip s in g.strips) { writer.Write(s.triangleCount); writer.Write(s.vertexOffset); } } } }
private void WriteBackgroundAndAmbient(CustomWriter writer) { writer.Write(Background.BackColor.R / 255.0f); writer.Write(Background.BackColor.G / 255.0f); writer.Write(Background.BackColor.B / 255.0f); writer.Write(Ambient.BackColor.R / 255.0f); writer.Write(Ambient.BackColor.G / 255.0f); writer.Write(Ambient.BackColor.B / 255.0f); }
private void WriteLights(CustomWriter writer, ModelRoot model) { writer.Write(1); writer.Write(0); writer.Write(350.671691894531f); writer.Write(525.585083007812f); writer.Write(76.9814834594727f); writer.Write(195.976226806641f); writer.Write(419.277282714844f); writer.Write(24.076717376709f); writer.Write(1.0f); writer.Write(1.0f); writer.Write(1.0f); }
private void saveButton_Click(object sender, EventArgs e) { if (openFileDialog1.FileName != null && saveFileDialog1.ShowDialog() == DialogResult.OK) { using (FileStream saveFile = File.OpenWrite(saveFileDialog1.FileName)) { using (CustomWriter writer = new CustomWriter(saveFile)) { var model = SharpGLTF.Schema2.ModelRoot.Load(openFileDialog1.FileName); WriteRefPoints(writer, model); WriteSplines(writer, model); WriteLights(writer, model); WriteBackgroundAndAmbient(writer); WriteVertices(writer, model); } } } }
private void WriteSplines(CustomWriter writer, ModelRoot model) { //List<Node> CameraSpline = model.LogicalNodes.Where(Node => Node.VisualParent?.Name == "CameraLocus").OrderBy(Node => Node.Name).ToList(); //writer.Write(1); //writer.Write("CameraLocus"); //writer.Write(CameraSpline.Count); //foreach(Node node in CameraSpline) //{ // Vector3 Pos = node.WorldMatrix.Translation; // Vertex v = new Vertex { X = Pos.X, Y = Pos.Y, Z = Pos.Z }.Converted(); // writer.Write(v.X); // writer.Write(v.Y); // writer.Write(v.Z); //} //No need to write a spline apparently the camera just follows if i don't populate this at all writer.Write(0); }
private void saveButton_Click(object sender, EventArgs e) { if (openFileDialog1.FileName != null && saveFileDialog1.ShowDialog() == DialogResult.OK) { using (FileStream saveFile = File.OpenWrite(saveFileDialog1.FileName)) { using (CustomWriter writer = new CustomWriter(saveFile)) { var model = SharpGLTF.Schema2.ModelRoot.Load(openFileDialog1.FileName); WriteRefPoints(writer, model); WriteSplines(writer, model); WriteLights(writer, model); WriteBackgroundAndAmbient(writer); WriteVertices(writer, model); var saveFileInfo = new FileInfo(saveFileDialog1.FileName); var textureDirectoryPath = Path.Combine(saveFileInfo.DirectoryName, "textures"); EnsureClearDirectory(textureDirectoryPath); WriteTextures(model, textureDirectoryPath); } } } }