Esempio n. 1
0
        public static void Run()
        {
            //Create a FBX file with embedded textures
            Scene scene = new Scene();

            //Create an embedded texture
            Texture tex = new Texture()
            {
                Content = CreateTextureContent(),
                //file name is required if the embedded texture is used.
                FileName = "test.png"
            };

            tex.SetProperty("TexProp", "value");
            //create a material with custom property
            LambertMaterial mat = new LambertMaterial("my-mat");

            mat.SetTexture(Material.MapDiffuse, tex);
            mat.SetProperty("MyProp", 1.0);

            //create a torus with this material applied
            scene.RootNode.CreateChildNode(new Torus()).Material = mat;
            //save this to file
            scene.Save(RunExamples.GetOutputFilePath(@"test.fbx"), FileFormat.FBX7500ASCII);
        }
Esempio n. 2
0
        private HashSet <string> DiagnoseResult(StorageFileNames fileNames)
        {
            HashSet <string> typeList = new HashSet <string>();
            Scene            scene    = OpenInput(fileNames);
            //create scene diagnoser
            var sd = SceneDiagnoser.LoadFromScene(scene);

            //print the problems we just found
            if (sd.Issues.Length == 0)
            {
                //Console.WriteLine("No errors found for this scene");
            }
            else
            {
                //Console.WriteLine($"{sd.Issues.Length} errors found for this scene:");
                foreach (var issue in sd.Issues)
                {
                    typeList.Add($"{issue.IssueType}");
                    //Console.WriteLine($"\t{issue.IssueType}");
                }
            }
            using (var fs = new FileStream(fileNames[AnalyzeResult], FileMode.Create))
            {
                sd.SaveToStream(fs);
            }
            //save the mesh and delta mesh for client side review:
            Scene review = new Scene();

            //review scene has the merged mesh with a default material(grey color)
            review.RootNode.CreateChildNode(sd.Mesh).Material = new LambertMaterial()
            {
                DiffuseColor = new Vector3(0.5, 0.5, 0.5)
            };
            //delta meshes that points to the problem area, and highlighted in red color using red material
            var errorMaterial = new LambertMaterial()
            {
                DiffuseColor = new Vector3(1, 0, 0)
            };

            foreach (var issue in sd.Issues)
            {
                if (issue.DeltaMesh != null)
                {
                    var node = review.RootNode.CreateChildNode(issue.IssueType.ToString(), issue.DeltaMesh);
                    node.Material = errorMaterial;
                }
            }
            review.Save(fileNames[ReviewFile], FileFormat.Aspose3DWeb);
            return(typeList);
        }
