Example #1
0
        public bool SetTexture(string name, string path)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Texture texture = null;

            try
            {
                texture = new warp_Texture(path);
            } catch (Exception)
            {
                return(false);
            }

            warp_Material material = (warp_Material)_scene.materialData [name];

            if (material == null)
            {
                return(false);
            }

            material.setTexture(texture);

            return(true);
        }
Example #2
0
        public bool SetBackgroundMaterial(string path)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Material material = null;

            try
            {
                material = new warp_Material(path);
            } catch (Exception)
            {
                return(false);
            }

            warp_Texture texture = material.getTexture();

            if (texture == null)
            {
                return(false);
            }

            _scene.environment.setBackground(texture);

            return(true);
        }
Example #3
0
        public bool AddMaterial(string name, int color)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Material material = new warp_Material(color);

            _scene.addMaterial(name, material);

            return(true);
        }
        public void destroy()
        {
            name         = null;
            material     = null;
            matrix       = null;
            normalmatrix = null;
            parent       = null;

            fastvertex   = null;
            fasttriangle = null;
            vertexData.Clear();
            triangleData.Clear();
        }
Example #5
0
        public void DisplayDefaultScene()
        {
            _scene = new warp_Scene(512, 512);

            warp_Material crystal = new warp_Material(warp_TextureFactory.MARBLE(128, 128, .15f));

            _scene.addMaterial("crystal", crystal);

            warp_Material c = (warp_Material)_scene.materialData ["crystal"];

            c.setReflectivity(255);
            c.setTransparency(100);

            _scene.environment.setBackground(warp_TextureFactory.CHECKERBOARD(128, 128, 3, 0x000000, 0x999999));

            _scene.addLight("light1", new warp_Light(new warp_Vector(0.2f, 0.2f, 1f), 0xFFFFFF, 320, 80));
            _scene.addLight("light2", new warp_Light(new warp_Vector(-1f, -1f, 1f), 0xffffff, 100, 40));

            warp_Vector[] path = new warp_Vector[15];

            path [0]  = new warp_Vector(0.0f, 0.2f, 0);
            path [1]  = new warp_Vector(0.13f, 0.25f, 0);
            path [2]  = new warp_Vector(0.33f, 0.3f, 0);
            path [3]  = new warp_Vector(0.43f, 0.6f, 0);
            path [4]  = new warp_Vector(0.48f, 0.9f, 0);
            path [5]  = new warp_Vector(0.5f, 0.9f, 0);
            path [6]  = new warp_Vector(0.45f, 0.6f, 0);
            path [7]  = new warp_Vector(0.35f, 0.3f, 0);
            path [8]  = new warp_Vector(0.25f, 0.2f, 0);
            path [9]  = new warp_Vector(0.1f, 0.15f, 0);
            path [10] = new warp_Vector(0.1f, 0.0f, 0);
            path [11] = new warp_Vector(0.1f, -0.5f, 0);
            path [12] = new warp_Vector(0.35f, -0.55f, 0);
            path [13] = new warp_Vector(0.4f, -0.6f, 0);
            path [14] = new warp_Vector(0.0f, -0.6f, 0);

            _scene.addObject("wineglass", warp_ObjectFactory.ROTATIONOBJECT(path, 32));
            _scene.sceneobject("wineglass").setMaterial(_scene.material("crystal"));

            _scene.sceneobject("wineglass").scale(0.8f, 0.8f, 0.8f);
            _scene.sceneobject("wineglass").rotate(0.5f, 0f, 0f);

            _scene.render();

            //Refresh();
        }
Example #6
0
        public bool SetWireframe(string name, bool w)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Material material = (warp_Material)_scene.materialData [name];

            if (material == null)
            {
                return(false);
            }

            material.setWireframe(w);

            return(true);
        }
Example #7
0
        public bool SetReflectivity(string name, int r)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Material material = (warp_Material)_scene.materialData [name];

            if (material == null)
            {
                return(false);
            }

            material.setReflectivity(r);

            return(true);
        }
Example #8
0
        public bool SetTransparency(string name, int t)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Material material = (warp_Material)_scene.materialData [name];

            if (material == null)
            {
                return(false);
            }

            material.setTransparency(t);

            return(true);
        }
Example #9
0
        public bool SetObjectMaterial(string name, string m)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Material material = (warp_Material)_scene.materialData [m];

            if (material == null)
            {
                return(false);
            }

            _scene.sceneobject(name).setMaterial(material);

            return(true);
        }
        // Material loader
        public void loadMaterial(warp_Material material)
        {
            color        = material.color;
            transparency = material.transparency;
            reflectivity = material.reflectivity;
            texture      = material.texture;
            if (material.envmap != null)
            {
                envmap = material.envmap.pixel;
            }
            else
            {
                envmap = null;
            }

            if (texture != null)
            {
                tw    = texture.width - 1;
                th    = texture.height - 1;
                tbitW = texture.bitWidth;
                tbitH = texture.bitHeight;
            }

            mode = 0;
            if (!material.flat)
            {
                mode |= P;
            }
            if (envmap != null)
            {
                mode |= E;
            }
            if (texture != null)
            {
                mode |= T;
            }
            if (material.wireframe)
            {
                mode |= W;
            }
            materialLoaded = true;
            ready          = lightmapLoaded && materialLoaded;
        }
