Exemple #1
0
 private static void WriteDeclarationsOfTextures(BinaryWriter writer, U3DDocument doc)
 {
     foreach (Texture texture in doc.Textures.Values)
     {
         writer.Write(GetTextureResourceModifierChain(texture).ToArray());
     }
 }
Exemple #2
0
 private static void WriteShaders(BinaryWriter writer, U3DDocument doc)
 {
     foreach (Shader shader in doc.Shaders.Values)
     {
         writer.Write(GetLitTextureShaderBlock(shader).ToArray());
     }
 }
Exemple #3
0
 private static void WriteDeclarationsOfMeshes(BinaryWriter writer, U3DDocument doc)
 {
     foreach (Mesh mesh in doc.Meshes.Values)
     {
         writer.Write(GetModelResourceModifierChain(mesh).ToArray());
     }
 }
Exemple #4
0
        public static void SavePdf(U3DDocument u3dDoc, Stream pdfDocStream)
        {
            var         pdfDoc    = new PdfDocument();
            PdfPageBase page      = pdfDoc.Pages.Add(PdfPageSize.A4, new PdfMargins(30.0f), PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape);
            var         rectangle = new System.Drawing.Rectangle(0, 0, (int)(page.Size.Width - 60.0f), (int)(page.Size.Height - 60.0f));

            string u3dTempFileName = Path.GetTempFileName();

            Save(u3dDoc, File.Create(u3dTempFileName));

            Pdf3DAnnotation annotation = new Pdf3DAnnotation(rectangle, u3dTempFileName);

            annotation.Activation = new Pdf3DActivation();
            annotation.Activation.ActivationMode = Pdf3DActivationMode.PageOpen;
            Pdf3DView View = new Pdf3DView();

            View.Background           = new Pdf3DBackground(new PdfRGBColor(System.Drawing.Color.White));
            View.ExternalName         = "Default";
            View.InternalName         = "Default";
            View.ViewNodeName         = "Default";
            View.RenderMode           = new Pdf3DRendermode(Pdf3DRenderStyle.Solid);
            View.LightingScheme       = new Pdf3DLighting();
            View.LightingScheme.Style = Pdf3DLightingStyle.Hard;
            annotation.Views.Add(View);
            page.AnnotationsWidget.Add(annotation);

            pdfDoc.SaveToStream(pdfDocStream, FileFormat.PDF);

            File.Delete(u3dTempFileName);
        }
Exemple #5
0
 public static void Read(U3DDocument doc, Stream stream, bool leaveOpen = false)
 {
     using (var reader = new StreamReader(stream, doc.TextEncoding, false, 1024, leaveOpen))
     {
         throw new System.NotImplementedException();
     }
 }
Exemple #6
0
 private static void WriteContinuationsOfMeshes(BinaryWriter writer, U3DDocument doc)
 {
     foreach (Mesh mesh in doc.Meshes.Values)
     {
         writer.Write(GetMeshContinuationBlock(mesh).ToArray());
     }
 }
Exemple #7
0
 private static void WriteMaterials(BinaryWriter writer, U3DDocument doc)
 {
     foreach (Material material in doc.Materials.Values)
     {
         writer.Write(GetMaterialResourceBlock(material).ToArray());
     }
 }
