상속: NativeElement
예제 #1
0
파일: Sea.cs 프로젝트: yooyke/work
        private void CreateSea()
        {
            Mesh mesh = new Mesh();
            MeshBuffer mb = new MeshBuffer(VertexType.Standard);
            for (int h = 0; h < TILE_H_NUMBER; h++)
            {
                for (int w = 0; w < TILE_W_NUMBER; w++)
                {
                    mb.SetVertex((uint)(h * TILE_H_NUMBER + TILE_W_NUMBER), new Vertex3D(
                        new Vector3D(w * TILE_SPAN, h * TILE_SPAN, 19.8f),
                        new Vector3D(0, 0, 1),
                        Color.White,
                        new Vector2D((float)w / TILE_W_NUMBER, (float)h / TILE_H_NUMBER)
                        ));
                }
            }

            uint index = 0;
            for (int h = 0; h < (int)(TILE_H_NUMBER - 1); h++)
            {
                for (int w = 0; w < (int)(TILE_W_NUMBER - 1); w++)
                {
                    mb.SetIndex(index++, (ushort)((h + 0) * TILE_H_NUMBER + (w + 0)));
                    mb.SetIndex(index++, (ushort)((h + 0) * TILE_H_NUMBER + (w + 1)));
                    mb.SetIndex(index++, (ushort)((h + 1) * TILE_H_NUMBER + (w + 0)));

                    mb.SetIndex(index++, (ushort)((h + 1) * TILE_H_NUMBER + (w + 0)));
                    mb.SetIndex(index++, (ushort)((h + 0) * TILE_H_NUMBER + (w + 1)));
                    mb.SetIndex(index++, (ushort)((h + 1) * TILE_H_NUMBER + (w + 1)));
                }
            }
            mb.Material.Texture1 = Render.Texture.GetTexture(Path.Combine(dir, "sea.jpg"));
            mb.Material.BackfaceCulling = false;
            mesh.AddMeshBuffer(mb);

            MeshSceneNode node = Render.Scene.AddMeshSceneNode(mesh, Root, -1);
            node.Position = new Vector3D(-(TILE_W_NUMBER * TILE_SPAN / 2), -(TILE_H_NUMBER * TILE_SPAN / 2), 0);
            node.AutomaticCulling = CullingType.Off;
        }
예제 #2
0
        public void create_mesh()
        {
            _mesh = new Mesh();
            // add default mesh buffer
            MeshBuffer mbuffer = new MeshBuffer(VertexType.Standard);

            //////add a default shape

            ////vertices
            //mbuffer.AllocateVertices(4);
            //mbuffer.SetVertex(0,new Vertex3D(new Vector3D(0, 0, 10), new Vector3D(1, 1, 0), Color.From(255, 0, 255, 255), new Vector2D(0, 1)));

            //mbuffer.SetVertex(1, new Vertex3D(new Vector3D(10, 0, -10), new Vector3D(1, 0, 0), Color.From(255, 255, 0, 255), new Vector2D(1, 1)));

            //mbuffer.SetVertex(2, new Vertex3D(new Vector3D(0, 20, 0), new Vector3D(0, 1, 1), Color.From(255, 255, 255, 0), new Vector2D(1, 0)));

            //mbuffer.SetVertex(3, new Vertex3D(new Vector3D(-10, 0, -10), new Vector3D(0, 0, 1), Color.From(255, 0, 255, 0), new Vector2D(0, 0)));

            //// alocate indices

            //mbuffer.AllocateIndices(12);
            //mbuffer.SetIndex(0, 0);
            //mbuffer.SetIndex(1, 2);
            //mbuffer.SetIndex(2, 3);
            //mbuffer.SetIndex(3, 2);
            //mbuffer.SetIndex(4, 1);
            //mbuffer.SetIndex(5, 3);
            //mbuffer.SetIndex(6, 1);
            //mbuffer.SetIndex(7, 0);
            //mbuffer.SetIndex(8, 3);
            //mbuffer.SetIndex(9, 2);
            //mbuffer.SetIndex(10, 0);
            //mbuffer.SetIndex(11, 1);

            _mesh.AddMeshBuffer(mbuffer);
        }
예제 #3
0
파일: Prim.cs 프로젝트: yooyke/work
        private Mesh CreateMesh(MeshData[] meshes)
        {
            Mesh mesh = new Mesh();

            foreach (MeshData data in meshes)
            {
                if (data == null)
                    continue;

                bool use_alpha = (data.Color[0] < 0.9999f);

                MeshBuffer mb = new MeshBuffer(VertexType.Standard);
                for (uint i = 0; i < data.Indices.Length; i++)
                {
                    VertexData v = data.Vertices[data.Indices[i]];
                    mb.SetVertex(i, new Vertex3D(
                        new Vector3D(v.Position[0], v.Position[1], v.Position[2]),
                        new Vector3D(v.Normal[0], v.Normal[1], v.Normal[2]),
                        Color.White,
                        new Vector2D(v.UV[0], v.UV[1])
                        ));

                    mb.SetIndex(i, (ushort)data.Indices[i]);
                }
                mb.SetColor(Util.ToColor(data.Color[0], data.Color[1], data.Color[2], data.Color[3]));
                mb.Material.AmbientColor = Util.ToColor(1, data.Color[1], data.Color[2], data.Color[3]);
                TextureInfo info = null;
                if (data.Texture1DownLoaded)
                    info = Render.Texture.GetTexture(Path.Combine(Ox.Paths.Cache, data.Texture1), true, true);
                if (info != null)
                {
                    mb.Material.Texture1 = (info.Texture == null) ? Render.RenderData.BlankTexture : info.Texture;
                    use_alpha |= info.UseAlpha;
                }
                mb.Material.MaterialType = use_alpha ? MaterialType.TransparentAlphaChannel : MaterialType.Solid;

                mesh.AddMeshBuffer(mb);
            }

            return mesh;
        }
