예제 #1
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;
        }
예제 #2
0
        private void CreateWater(WarpRenderer renderer)
        {
            float waterHeight = (float) m_scene.RegionInfo.RegionSettings.WaterHeight;

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

            warp_Material waterColormaterial = new warp_Material(ConvertColor(WATER_COLOR));
            waterColormaterial.setTransparency((byte) ((1f - WATER_COLOR.A)*255f)*2);
            waterColormaterial.setReflectivity(50);
            renderer.Scene.addMaterial("WaterColor", waterColormaterial);
            renderer.SetObjectMaterial("Water", "WaterColor");
        }
예제 #3
0
 public void addMaterial(String key, warp_Material m)
 {
     materialData.Add(key, m);
 }
예제 #4
0
        private void CreateWater(WarpRenderer renderer)
        {
            float waterHeight = (float) m_scene.RegionInfo.RegionSettings.WaterHeight;

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

            RegionLightShareData rls = m_scene.RequestModuleInterface<IWindLightSettingsModule>().FindRegionWindLight();

            warp_Material waterColormaterial;
            if (rls != null)
                waterColormaterial =
                    new warp_Material(
                        ConvertColor(new Color4(rls.waterColor.X/256, rls.waterColor.Y/256, rls.waterColor.Z/256,
                                                WATER_COLOR.A)));
            else
                waterColormaterial = new warp_Material(ConvertColor(WATER_COLOR));

            waterColormaterial.setTransparency((byte) ((1f - WATER_COLOR.A)*255f)*2);
            waterColormaterial.setReflectivity(50);
            renderer.Scene.addMaterial("WaterColor", waterColormaterial);
            renderer.SetObjectMaterial("Water", "WaterColor");

            /*
            AssetBase textureAsset = m_scene.AssetService.Get(rls.normalMapTexture.ToString());
            if (textureAsset != null)
            {
                IJ2KDecoder decoder = m_scene.RequestModuleInterface<IJ2KDecoder> ();
                Bitmap bitmap = (Bitmap)decoder.DecodeToImage (textureAsset.Data);
                if (bitmap != null)
                {
                    textureAsset = null;
                    warp_Texture texture = new warp_Texture (bitmap);
                    warp_Material waterTextmaterial = new warp_Material (texture);
                    waterTextmaterial.setTransparency ((byte)((1f - WATER_COLOR.A) * 255f) * 4);
                    waterTextmaterial.setReflectivity (0);
                    renderer.AddPlane ("Water2", m_scene.RegionInfo.RegionSizeX * 0.5f);
                    renderer.Scene.sceneobject ("Water2").setPos ((m_scene.RegionInfo.RegionSizeX / 2) - 0.5f, waterHeight, (m_scene.RegionInfo.RegionSizeY / 2) - 0.5f);
                    renderer.Scene.addMaterial ("WaterColor2", waterTextmaterial);
                    renderer.SetObjectMaterial ("Water2", "WaterColor2");
                }
            }*/
        }
예제 #5
0
 public void setMaterial(warp_Material m)
 {
     material = m;
 }
        // 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;
        }
예제 #7
0
        private void CreateTerrain(WarpRenderer renderer, bool textureTerrain)
        {
            ITerrainChannel terrain = m_scene.Heightmap;
            float[] heightmap = terrain.GetFloatsSerialised();

            warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2);

            for (int y = 0; y < 256; y++)
            {
                for (int x = 0; x < 256; x++)
                {
                    int v = y * 256 + x;
                    float height = heightmap[v];

                    warp_Vector pos = ConvertVector(new Vector3(x, y, height));
                    obj.addVertex(new warp_Vertex(pos, (float)x / 255f, (float)(255 - y) / 255f));
                }
            }

            for (int y = 0; y < 256; y++)
            {
                for (int x = 0; x < 256; x++)
                {
                    if (x < 255 && y < 255)
                    {
                        int v = y * 256 + x;

                        // Normal
                        Vector3 v1 = new Vector3(x, y, heightmap[y * 256 + x]);
                        Vector3 v2 = new Vector3(x + 1, y, heightmap[y * 256 + x + 1]);
                        Vector3 v3 = new Vector3(x, y + 1, heightmap[(y + 1) * 256 + x]);
                        warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3));
                        norm = norm.reverse();
                        obj.vertex(v).n = norm;

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

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

            renderer.Scene.addObject("Terrain", obj);

            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(heightmap, 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(50);
            renderer.Scene.addMaterial("TerrainColor", material);
			renderer.Scene.material("TerrainColor").setReflectivity(0); // reduces tile seams a bit thanks lkalif
            renderer.SetObjectMaterial("Terrain", "TerrainColor");
        }
예제 #8
0
        // Add a water plane to the renderer.
        private void CreateWater(WarpRenderer renderer)
        {
            float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight;

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

            warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR));
			waterColorMaterial.setReflectivity(0);  // match water color with standard map module thanks lkalif
            waterColorMaterial.setTransparency((byte)((1f - WATER_COLOR.A) * 255f));
            renderer.Scene.addMaterial("WaterColor", waterColorMaterial);
            renderer.SetObjectMaterial("Water", "WaterColor");
        }