Example #11
0
        public bool AddMaterial(string name, string path)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Material material = null;

            try
            {
                material = new warp_Material(path);
            } catch (Exception)
            {
                return(false);
            }

            _scene.addMaterial(name, material);

            return(true);
        }
        void CreateWater(WarpRenderer renderer, bool threeD)
        {
            float waterHeight = (float) m_scene.RegionInfo.RegionSettings.WaterHeight;

            warp_Material waterColormaterial;
            if (!threeD)
            {
                if(m_scene.RegionInfo.RegionSizeX >= m_scene.RegionInfo.RegionSizeY)
                    renderer.AddPlane ("Water", m_scene.RegionInfo.RegionSizeX/2);
                else
                    renderer.AddPlane ("Water", m_scene.RegionInfo.RegionSizeY/2);

                renderer.Scene.sceneobject ("Water").setPos ((m_scene.RegionInfo.RegionSizeX / 2) - 0.5f, waterHeight,
                    (m_scene.RegionInfo.RegionSizeY / 2) - 0.5f);
                               waterColormaterial = new warp_Material (ConvertColor (WATER_COLOR));
                waterColormaterial.setTransparency ((byte)((1f - WATER_COLOR.A) * 255f) * 2);
            } else
            {
                if(m_scene.RegionInfo.RegionSizeX >= m_scene.RegionInfo.RegionSizeY)
                    renderer.AddPlane ("Water", m_scene.RegionInfo.RegionSizeX/2);
                else
                    renderer.AddPlane ("Water", m_scene.RegionInfo.RegionSizeY/2);

                renderer.Scene.sceneobject ("Water").setPos (
                    (m_scene.RegionInfo.RegionSizeX / 2) -0.5f,
                    - 0.5f,
                    waterHeight+5.1f
                    );

                waterColormaterial = new warp_Material(ConvertColor(OPAQUE_WATER_COLOR));
                waterColormaterial.setTransparency (48);
                //waterColormaterial.opaque = true;
            }

            waterColormaterial.setReflectivity(0);
            renderer.Scene.addMaterial("WaterColor", waterColormaterial);
            renderer.SetObjectMaterial("Water", "WaterColor");
        }
Example #13
0
		// Material loader
		public void loadMaterial (warp_Material material)
		{
			color = material.color;
			transparency = material.transparency;
			reflectivity = material.reflectivity;
			texture = material.texture;
			if (material.envmap != null)
				envmap = material.envmap.pixel;
			else
				envmap = null;

			if (texture != null)
			{
				tw = texture.width - 1;
				th = texture.height - 1;
				tbitW = texture.bitWidth;
				tbitH = texture.bitHeight;
			}

			mode = 0;
			if (!material.flat)
				mode |= P;
			if (envmap != null)
				mode |= E;
			if (texture != null)
				mode |= T;
			if (material.wireframe)
				mode |= W;
			materialLoaded = true;
			ready = lightmapLoaded && materialLoaded;
		}
Example #14
0
		public bool AddMaterial (string name, string path)
		{
			if (_scene == null)
			{
				return false;
			}

			warp_Material material = null;
			try
			{
				material = new warp_Material (path);
			} catch (Exception)
			{
				return false;
			}

			_scene.addMaterial (name, material);

			return true;
		}