Esempio n. 3
0
        public static List <Hitable> MakeCornellBoxScene()
        {
            var list = new List <Hitable>();

            var red   = new LambertMaterial(0.65f, 0.05f, 0.05f);
            var white = new LambertMaterial(0.73f, 0.73f, 0.73f);
            var green = new LambertMaterial(0.12f, 0.45f, 0.15f);
            var light = new DiffuseLightMaterial(new ConstantTexture(new Vector3(15, 15, 15)));

            list.Add(new Quad(Quad.Axis.YZ, true, 0, 555, 0, 555, 555, green));
            list.Add(new Quad(Quad.Axis.YZ, false, 0, 555, 0, 555, 0, red));
            list.Add(new Quad(Quad.Axis.XZ, false, 213, 343, 227, 332, 554, light));
            list.Add(new Quad(Quad.Axis.XZ, true, 0, 555, 0, 555, 555, white));
            list.Add(new Quad(Quad.Axis.XZ, false, 0, 555, 0, 555, 0, white));
            list.Add(new Quad(Quad.Axis.XY, true, 0, 555, 0, 555, 555, white));

            return(list);
        }
        public static void Run()
        {
            //ExStart:ShareMeshGeometryData
            // Initialize scene object
            Scene scene = new Scene();

            // Define color vectors
            Vector3[] colors = new Vector3[] {
                new Vector3(1, 0, 0),
                new Vector3(0, 1, 0),
                new Vector3(0, 0, 1)
            };

            // Call Common class create mesh using polygon builder method to set mesh instance
            Mesh mesh = Common.CreateMeshUsingPolygonBuilder();

            int idx = 0;

            foreach (Vector3 color in colors)
            {
                // Initialize cube node object
                Node cube = new Node("cube");
                cube.Entity = mesh;
                LambertMaterial mat = new LambertMaterial();
                // Set color
                mat.DiffuseColor = color;
                // Set material
                cube.Material = mat;
                // Set translation
                cube.Transform.Translation = new Vector3(idx++ *20, 0, 0);
                // Add cube node
                scene.RootNode.ChildNodes.Add(cube);
            }

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir();

            MyDir = MyDir + RunExamples.GetOutputFilePath("MeshGeometryData.fbx");

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7400ASCII);
            //ExEnd:ShareMeshGeometryData
            Console.WriteLine("\nMesh’s geometry data shared successfully between multiple nodes.\nFile saved at " + MyDir);
        }
        public static void Run()
        {
            // Initialize scene object
            Scene scene = new Scene();

            // Define color vectors
            Vector3[] colors = new Vector3[] {
            new Vector3(1, 0, 0),
            new Vector3(0, 1, 0),
            new Vector3(0, 0, 1)
            };
            // Call Common class create meshh method to set mesh instance
            Mesh mesh = Common.CreateMesh();

            int idx = 0;
            foreach (Vector3 color in colors)
            {
                // Initialize cube node object
                Node cube = new Node("cube");
                cube.Entity = mesh;
                LambertMaterial mat = new LambertMaterial();
                // Set color
                mat.DiffuseColor = color;
                // Set material
                cube.Material = mat;
                // Set translation
                cube.Transform.Translation = new Vector3(idx++ * 20, 0, 0);
                // Add cube node
                scene.RootNode.ChildNodes.Add(cube);
            }

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir_GeometryAndHierarchy();
            MyDir = MyDir + "MeshGeometryData.fbx";

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7400ASCII);

            Console.WriteLine("\nMesh’s geometry data shared successfully between multiple nodes.\nFile saved at " + MyDir);
        }