예제 #4
0
 /// <summary>
 /// Gets the meshbuffer data based on a specified level of detail. 
 /// </summary>
 /// <param name="mb">A reference to an MeshBuffer object</param> 
 /// <param name="LOD">the level of detail you want the indices from.</param>
 public void GetMeshBufferForLOD(ref MeshBuffer mb, int LOD)
 {
     TerrainSceneNode_GetMeshBufferForLOD(_raw, mb.Raw, LOD);
 }
예제 #5
0
 public void DrawMeshBuffer(MeshBuffer buffer)
 {
     VideoDriver_DrawMeshBuffer(_raw, buffer.Raw);
 }
예제 #6
0
 public void AddMeshBuffer(MeshBuffer mb)
 {
     Mesh_AddMeshBuffer(_raw, mb.Raw);
 }
예제 #7
0
        // experimental - build sculpt mesh using indexed access to vertex, normal, and UV lists
        private static Mesh SculptMeshToIrrMesh(SculptMesh sculptMesh)
        {
            Color color = new Color(255, 255, 255, 255);

            Mesh mesh = new Mesh();

            int numFaces = sculptMesh.faces.Count;

            MeshBuffer mb = new MeshBuffer(VertexType.Standard);

            int numVerts = sculptMesh.coords.Count;

            try
            {
                for (int i = 0; i < numVerts; i++)
                    mb.SetVertex((uint)i, new Vertex3D(convVect3d(sculptMesh.coords[i]), convNormal(sculptMesh.normals[i]), color, convVect2d(sculptMesh.uvs[i])));

                ushort index = 0;
                foreach (Face face in sculptMesh.faces)
                {
                    mb.SetIndex(index++, (ushort)face.v1);
                    mb.SetIndex(index++, (ushort)face.v3);
                    mb.SetIndex(index++, (ushort)face.v2);
                }

                mesh.AddMeshBuffer(mb);

                // don't dispose here
                //mb.Dispose();
            }

            catch (AccessViolationException)
            {
                VUtil.LogConsole("[ACCESSVIOLATION]", "PrimMesherG::SCultMeshToIrrMesh");
                m_log.Error("ACCESSVIOLATION");
                mesh = null;
            }

            return mesh;
        }
예제 #8
0
        private static Mesh FacesToIrrMesh(List<ViewerFace> viewerFaces, int numPrimFaces)
        {
            Color color = new Color(255, 255, 255, 255);

            Mesh mesh;
            try
            {
                mesh = new Mesh();
            }
            catch (IndexOutOfRangeException)
            {
                return null;
            }
            int numViewerFaces = viewerFaces.Count;

            MeshBuffer[] mb = new MeshBuffer[numPrimFaces];

            for (int i = 0; i < mb.Length; i++)
                mb[i] = new MeshBuffer(VertexType.Standard);

            try
            {
                uint[] index = new uint[mb.Length];

                for (int i = 0; i < index.Length; i++)
                    index[i] = 0;

                for (uint i = 0; i < numViewerFaces; i++)
                {
                    ViewerFace vf = viewerFaces[(int)i];

                    try
                    {
                        mb[vf.primFaceNumber].SetVertex(index[vf.primFaceNumber], new Vertex3D(convVect3d(vf.v1), convNormal(vf.n1), color, convVect2d(vf.uv1)));
                        mb[vf.primFaceNumber].SetVertex(index[vf.primFaceNumber] + 1, new Vertex3D(convVect3d(vf.v2), convNormal(vf.n2), color, convVect2d(vf.uv2)));
                        mb[vf.primFaceNumber].SetVertex(index[vf.primFaceNumber] + 2, new Vertex3D(convVect3d(vf.v3), convNormal(vf.n3), color, convVect2d(vf.uv3)));

                    }
                    catch (OutOfMemoryException)
                    {
                        return null;
                    }
                    catch (IndexOutOfRangeException)
                    {
                        return null;
                    }

                    mb[vf.primFaceNumber].SetIndex(index[vf.primFaceNumber], (ushort)index[vf.primFaceNumber]);
                    mb[vf.primFaceNumber].SetIndex(index[vf.primFaceNumber] + 1, (ushort)(index[vf.primFaceNumber] + 2));
                    mb[vf.primFaceNumber].SetIndex(index[vf.primFaceNumber] + 2, (ushort)(index[vf.primFaceNumber] + 1));

                    index[vf.primFaceNumber] += 3;
                }

                for (int i = 0; i < mb.Length; i++)
                {
                    mesh.AddMeshBuffer(mb[i]);
                }

                Box3D box = new Box3D(0, 0, 0, 0, 0, 0);
                for (int i = 0; i < mesh.MeshBufferCount; i++)
                {
                    mesh.GetMeshBuffer(i).RecalculateBoundingBox();
                    box.AddInternalBox(mesh.GetMeshBuffer(i).BoundingBox);
                }
                mesh.BoundingBox = box;
                // don't dispose here
                //mb.Dispose();
            }
            catch (AccessViolationException)
            {
                VUtil.LogConsole("[ACCESSVIOLATION]", "PrimMesherG::FacesToIrrMesh");
                mesh = null;
            }

            return mesh;
        }