public SceneDatabase()
        {
            mAllGeoms = new SceneResource<RTGeometry>();
            mAllMaterials = new SceneResource<RTMaterial>();
            mAllTextures = new SceneResource<RTTexture>();
            mAllLights = new SceneResource<RTLight>();

            // the default material: index of 0
            RTMaterial m = new RTMaterial();
            mAllMaterials.AddResource(m);
        }
Exemple #2
0
    public uint collectMaterial(GameObject primitive)
    {
        RT_Material temp = primitive.GetComponent <RT_Material>();

        if (temp != null)
        {
            RT_Material_Instance instance = temp.RT_material;

            if (instance == null)
            {
                return(0);
            }

            string matName = instance.name;

            if (materialMap.ContainsKey(matName))
            {
                return(materialMap[matName]);
            }

            RTMaterial mat = new RTMaterial()
            {
                color       = new Vector3(instance.color.r, instance.color.g, instance.color.b),
                specular    = new Vector3(instance.specular.R, instance.specular.G, instance.specular.B),
                diffuse     = new Vector3(instance.diffuse.R, instance.diffuse.G, instance.diffuse.B),
                reflectness = new Vector3(instance.reflectness.R, instance.reflectness.G, instance.reflectness.B),
                shininess   = instance.shininess
            };

            uint index = (uint)materials.Count;
            materials.Add(mat);
            materialMap.Add(matName, index);
            return(index);
        }

        return(0);
    }
 /// <summary>
 /// Material: can only be access given an index (the collection may be a sparse array!)
 /// </summary>
 /// <param name="m"></param>
 public void AddMaterial(RTMaterial m)
 {
     mAllMaterials.AddResource(m);
 }
        public CommandFileParser(String cmdFile, ContentManager meshLoader, System.Windows.Forms.TextBox statusArea, RTCore rt, SceneDatabase scene)
        {
            mStatusArea = statusArea;

            mFullPath = System.IO.Path.GetFullPath(System.IO.Path.GetDirectoryName(cmdFile));

            mParser = new XmlTextReader(cmdFile);
            mParser.WhitespaceHandling = WhitespaceHandling.None;

            ParserRead();
            while (!IsEndElement("RayTracer_552"))
            {
                if (IsElement() && (!IsElement("RayTracer_552")) )
                {
                    if (IsElement("camera"))
                    {
                        RTCamera c = new RTCamera(this);
                        rt.SetCamera(c);
                        ParserRead();
                    }
                    else if (IsElement("sphere"))
                    {
                        RTSphere s = new RTSphere(this);
                        scene.AddGeom(s);
                        ParserRead();
                    }
                    else if (IsElement("rectangle"))
                    {
                        RTRectangle r = new RTRectangle(this);
                        scene.AddGeom(r);
                        ParserRead();
                    }
                    else if (IsElement("triangle"))
                    {
                        RTTriangle t = new RTTriangle(this);
                        scene.AddGeom(t);
                        ParserRead();
                    }
                    else if (IsElement("mesh"))
                    {
                        RTTriangle.ParseMeshForTriangles(this, meshLoader, scene);
                        ParserRead();
                    }
                    else if (IsElement("imagespec"))
                    {
                        ImageSpec s = new ImageSpec(this);
                        rt.SetImageSpec(s);
                        ParserRead();
                    }
                    else if (IsElement("rtspec"))
                    {
                        rt.Parse(this);
                        ParserRead();
                    }
                    else if (IsElement("material"))
                    {
                        RTMaterial m = new RTMaterial(this);
                        scene.AddMaterial(m);
                        ParserRead();
                    }
                    else if (IsElement("light"))
                    {
                        RTLight l = new RTLight(this);
                        scene.AddLight(l);
                        ParserRead();
                    }
                    else if (IsElement("texture"))
                    {
                        RTTexture t = new RTTexture(this);
                        scene.AddTexture(t);
                        ParserRead();
                    }
                    else
                        ParserError("Main Parser:");
                }
                else
                    ParserRead();
            }
            mParser.Close();

            if (!mHasError)
                mStatusArea.Text = "Parsing Completed!";
        }
Exemple #5
0
 public T SetMaterial <T>(RTMaterial material) where T : Hitable
 {
     this.material = material;
     return((T)this);
 }