Exemple #8
0
 private static void WriteContinuationsOfTextures(BinaryWriter writer, U3DDocument doc)
 {
     foreach (Texture texture in doc.Textures.Values)
     {
         writer.Write(GetTextureContinuationBlock(texture).ToArray());
     }
 }
 private static void AddShaders(U3DDocument doc)
 {
     doc.TryAddShader(new Shader("front_shader", "default_material", "front_texture"));
     doc.TryAddShader(new Shader("back_shader", "default_material", "back_texture"));
     doc.TryAddShader(new Shader("left_shader", "default_material", "left_texture"));
     doc.TryAddShader(new Shader("right_shader", "default_material", "right_texture"));
     doc.TryAddShader(new Shader("top_shader", "default_material", "top_texture"));
     doc.TryAddShader(new Shader("bottom_shader", "default_material", "bottom_texture"));
 }
 private static void AddTextures(U3DDocument doc)
 {
     doc.TryAddTexture(new Texture("front_texture", ImageFormat.PNG, GetImageFromResources("front.png")));
     doc.TryAddTexture(new Texture("back_texture", ImageFormat.PNG, GetImageFromResources("back.png")));
     doc.TryAddTexture(new Texture("left_texture", ImageFormat.PNG, GetImageFromResources("left.png")));
     doc.TryAddTexture(new Texture("right_texture", ImageFormat.PNG, GetImageFromResources("right.png")));
     doc.TryAddTexture(new Texture("top_texture", ImageFormat.PNG, GetImageFromResources("top.png")));
     doc.TryAddTexture(new Texture("bottom_texture", ImageFormat.PNG, GetImageFromResources("bottom.png")));
 }
        public static U3DDocument GetDocument()
        {
            var doc = new U3DDocument();

            AddTextures(doc);
            AddMaterials(doc);
            AddShaders(doc);
            AddMeshes(doc);
            AddNodes(doc);
            return(doc);
        }
        private static void AddNodes(U3DDocument doc)
        {
            string rootNodeName = "Rubik's Cube";

            doc.TryAddNode(new Node(rootNodeName, null, null, Matrix4.GetIdentityMatrix()));
            doc.TryAddNode(new Node("front", "front_mesh", rootNodeName, Matrix4.GetIdentityMatrix()));
            doc.TryAddNode(new Node("back", "back_mesh", rootNodeName, Matrix4.GetIdentityMatrix()));
            doc.TryAddNode(new Node("left", "left_mesh", rootNodeName, Matrix4.GetIdentityMatrix()));
            doc.TryAddNode(new Node("right", "right_mesh", rootNodeName, Matrix4.GetIdentityMatrix()));
            doc.TryAddNode(new Node("top", "top_mesh", rootNodeName, Matrix4.GetIdentityMatrix()));
            doc.TryAddNode(new Node("bottom", "bottom_mesh", rootNodeName, Matrix4.GetIdentityMatrix()));
        }
Exemple #13
0
 private static void WriteNodes(BinaryWriter writer, U3DDocument doc)
 {
     foreach (Node node in doc.Nodes.Values)
     {
         if (string.IsNullOrEmpty(node.Mesh))
         {
             writer.Write(GetGroupNodeModifierChain(node).ToArray());
         }
         else
         {
             writer.Write(GetNodeModifierChain(node, doc).ToArray());
         }
     }
 }
Exemple #14
0
 public static void Save(U3DDocument doc, Stream stream, bool leaveOpen = false)
 {
     using (var writer = new BinaryWriter(stream, doc.TextEncoding, leaveOpen))
     {
         writer.Write(GetHeaderBlock(doc).ToArray());
         WriteNodes(writer, doc);
         WriteDeclarationsOfMeshes(writer, doc);
         WriteShaders(writer, doc);
         WriteMaterials(writer, doc);
         WriteDeclarationsOfTextures(writer, doc);
         WriteContinuationsOfMeshes(writer, doc);
         WriteContinuationsOfTextures(writer, doc);
     }
 }
Exemple #15
0
        private static Block GetNodeModifierChain(Node node, U3DDocument doc)
        {
            var w = new BlockWriter();

            w.WriteString(node.Name); // modifier chain name
            w.WriteU32(0);            // modifier chain type: 0 = node modifier chain
            w.WriteU32(0);            // modifier chain attributes: 0 = neither bounding sphere nor
            // Bounding box info present.
            w.WritePadding();
            w.WriteU32(2); // modifier count in this chain
            w.WriteBlock(GetModelNodeBlock(node));
            w.WriteBlock(GetShadingModifierBlock(node.Name, doc.Meshes[node.Mesh].Shader));
            return(w.GetBlock(BlockType.ModifierChain));
        }