Example #15
0
		public void DisplayDefaultScene ()
		{
			_scene = new warp_Scene (512, 512);

			warp_Material crystal = new warp_Material (warp_TextureFactory.MARBLE (128, 128, .15f));
			_scene.addMaterial ("crystal", crystal);

			warp_Material c = (warp_Material)_scene.materialData ["crystal"];
			c.setReflectivity (255);
			c.setTransparency (100);

			_scene.environment.setBackground (warp_TextureFactory.CHECKERBOARD (128, 128, 3, 0x000000, 0x999999));

			_scene.addLight ("light1", new warp_Light (new warp_Vector (0.2f, 0.2f, 1f), 0xFFFFFF, 320, 80));
			_scene.addLight ("light2", new warp_Light (new warp_Vector (-1f, -1f, 1f), 0xffffff, 100, 40));

			warp_Vector[] path = new warp_Vector[15];

			path [0] = new warp_Vector (0.0f, 0.2f, 0);
			path [1] = new warp_Vector (0.13f, 0.25f, 0);
			path [2] = new warp_Vector (0.33f, 0.3f, 0);
			path [3] = new warp_Vector (0.43f, 0.6f, 0);
			path [4] = new warp_Vector (0.48f, 0.9f, 0);
			path [5] = new warp_Vector (0.5f, 0.9f, 0);
			path [6] = new warp_Vector (0.45f, 0.6f, 0);
			path [7] = new warp_Vector (0.35f, 0.3f, 0);
			path [8] = new warp_Vector (0.25f, 0.2f, 0);
			path [9] = new warp_Vector (0.1f, 0.15f, 0);
			path [10] = new warp_Vector (0.1f, 0.0f, 0);
			path [11] = new warp_Vector (0.1f, -0.5f, 0);
			path [12] = new warp_Vector (0.35f, -0.55f, 0);
			path [13] = new warp_Vector (0.4f, -0.6f, 0);
			path [14] = new warp_Vector (0.0f, -0.6f, 0);

			_scene.addObject ("wineglass", warp_ObjectFactory.ROTATIONOBJECT (path, 32));
			_scene.sceneobject ("wineglass").setMaterial (_scene.material ("crystal"));

			_scene.sceneobject ("wineglass").scale (0.8f, 0.8f, 0.8f);
			_scene.sceneobject ("wineglass").rotate (0.5f, 0f, 0f);

			_scene.render ();

			//Refresh();
		}
Example #16
0
		public void setMaterial (warp_Material m)
		{
			material = m;
		}
Example #17
0
		public bool AddMaterial (string name, int color)
		{
			if (_scene == null)
			{
				return false;
			}

			warp_Material material = new warp_Material (color);
			_scene.addMaterial (name, material);

			return true;
		}
        void CreateWater (WarpRenderer renderer, bool threeD)
        {
            float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight;
            int maxSize = m_scene.RegionInfo.RegionSizeX;
            if (m_scene.RegionInfo.RegionSizeY >= maxSize)
                maxSize = m_scene.RegionInfo.RegionSizeY;

            warp_Material waterColormaterial;
            if (!threeD) {
                // 20160210 -greythane-
                // it appears that the default plan object is rotated 45 degrees
                // work-a-round until verified or otherwise in the Warp3D library
                renderer.AddPlane ("Water", maxSize);
                renderer.Scene.sceneobject ("Water").setPos (0, waterHeight, 0);

                /* reference    if(m_scene.RegionInfo.RegionSizeX >= m_scene.RegionInfo.RegionSizeY)
                                    renderer.AddPlane ("Water", m_scene.RegionInfo.RegionSizeX/2);
                                else
                                    renderer.AddPlane ("Water", m_scene.RegionInfo.RegionSizeY/2);

                                renderer.Scene.sceneobject ("Water").setPos (
                                    (m_scene.RegionInfo.RegionSizeX / 2) - 0.5f,
                                    waterHeight,
                                    (m_scene.RegionInfo.RegionSizeY / 2) - 0.5f);


                */
                waterColormaterial = new warp_Material (ConvertColor (WATER_COLOR));
                //  waterColormaterial.setTransparency ((byte)((1f - WATER_COLOR.A) * 255f) * 2);
                waterColormaterial.setTransparency ((byte)((1f - WATER_COLOR.A) * 255f));
            } else {
                renderer.AddPlane ("Water", maxSize / 2);

                /* for reference
                                if(m_scene.RegionInfo.RegionSizeX >= m_scene.RegionInfo.RegionSizeY)
                                    renderer.AddPlane ("Water", m_scene.RegionInfo.RegionSizeX/2);
                                else
                                    renderer.AddPlane ("Water", m_scene.RegionInfo.RegionSizeY/2);
                */
                renderer.Scene.sceneobject ("Water").setPos (
                    (m_scene.RegionInfo.RegionSizeX / 2f) - 0.5f,
                    -0.5f,
                    waterHeight + 5.1f
                    );

                waterColormaterial = new warp_Material (ConvertColor (OPAQUE_WATER_COLOR));
                waterColormaterial.setTransparency (48);
                //waterColormaterial.opaque = true;
            }

            waterColormaterial.setReflectivity (0);
            renderer.Scene.addMaterial ("WaterColor", waterColormaterial);
            renderer.SetObjectMaterial ("Water", "WaterColor");
        }
 public void setMaterial(warp_Material m)
 {
     material = m;
 }
 public void addMaterial(String key, warp_Material m)
 {
     materialData.Add(key, m);
 }