예제 #9
0
        private void CreateTerrain(WarpRenderer renderer, bool textureTerrain)
        {
            ITerrainChannel terrain = m_scene.RequestModuleInterface<ITerrainChannel>();

            warp_Object obj = new warp_Object (m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY, (m_scene.RegionInfo.RegionSizeX - 1) * (m_scene.RegionInfo.RegionSizeY - 1) * 2);

            for (int y = 0; y < m_scene.RegionInfo.RegionSizeY; y++)
            {
                for (int x = 0; x < m_scene.RegionInfo.RegionSizeX; x++)
                {
                    float height = terrain[x, y];

                    warp_Vector pos = ConvertVector(new Vector3(x, y, height));
                    obj.addVertex (new warp_Vertex (pos, (float)x / (m_scene.RegionInfo.RegionSizeX - 1), (float)((m_scene.RegionInfo.RegionSizeX - 1) - y) / (m_scene.RegionInfo.RegionSizeX - 1)));
                }
            }

            for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += 1)
            {
                for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += 1)
                {
                    if (x < m_scene.RegionInfo.RegionSizeX - 1 && y < m_scene.RegionInfo.RegionSizeY - 1)
                    {
                        float v = y * m_scene.RegionInfo.RegionSizeX + x;

                        // Normal
                        warp_Vector norm = new warp_Vector(x, y, terrain.GetNormalizedGroundHeight((int)x, (int)y));
                        norm = norm.reverse();
                        obj.vertex ((int)v).n = norm;

                        // Triangle 1
                        obj.addTriangle(
                            (int)v,
                            (int)v + 1,
                            (int)v + m_scene.RegionInfo.RegionSizeX);

                        // Triangle 2
                        obj.addTriangle(
                            (int)v + m_scene.RegionInfo.RegionSizeX + 1,
                            (int)v + m_scene.RegionInfo.RegionSizeX,
                            (int)v + 1);
                    }
                }
            }

            renderer.Scene.addObject("Terrain", obj);

            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(50);
            renderer.Scene.addMaterial("TerrainColor", material);
            renderer.SetObjectMaterial("Terrain", "TerrainColor");
        }
예제 #10
0
파일: Warp3D.cs 프로젝트: Belxjander/Asuna
		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();
		}
예제 #11
0
파일: Warp3D.cs 프로젝트: Belxjander/Asuna
        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;
        }
예제 #12
0
파일: Warp3D.cs 프로젝트: Belxjander/Asuna
        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;
        }
예제 #13
0
파일: Warp3D.cs 프로젝트: Belxjander/Asuna
        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;
        }
예제 #14
0
		public void addMaterial(String key, warp_Material m)
		{
			materialData.Add(key, m);
		}
예제 #15
0
        // Add a terrain to the renderer.
        // Note that we create a 'low resolution' 256x256 vertex terrain rather than trying for
        //    full resolution. This saves a lot of memory especially for very large regions.
        private void CreateTerrain(WarpRenderer renderer, bool textureTerrain)
        {
            ITerrainChannel terrain = m_scene.Heightmap;

            // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding
            float diff = (float)m_scene.RegionInfo.RegionSizeX / 256f;

            warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2);

            // Create all the vertices for the terrain
            for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff)
            {
                for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff)
                {
                    warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]);
                    obj.addVertex(new warp_Vertex(pos,
                        x / (float)m_scene.RegionInfo.RegionSizeX,
                        (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY));
                }
            }

            // Now that we have all the vertices, make another pass and create
            //     the normals for each of the surface triangles and
            //     create the list of triangle indices.
            for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff)
            {
                for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff)
                {
                    float newX = x / diff;
                    float newY = y / diff;
                    if (newX < 255 && newY < 255)
                    {
                        int v = (int)newY * 256 + (int)newX;

                        // Normal for a triangle made up of three adjacent vertices
                        Vector3 v1 = new Vector3(newX, newY, (float)terrain[(int)x, (int)y]);
                        Vector3 v2 = new Vector3(newX + 1, newY, (float)terrain[(int)(x + 1), (int)y]);
                        Vector3 v3 = new Vector3(newX, newY + 1, (float)terrain[(int)x, ((int)(y + 1))]);
                        warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3));
                        norm = norm.reverse();
                        obj.vertex(v).n = norm;

                        // Make two triangles for each of the squares in the grid of vertices
                        obj.addTriangle(
                            v,
                            v + 1,
                            v + 256);

                        obj.addTriangle(
                            v + 256 + 1,
                            v + 256,
                            v + 1);
                    }
                }
            }

            renderer.Scene.addObject("Terrain", obj);

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

            OpenSim.Framework.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;
            Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY);

            warp_Texture texture;
            using (
                Bitmap image
                    = TerrainSplat.Splat(
                        terrain, textureIDs, startHeights, heightRanges,
                        new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain))
            {
                texture = new warp_Texture(image);
            }

            warp_Material material = new warp_Material(texture);
            material.setReflectivity(50);
            renderer.Scene.addMaterial("TerrainColor", material);
			renderer.Scene.material("TerrainColor").setReflectivity(0); // reduces tile seams a bit thanks lkalif
            renderer.SetObjectMaterial("Terrain", "TerrainColor");
        }