Exemple #16
0
        public static void Main(string[] args)
        {
            U3DDocument doc = U3DSpace.Samples.Textured_Rubik_s_Cube.GetDocument();

            string u3dFileName = "Textured_Rubik_s_Cube.u3d";

            doc.SaveToFile(u3dFileName);
            Console.WriteLine(@"Successfully saved: {0}\{1}", Environment.CurrentDirectory, u3dFileName);

            string pdfFileName = "Textured_Rubik_s_Cube.pdf";

            doc.SaveToPdfFile(pdfFileName);
            Console.WriteLine(@"Successfully saved: {0}\{1}", Environment.CurrentDirectory, pdfFileName);

            Console.ReadKey();
        }
Exemple #17
0
        private static Block GetHeaderBlock(U3DDocument doc)
        {
            var w = new BlockWriter();

            w.WriteI32(0x00000000);                            // version
            w.WriteU32(0x00000004);                            // profile identifier (0x00000004 - No compression mode)
            w.WriteU32(36);                                    // declaration size
            w.WriteU64(732);                                   // file size
            w.WriteU32(106);                                   // character encoding: 106 = UTF-8
            //Meta data.
            w.WriteMetaU32(1);                                 // Key/Value Pair Count
            w.WriteMetaU32(0);                                 // Key/Value Pair Attributes; 0x00000000 - indicates the Value is formatted as a String
            w.WriteMetaString("Created by", doc.TextEncoding); // Key String
            w.WriteMetaString("U3DSpace", doc.TextEncoding);   // Value String
            return(w.GetBlock(BlockType.Header));
        }
        private static void AddMeshes(U3DDocument doc)
        {
            var triangles = new List <Triangle> {
                new Triangle(new Corner(0, 0, 0), new Corner(1, 0, 1), new Corner(2, 0, 2)), new Triangle(new Corner(2, 0, 2), new Corner(3, 0, 3), new Corner(0, 0, 0))
            };
            var textureCoordinates = new List <Vector2> {
                new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0)
            };

            doc.TryAddMesh(new Mesh(
                               "front_mesh", "front_shader",
                               new List <Vector3> {
                new Vector3(-1, -1, 1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), new Vector3(1, -1, 1)
            },
                               new List <Vector3> {
                new Vector3(0, 0, 1)
            },
                               textureCoordinates,
                               triangles
                               ));
            doc.TryAddMesh(new Mesh(
                               "back_mesh", "back_shader",
                               new List <Vector3> {
                new Vector3(1, -1, -1), new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1)
            },
                               new List <Vector3> {
                new Vector3(0, 0, -1)
            },
                               textureCoordinates,
                               triangles
                               ));
            doc.TryAddMesh(new Mesh(
                               "left_mesh", "left_shader",
                               new List <Vector3> {
                new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1)
            },
                               new List <Vector3> {
                new Vector3(-1, 0, 0)
            },
                               textureCoordinates,
                               triangles
                               ));
            doc.TryAddMesh(new Mesh(
                               "right_mesh", "right_shader",
                               new List <Vector3> {
                new Vector3(1, -1, 1), new Vector3(1, 1, 1), new Vector3(1, 1, -1), new Vector3(1, -1, -1)
            },
                               new List <Vector3> {
                new Vector3(1, 0, 0)
            },
                               textureCoordinates,
                               triangles
                               ));
            doc.TryAddMesh(new Mesh(
                               "top_mesh", "top_shader",
                               new List <Vector3> {
                new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), new Vector3(1, 1, 1)
            },
                               new List <Vector3> {
                new Vector3(0, 1, 0)
            },
                               textureCoordinates,
                               triangles
                               ));
            doc.TryAddMesh(new Mesh(
                               "bottom_mesh", "bottom_shader",
                               new List <Vector3> {
                new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1)
            },
                               new List <Vector3> {
                new Vector3(0, -1, 0)
            },
                               textureCoordinates,
                               triangles
                               ));
        }
Exemple #19
0
 public static U3DDocument Merge(U3DDocument doc1, U3DDocument doc2)
 {
     throw new System.NotImplementedException();
 }
 private static void AddMaterials(U3DDocument doc)
 {
     doc.TryAddMaterial(new Material("default_material", new Color(0.1), new Color(1.0), new Color(0.5), new Color(0.0), 1.0f, 1.0f));
 }