Example #21
0
		public void addMaterial (String key, warp_Material m)
		{
			materialData.Add (key, m);
		}
        warp_Object CreateTerrain (WarpRenderer renderer, bool textureTerrain)
        {
            ITerrainChannel terrain = m_scene.RequestModuleInterface<ITerrainChannel> ();

            float diffX = 1.0f; //(float) m_scene.RegionInfo.RegionSizeX/(float) Constants.RegionSize;
            float diffY = 1.0f; //(float) m_scene.RegionInfo.RegionSizeY/(float) Constants.RegionSize;
            int newRsX = m_scene.RegionInfo.RegionSizeX / (int)diffX;
            int newRsY = m_scene.RegionInfo.RegionSizeY / (int)diffY;

            warp_Object obj = new warp_Object (newRsX * newRsY, ((newRsX - 1) * (newRsY - 1) * 2));

            for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diffY) {
                for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diffX) {
                    float t_height = terrain [(int)x, (int)y];
                    float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight;

                    //clamp to eliminate artifacts
                    t_height = Utils.Clamp (t_height, waterHeight - 0.5f, waterHeight + 0.5f);
                    if (t_height < 0.0f) t_height = 0.0f;

                    warp_Vector pos = ConvertVector (x / diffX, y / diffY, t_height);
                    obj.addVertex (
                        new warp_Vertex (pos,
                                        x / m_scene.RegionInfo.RegionSizeX,
                                        (m_scene.RegionInfo.RegionSizeY - y) / (m_scene.RegionInfo.RegionSizeY)));
                }
            }

            const float normal_map_reduction = 2.0f; //2.0f-2.5f is the sweet spot

            for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diffY) {
                for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diffX) {
                    float newX = x / diffX;
                    float newY = y / diffY;

                    if (newX < newRsX - 1 && newY < newRsY - 1) {
                        int v = (int)(newY * newRsX + newX);

                        // Normal
                        Vector3 v1 = new Vector3 (newX, newY, (terrain [(int)x, (int)y]) / normal_map_reduction);
                        Vector3 v2 = new Vector3 (newX + 1, newY,
                                                 (terrain [(int)x + 1, (int)y]) / normal_map_reduction);
                        Vector3 v3 = new Vector3 (newX, newY + 1,
                                                 (terrain [(int)x, (int)(y + 1)]) / normal_map_reduction);
                        warp_Vector norm = ConvertVector (SurfaceNormal (v1, v2, v3));
                        norm = norm.reverse ();
                        obj.vertex (v).n = norm;

                        // Triangle 1
                        obj.addTriangle (
                            v,
                            v + 1,
                            v + newRsX);

                        // Triangle 2
                        obj.addTriangle (
                            v + newRsX + 1,
                            v + newRsX,
                            v + 1);
                    }
                }
            }

            renderer.Scene.addObject ("Terrain", obj);
            renderer.Scene.sceneobject ("Terrain").setPos (0.0f, 0.0f, 0.0f);

            UUID [] textureIDs = new UUID [4];
            float [] startHeights = new float [4];
            float [] heightRanges = new float [4];

            RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings;

            textureIDs [0] = regionInfo.TerrainTexture1;
            textureIDs [1] = regionInfo.TerrainTexture2;
            textureIDs [2] = regionInfo.TerrainTexture3;
            textureIDs [3] = regionInfo.TerrainTexture4;

            startHeights [0] = (float)regionInfo.Elevation1SW;
            startHeights [1] = (float)regionInfo.Elevation1NW;
            startHeights [2] = (float)regionInfo.Elevation1SE;
            startHeights [3] = (float)regionInfo.Elevation1NE;

            heightRanges [0] = (float)regionInfo.Elevation2SW;
            heightRanges [1] = (float)regionInfo.Elevation2NW;
            heightRanges [2] = (float)regionInfo.Elevation2SE;
            heightRanges [3] = (float)regionInfo.Elevation2NE;

            uint globalX, globalY;
            Utils.LongToUInts (m_scene.RegionInfo.RegionHandle, out globalX, out globalY);

            Bitmap image = TerrainSplat.Splat (terrain, textureIDs, startHeights, heightRanges,
                                              new Vector3d (globalX, globalY, 0.0), m_scene.AssetService, textureTerrain);
            warp_Texture texture = new warp_Texture (image);
            warp_Material material = new warp_Material (texture);
            material.setReflectivity (0); // reduces tile seams a bit thanks lkalif
            renderer.Scene.addMaterial ("TerrainColor", material);
            renderer.SetObjectMaterial ("Terrain", "TerrainColor");

            image.Dispose ();

            return obj;
        }
Example #23
0
		public bool SetBackgroundMaterial (string path)
		{
			if (_scene == null)
			{
				return false;
			}

			warp_Material material = null;
			try
			{
				material = new warp_Material (path);
			} catch (Exception)
			{
				return false;
			}

			warp_Texture texture = material.getTexture ();
			if (texture == null)
			{
				return false;
			}

			_scene.environment.setBackground (texture);

			return true;
		}