예제 #16
0
        private warp_Object CreateTerrain(WarpRenderer renderer, bool textureTerrain)
        {
            ITerrainChannel terrain = m_scene.RequestModuleInterface<ITerrainChannel>();

            float diff = (float) m_scene.RegionInfo.RegionSizeY/(float) Constants.RegionSize;
            warp_Object obj =
                new warp_Object(Constants.RegionSize*Constants.RegionSize,
                                ((Constants.RegionSize - 1)*(Constants.RegionSize - 1)*2));

            for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff)
            {
                for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff)
                {
                    warp_Vector pos = ConvertVector(x, y, terrain[(int) x, (int) y]);
                    obj.addVertex(new warp_Vertex(pos, x/(float) (m_scene.RegionInfo.RegionSizeX),
                                                  (((float) m_scene.RegionInfo.RegionSizeX) - y)/
                                                  (m_scene.RegionInfo.RegionSizeX)));
                }
            }

            for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff)
            {
                for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff)
                {
                    float newX = x/diff;
                    float newY = y/diff;
                    if (newX < Constants.RegionSize - 1 && newY < Constants.RegionSize - 1)
                    {
                        int v = (int) (newY*Constants.RegionSize + newX);

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

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

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

            renderer.Scene.addObject("Terrain", obj);

            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");
            return obj;
        }
예제 #17
0
		public void setMaterial(warp_Material m)
		{
			material = m;
		}
예제 #18
0
        private void CreateTerrain(IScene scene, WarpRenderer renderer, ITerrain terrain, RegionInfo regionInfo)
        {
            float[] heightmap = (terrain != null) ? terrain.GetHeightmap() : new float[256 * 256];

            warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2);

            for (int y = 0; y < 256; y++)
            {
                for (int x = 0; x < 256; x++)
                {
                    int v = y * 256 + x;
                    float height = heightmap[v];

                    warp_Vector pos = ConvertVector(new Vector3(x, y, height));
                    obj.addVertex(new warp_Vertex(pos, (float)x / 255f, (float)(255 - y) / 255f));
                }
            }

            for (int y = 0; y < 256; y++)
            {
                for (int x = 0; x < 256; x++)
                {
                    if (x < 255 && y < 255)
                    {
                        int v = y * 256 + x;

                        // Normal
                        Vector3 v1 = new Vector3(x, y, heightmap[y * 256 + x]);
                        Vector3 v2 = new Vector3(x + 1, y, heightmap[y * 256 + x + 1]);
                        Vector3 v3 = new Vector3(x, y + 1, heightmap[(y + 1) * 256 + x]);
                        warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3));
                        norm = norm.reverse();
                        obj.vertex(v).n = norm;

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

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

            renderer.Scene.addObject("Terrain", obj);

            UUID[] textureIDs = new UUID[4];
            float[] startHeights = new float[4];
            float[] heightRanges = new float[4];
            if (regionInfo != null)
            {
                textureIDs[0] = regionInfo.TerrainDetail0;
                textureIDs[1] = regionInfo.TerrainDetail1;
                textureIDs[2] = regionInfo.TerrainDetail2;
                textureIDs[3] = regionInfo.TerrainDetail3;

                startHeights[0] = regionInfo.TerrainStartHeight00;
                startHeights[1] = regionInfo.TerrainStartHeight01;
                startHeights[2] = regionInfo.TerrainStartHeight10;
                startHeights[3] = regionInfo.TerrainStartHeight11;

                heightRanges[0] = regionInfo.TerrainHeightRange00;
                heightRanges[1] = regionInfo.TerrainHeightRange01;
                heightRanges[2] = regionInfo.TerrainHeightRange10;
                heightRanges[3] = regionInfo.TerrainHeightRange11;
            }

            Bitmap image = TerrainSplat.Splat(heightmap, textureIDs, startHeights, heightRanges, scene.MinPosition, m_assetClient);
            warp_Texture texture = new warp_Texture(image);
            warp_Material material = new warp_Material(texture);
            material.setReflectivity(50);
            renderer.Scene.addMaterial("TerrainColor", material);
            renderer.SetObjectMaterial("Terrain", "TerrainColor");
        }