Esempio n. 6
0
        private void ParseMaterials(IEnumerable <XElement> materialNodes, IEnumerable <XElement> materialInfos, IEnumerable <XElement> imageNodes)
        {
            #region build Material Dictionary
            foreach (var material in materialInfos.Elements("material"))
            {
                String id        = material.Attribute("id").Value;
                String reference = material.Element("instance_effect").Attribute("url").Value.Replace("#", "");
                materialsToEffects.Add(id, reference);
            }
            #endregion

            foreach (var material in materialNodes.Elements("effect"))
            {
                String materialId   = material.Attribute("id").Value;
                String materialName = material.Attribute("name").Value;

                //Determine the MaterialType
                foreach (var subNode in material.Element("profile_COMMON").Element("technique").Elements())
                {
                    if (subNode.Name == "lambert")
                    {
                        if (subNode.Element("diffuse").Element("texture") != null)
                        {
                            foreach (var image in imageNodes.Elements("image"))
                            {
                                if (image.Attribute("id").Value.Equals(subNode.Element("diffuse").Element("texture").Attribute("texture").Value))
                                {
                                    Texture  texture = new Texture(image.Element("init_from").Value.Replace("file://", ""), false);
                                    Material mat     = new LambertMaterial(new Color(0, 0, 0));
                                    mat.ColorTexture = texture;
                                    Materials.Add(materialName, mat);
                                }
                            }
                        }
                        else
                        {
                            Color    diffuse = ParseColor(subNode.Element("diffuse").Element("color").Value);
                            Material mat     = new LambertMaterial(diffuse);
                            //Create lambert material
                            Materials.Add(materialName, mat);
                        }
                    }
                    if (subNode.Name == "blinn")
                    {
                        if (subNode.Element("diffuse").Element("texture") != null)
                        {
                            foreach (var image in imageNodes.Elements("image"))
                            {
                                if (image.Attribute("id").Value.Equals(subNode.Element("diffuse").Element("texture").Attribute("texture").Value))
                                {
                                    Texture  texture = new Texture(image.Element("init_from").Value.Replace("file://", ""), false);
                                    Material mat     = new LambertMaterial(new Color(0, 0, 0));
                                    mat.ColorTexture = texture;
                                    Materials.Add(materialName, mat);
                                }
                            }
                        }
                        else
                        {
                            //Create BlinnPhong Material
                            Color    diffuse   = ParseColor(subNode.Element("diffuse").Element("color").Value);
                            Color    specular  = ParseColor(subNode.Element("specular").Element("color").Value);
                            float    shininess = (float)Convert.ToDouble(subNode.Element("shininess").Element("float").Value);
                            Material mat       = new BlinnPhongMaterial(diffuse, specular, shininess);
                            Materials.Add(materialName, mat);
                        }
                    }
                    if (subNode.Name == "phong")
                    {
                        if (subNode.Element("diffuse").Element("texture") != null)
                        {
                            foreach (var image in imageNodes.Elements("image"))
                            {
                                if (image.Attribute("id").Value.Equals(subNode.Element("diffuse").Element("texture").Attribute("texture").Value))
                                {
                                    Texture  texture = new Texture(image.Element("init_from").Value.Replace("file://", ""), false);
                                    Material mat     = new LambertMaterial(new Color(0, 0, 0));
                                    mat.ColorTexture = texture;
                                    Materials.Add(materialName, mat);
                                }
                            }
                        }
                        else
                        {
                            float shininess = 0f;
                            //Create Refractive Material
                            Color diffuse  = ParseColor(subNode.Element("diffuse").Element("color").Value);
                            Color specular = ParseColor(subNode.Element("specular").Element("color").Value);
                            try
                            {
                                shininess = (float)Convert.ToDouble(subNode.Element("shininess").Element("float").Value);
                            }
                            catch (Exception)
                            {
                            }
                            Material mat = new BlinnPhongMaterial(diffuse, specular, shininess);
                            Materials.Add(materialName, mat);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public ColladaScene()
        {
            FileName = "Assignment_Collada.jpg";
            ColladaParser parser = new ColladaParser();

            parser.ParseColladaFile("./geometries/collada/reference.dae", 1024);
            Integrator = (IIntegrator)Activator.CreateInstance(Constants.Integrator);

            /*Camera = new PinholeCamera()
             * {
             *  FieldOfViewX = 60f,
             *  FieldOfViewY = 60f,
             *  ScreenWidth = 128,
             *  ScreenHeight = 128,
             *  Eye = new Vector4(0, 0, -50, 1),
             *  Up = new Vector4(0, 1, 0, 1),
             *  LookAt = new Vector4(0, 0, 0, 1)
             * };
             * Camera.PreProcess();
             */

            LambertMaterial green = new LambertMaterial(new Color(0, 1, 0));
            LambertMaterial red   = new LambertMaterial(new Color(1, 0, 0));
            LambertMaterial blue  = new LambertMaterial(new Color(0, 0, 1));
            LambertMaterial gray  = new LambertMaterial(new Color(0.8f, 0.8f, 0.8f));
            LambertMaterial black = new LambertMaterial(new Color(0, 0, 0));
            LambertMaterial white = new LambertMaterial(new Color(1, 1, 1));

            //List of objects
            Sphere sphere = new Sphere(white, new Vector3(0, 0, .25f), .3f);


            Plane p1 = new Plane(1f, new Vector3(0, 1, 0))
            {
                Material = white
            };
            Plane p2 = new Plane(1f, new Vector3(0, 0, -1))
            {
                Material = white
            };
            Plane p3 = new Plane(1f, new Vector3(-1, 0, 0))
            {
                Material = green
            };
            Plane p4 = new Plane(1f, new Vector3(1, 0, 0))
            {
                Material = blue
            };
            Plane p5 = new Plane(1f, new Vector3(0, -1, 0))
            {
                Material = white
            };
            Rectangle rect = new Rectangle(new Vector3(-0.2f, .99f, 0f), new Vector3(.5f, 0, 0), new Vector3(0, 0, 0.5f))
            {
                Material = blue
            };

            Objects = new IntersectableList();

            /*
             * Objects.Add(p1);
             * Objects.Add(p2);
             * Objects.Add(p3);
             * Objects.Add(p4);
             * Objects.Add(p5);
             */
            Lights = new List <ILight>();

            foreach (ILight light in parser.Lights.Values)
            {
                Lights.Add(light);
            }
            foreach (IIntersectable intersectable in parser.Meshes.Values)
            {
                Objects.Add(intersectable);
            }



            foreach (ICamera camera in parser.Cameras.Values)
            {
                Camera = camera;
                Camera.PreProcess();
            }

            if (Camera == null || float.IsNaN(Camera.AspectRation))
            {
                Integrator = (IIntegrator)Activator.CreateInstance(Constants.Integrator);

                Camera.FieldOfViewX = 30f;
                Camera.FieldOfViewY = 30f;
                Camera.ScreenWidth  = 512;
                Camera.ScreenHeight = 512;
                Camera.Eye          = new Vector4(0, 0, -2, 1);
                Camera.Up           = new Vector4(0, 1, 0, 1);
                Camera.LookAt       = new Vector4(0, 0, 0, 1);

                Camera.PreProcess();
            }

            Film = new Film(Camera.ScreenWidth, Camera.ScreenHeight);
        }
Esempio n. 8
0
        public BasicScene()
        {
            FileName = "Assignment1_Basic.jpg";
            //scene = new Scene { BackgroundColor = Color.Black };
            Integrator = (IIntegrator)Activator.CreateInstance(Constants.Integrator);

            Camera.FieldOfView  = 60f;
            Camera.ScreenWidth  = 256;
            Camera.ScreenHeight = 256;
            Camera.Eye          = new Vector4(0, 0, -1f, 1);
            Camera.Up           = new Vector4(0, 1, 0, 1);
            Camera.LookAt       = new Vector4(0, 0, 0, 1);
            Camera.D            = 1f;
            Camera.Apperture    = 0.2f;
            Camera.PreProcess();

            Film = new Film(Camera.ScreenWidth, Camera.ScreenHeight);

            LambertMaterial green = new LambertMaterial(new Color(0, 1, 0));
            LambertMaterial red   = new LambertMaterial(new Color(1, 0, 0));
            LambertMaterial blue  = new LambertMaterial(new Color(0, 0, 1));
            LambertMaterial gray  = new LambertMaterial(new Color(0.8f, 0.8f, 0.8f));
            LambertMaterial black = new LambertMaterial(new Color(0, 0, 0));
            LambertMaterial white = new LambertMaterial(new Color(1, 1, 1));

            //List of objects
            Sphere sphere  = new Sphere(white, new Vector3(0, -.25f, 2f), 1f);
            Sphere sphere2 = new Sphere(white, new Vector3(3f, -.25f, 5f), 1f);

            Plane p1 = new Plane(20f, new Vector3(0, 1, 0))
            {
                Material = white
            };
            Plane p2 = new Plane(20f, new Vector3(0, 0, -1))
            {
                Material = white
            };
            Plane p6 = new Plane(20f, new Vector3(0, 0, 1))
            {
                Material = white
            };
            Plane p3 = new Plane(20f, new Vector3(-1, 0, 0))
            {
                Material = red
            };
            Plane p4 = new Plane(20f, new Vector3(1, 0, 0))
            {
                Material = blue
            };
            Plane p5 = new Plane(20f, new Vector3(0, -1, 0))
            {
                Material = white
            };

            /*Rectangle rect = new Rectangle(new Vector3(-0.2f, .99f, 0f), new Vector3(.5f, 0, 0), new Vector3(0, 0, 0.5f))
             * {
             *  Material = blue
             * };*/
            int[] i         = { 0, 1, 2, 2, 3, 0 };
            Mesh  rectangle = new Mesh(new LambertMaterial(new Color(0, 0, 1)), i,
                                       -.25f, .999998f, .25f,
                                       -.25f, .999999f, -.25f,
                                       .25f, .999999f, -.25f,
                                       .25f, .999998f, .25f);

            Objects = new IntersectableList();
            //Objects.Add(rect);
            //Objects.Add(rectangle);
            Objects.Add(sphere);
            Objects.Add(sphere2);
            Objects.Add(p1);
            Objects.Add(p2);
            Objects.Add(p3);
            Objects.Add(p4);
            Objects.Add(p5);
            Objects.Add(p6);
            Lights = new List <ILight>();



            ILight light = new DirectionalLight(new Vector3(0.0f, 0f, -1f), new Color(1, 1, 1));

            //ILight light = new AreaLight(new Color(1, 1, 1), rectangle);

            Lights.Add(light);
        }