상속: 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
        // 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;
        }
예제 #4
0
파일: Prim.cs 프로젝트: yooyke/work
        private Mesh UpdateMesh(MeshData[] meshes, Mesh mesh)
        {
            if (mesh != null)
                mesh.Drop();

            return CreateMesh(meshes);
        }
예제 #5
0
		public void RemoveMesh (Mesh mesh)
		{
			MeshCache_RemoveMesh (_raw, mesh.Raw);
		}
예제 #6
0
		public string GetMeshFilename (Mesh mesh)
		{
			return MeshCache_GetMeshFilename (_raw, mesh.Raw);
		}
예제 #7
0
 /// <summary>
 /// Creates an optimized collision detector based on OctTrees
 /// </summary>
 /// <returns>A TriangleSelector</returns>
 /// <param name="mesh">Mesh from your node</param>
 /// <param name="node">Node</param>
 /// <param name="minimalPolysPerNode">Specifies the minimal polygons contained a octree node. If a node gets less polys the this value, it will not be splitted into smaller nodes.</param>
 public TriangleSelector CreateOctTreeTriangleSelector(Mesh mesh, SceneNode node, int minimalPolysPerNode)
 {
     return (TriangleSelector)
         NativeElement.GetObject(SceneManager_CreateOctTreeTriangleSelector(_raw, mesh.Raw, node.Raw, minimalPolysPerNode),
                                 typeof(TriangleSelector));
 }
예제 #8
0
 /// <summary>
 /// Adds an oct tree scene node
 /// </summary>
 /// <returns>The oct tree</returns>
 /// <param name="mesh">The mesh it is based on</param>
 /// <param name="parent">Its parent</param>
 /// <param name="id">ID (-1 for automatic assign.)</param>
 /// <param name="minimalPolysPerNode">The minimal polys per node (ideal : 128)</param>
 public SceneNode AddOctTreeSceneNode(Mesh mesh, SceneNode parent, int id, int minimalPolysPerNode)
 {
     IntPtr par = IntPtr.Zero;
     if(parent != null)
         par = parent.Raw;
     return (SceneNode)
         NativeElement.GetObject(SceneManager_AddOctTreeSceneNode(_raw, mesh.Raw, par, id, minimalPolysPerNode),
                                 typeof(SceneNode));
 }
예제 #9
0
 /// <summary>
 /// Unweld vertices.
 /// </summary>
 /// <param name="baseMesh">Input mesh</param>
 /// <returns>Result mesh</returns>
 public Mesh CreateMeshUniquePrimitives(Mesh baseMesh)
 {
     return (Mesh)
         NativeElement.GetObject(MeshManipulator_CreateMeshUniquePrimitives(_raw, baseMesh.Raw),
                                 typeof(Mesh));
 }
예제 #10
0
 /// <summary>
 /// Applies a transformation. 
 /// </summary>
 /// <param name="mesh">
 /// A mesh to be transformed <see cref="Mesh"/>
 /// </param>
 /// <param name="mat">
 /// A transform matrix <see cref="Matrix4"/>
 /// </param>
 public void TransformMesh(Mesh mesh, Matrix4 mat)
 {
     MeshManipulator_TransformMesh(_raw, mesh.Raw, mat.ToUnmanaged());
 }
예제 #11
0
 /// <summary>
 /// Sets the colors of all vertices to one color. 
 /// </summary>
 /// <param name="mesh">Mesh on which the operation is performed. </param>
 /// <param name="color">New color.</param>
 public void SetVertexColors(Mesh mesh, Color color)
 {
     MeshManipulator_SetVertexColors(_raw, mesh.Raw, color.ToUnmanaged());
 }
예제 #12
0
 /// <summary>
 /// Sets the alpha vertex color value of the whole mesh to a new value.  
 /// </summary>
 /// <param name="mesh">Mesh on which the operation is performed. </param>
 /// <param name="alpha">New alpha value. Must be a value between 0 and 255. </param>
 public void SetVertexColorAlpha(Mesh mesh, int alpha)
 {
     MeshManipulator_SetVertexColorAlpha(_raw, mesh.Raw, alpha);
 }
예제 #13
0
 /// <summary>
 /// Scales the whole mesh. 
 /// </summary>
 /// <param name="mesh">Mesh on which the operation is performed. </param>
 /// <param name="scale">Scale factor. </param>
 public void ScaleMesh(Mesh mesh, Vector3D scale)
 {
     MeshManipulator_ScaleMesh(_raw, mesh.Raw, scale.ToUnmanaged());
 }
예제 #14
0
 /// <summary>
 /// Recalculates all normals of the mesh. 
 /// </summary>
 /// <param name="mesh">Mesh on which the operation is performed.</param>
 /// <param name="smooth"></param>
 public void RecalculateNormals(Mesh mesh, bool smooth)
 {
     MeshManipulator_RecalculateNormals(_raw, mesh.Raw, smooth);
 }
예제 #15
0
        public bool GetMeshInstance(Primitive prim, out Mesh objMesh)
        {
            Primitive.ConstructionData primData = prim.PrimData;
            int sides = 4;
            int hollowsides = 4;

            float profileBegin = primData.ProfileBegin;
            float profileEnd = primData.ProfileEnd;

            if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.Circle)
                sides = 24;
            else if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.EqualTriangle)
                sides = 3;
            else if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.HalfCircle)
            { // half circle, prim is a sphere
                sides = 24;
                profileBegin = 0.5f * profileBegin + 0.5f;
                profileEnd = 0.5f * profileEnd + 0.5f;
            }

            if ((HoleType)primData.ProfileHole == HoleType.Same)
                hollowsides = sides;
            else if ((HoleType)primData.ProfileHole == HoleType.Circle)
                hollowsides = 24;
            else if ((HoleType)primData.ProfileHole == HoleType.Triangle)
                hollowsides = 3;
            objMesh = null;

            string storedmeshcode = (sides.ToString() + profileBegin.ToString() + profileEnd.ToString() + ((float)primData.ProfileHollow).ToString() + hollowsides.ToString() + primData.PathScaleX.ToString() + primData.PathScaleY.ToString() + primData.PathBegin.ToString() +
                primData.PathEnd.ToString() + primData.PathShearX.ToString() + primData.PathShearY.ToString() +
                primData.PathRadiusOffset.ToString() + primData.PathRevolutions.ToString() + primData.PathSkew.ToString() +
                ((int)primData.PathCurve).ToString() + primData.PathScaleX.ToString() + primData.PathScaleY.ToString() +
                primData.PathTwistBegin.ToString() + primData.PathTwist.ToString());

            bool identicalcandidate = true;
            if (prim.Textures != null)
            {
                foreach (Primitive.TextureEntryFace face in prim.Textures.FaceTextures)
                {
                    if (face != null)
                        identicalcandidate = false;
                }
            }

            StringBuilder sbIdenticalMesh = new StringBuilder();
            sbIdenticalMesh.Append(storedmeshcode);

            // this test is short circuit dependent - don't change the order
            if (prim.Textures != null && prim.Textures.DefaultTexture != null)
                {
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.TextureID);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.Bump);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.Fullbright);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.Glow);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.MediaFlags);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.OffsetU);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.OffsetV);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.RepeatU);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.RepeatV);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.RGBA.ToRGBString());
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.Rotation);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.Shiny);
                    sbIdenticalMesh.Append(prim.Textures.DefaultTexture.TexMapType.ToString());
                }

            string identicalmeshcode = sbIdenticalMesh.ToString();

            if (identicalcandidate)
            {
                lock (IdenticalMesh)
                {
                    if (IdenticalMesh.ContainsKey(identicalmeshcode))
                        objMesh = IdenticalMesh[identicalmeshcode];

                }
                if (objMesh == null)
                {
                    objMesh = PrimMesherG.PrimitiveToIrrMesh(prim, LevelOfDetail.High);
                }
                lock (IdenticalMesh)
                {
                    if (!IdenticalMesh.ContainsKey(identicalmeshcode))
                        IdenticalMesh.Add(identicalmeshcode, objMesh);
                }

                lock (StoredMesh)
                {
                    if (!StoredMesh.ContainsKey(storedmeshcode))
                        StoredMesh.Add(storedmeshcode, objMesh);
                }
                return false;
            }

            lock (StoredMesh)
            {
                if (StoredMesh.ContainsKey(storedmeshcode))
                {
                    objMesh = StoredMesh[storedmeshcode];
                }
            }

            if (objMesh == null)
            {
                objMesh = PrimMesherG.PrimitiveToIrrMesh(prim, LevelOfDetail.High);
                lock (StoredMesh)
                {
                    if (!StoredMesh.ContainsKey(storedmeshcode))
                    {
                        StoredMesh.Add(storedmeshcode, objMesh);
                    }
                }
            }

            // outside lock.
            if (objMesh != null)
            {
                objMesh = mm.CreateMeshCopy(objMesh);
                return true;
            }

            return false;
        }
예제 #16
0
 /// <summary>
 /// Adds a basic and not-moving scene node based on a simple mesh
 /// </summary>
 /// <returns>Your scene node</returns>
 /// <param name="mesh">A static mesh often obtained via GetMesh(0)</param>
 /// <param name="parent">Parent of the node</param>
 /// <param name="id">ID of the node (-1 for automatic assignation)</param>
 public MeshSceneNode AddMeshSceneNode(Mesh mesh, SceneNode parent, int id)
 {
     IntPtr par = IntPtr.Zero;
     if(parent != null)
         par = parent.Raw;
     return (MeshSceneNode)
         NativeElement.GetObject(SceneManager_AddMeshSceneNode(_raw, mesh.Raw, par, id),
                                 typeof(MeshSceneNode));
 }
예제 #17
0
 /// <summary>
 /// Creates a copy of the mesh, which will only consist of S3DVertexTangents vertices. 
 /// This is useful if you want to draw tangent space normal mapped geometry because it calculates the tangent and binormal data which is needed there. 
 /// </summary>
 /// <param name="baseMesh">Input mesh</param>
 /// <returns>Mesh consiting only of S3DVertexTangents vertices.</returns>
 public Mesh CreateMeshWithTangents(Mesh baseMesh)
 {
     return (Mesh)
         NativeElement.GetObject(MeshManipulator_CreateMeshWithTangents(_raw, baseMesh.Raw),
                                 typeof(Mesh));
 }
예제 #18
0
 /// <summary>
 /// Adds a water surface based on a hill mesh (use AddHillPlaneMesh). Looks good when material is TransparentReflection
 /// </summary>
 /// <returns>The water to surf on</returns>
 /// <param name="hillMesh">Hill mesh the water is based on</param>
 /// <param name="waveH">Height of waves</param>
 /// <param name="waveS">Speed of waves</param>
 /// <param name="waveL">Length of waves</param>
 /// <param name="parent">Parent of the node</param>
 /// <param name="id">ID (-1 for automatic assign.)</param>
 public SceneNode AddWaterSurfaceSceneNode(Mesh hillMesh, float waveH, float waveS, float waveL, SceneNode parent,int id)
 {
     IntPtr par = IntPtr.Zero;
     if(parent != null)
         par = parent.Raw;
     return (SceneNode)
         NativeElement.GetObject(SceneManager_AddWaterSurfaceSceneNode(_raw, hillMesh.Raw, waveH, waveS, waveL, par, id),
                                 typeof(SceneNode));
 }
예제 #19
0
 /// <summary>
 /// Flips the direction of surfaces.
 /// Changes backfacing triangles to frontfacing triangles and vice versa
 /// </summary>
 /// <param name="m">Mesh on which the operation is performed. </param>
 public void FlipSurfaces(Mesh m)
 {
     MeshManipulator_FlipSurfaces(_raw, m.Raw);
 }
예제 #20
0
 /// <summary>
 /// Creates a basic triangle selector based on a mesh
 /// </summary>
 /// <returns>A TriangleSelector</returns>
 /// <param name="mesh">The MESH !</param>
 /// <param name="node">Scene node, you NEED TO ADD THIS SELECTOR WITH SceneNode.TriangleSelector !</param>
 public TriangleSelector CreateTriangleSelector(Mesh mesh, SceneNode node)
 {
     return (TriangleSelector)
         NativeElement.GetObject(SceneManager_CreateTriangleSelector(_raw, mesh.Raw, node.Raw),
                                 typeof(TriangleSelector));
 }
예제 #21
0
 /// <summary>
 /// Returns amount of polygons in mesh. 
 /// </summary>
 /// <param name="mesh">Mesh</param>
 /// <returns>Amount of polygons</returns>
 public int GetPolyCount(Mesh mesh)
 {
     return MeshManipulator_GetPolyCount(_raw, mesh.Raw);
 }
예제 #22
0
		public int GetMeshIndex (Mesh mesh)
		{
			return MeshCache_GetMeshIndex (_raw, mesh.Raw);
		}
예제 #23
0
 /// <summary>
 /// Creates a planar texture mapping on the mesh.  
 /// </summary>
 /// <param name="baseMesh">Mesh on which the operation is performed. </param>
 /// <param name="resolution">Resolution of the planar mapping. This is the value specifying which is the relation between world space and texture coordinate space. </param>
 public void MakePlanarTextureMapping(Mesh baseMesh, float resolution)
 {
     MeshManipulator_MakePlanarTextureMapping(_raw, baseMesh.Raw, resolution);
 }
예제 #24
0
		public bool SetMeshFilename (Mesh mesh, string filename)
		{
			return MeshCache_SetMeshFilename (_raw, mesh.Raw, filename);
		}
예제 #25
0
        public void ModifyMeshBuffer(Color4 coldata, float shinyval, int j, Mesh mesh, Primitive.TextureEntryFace teface, bool alpha)
        {
            MeshBuffer mb = mesh.GetMeshBuffer(j);

            // If it's an alpha texture, ensure Irrlicht knows or you get artifacts.
            if (alpha)
            {
                mb.Material.MaterialType = MaterialType.TransparentAlphaChannel;
            }

            // Create texture transform based on the UV transforms specified in the texture entry
            IrrlichtNETCP.Matrix4 mat = mb.Material.Layer1.TextureMatrix;

            mat = IrrlichtNETCP.Matrix4.buildTextureTransform(teface.Rotation, new Vector2D(-0.5f, -0.5f * teface.RepeatV), new Vector2D(0.5f + teface.OffsetU, -(0.5f + teface.OffsetV)), new Vector2D(teface.RepeatU, teface.RepeatV));
            mb.Material.Layer1.TextureMatrix = mat;

            mb.Material.ZWriteEnable = true;
            mb.Material.BackfaceCulling = (this.texDownloadStyle == TextureDownloadStyle.TEX_DOWNLOAD_ASSETSERVER);

            if (coldata.A != 1)
            {
                coldata.R *= coldata.A;
                coldata.B *= coldata.A;
                coldata.G *= coldata.A;
            }

            if (coldata.R != 1 || coldata.G != 1 || coldata.B != 1)
                mb.SetColor(new Color(
                    Util.Clamp<int>((int)(coldata.A * 255), 0, 255),
                    Util.Clamp<int>((int)(coldata.R * 255), 0, 255),
                    Util.Clamp<int>((int)(coldata.G * 255), 0, 255),
                    Util.Clamp<int>((int)(coldata.B * 255), 0, 255)
                    ));

            // If it's partially translucent inform Irrlicht
            if (coldata.A != 1)
            {
                mb.Material.MaterialType = MaterialType.TransparentVertexAlpha;
                mb.Material.Lighting = false;
            }
            else
            {
                mb.Material.Lighting = false;
                //mb.Material.Lighting = !teface.Fullbright;

                if (shinyval > 0)
                {
                    if (newMaterialType1 != -1)
                    {
                        mb.Material.MaterialType = (MaterialType)newMaterialType1;
                        mb.Material.Lighting = false;
                    }
                }
            }
        }
예제 #26
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;
        }
예제 #27
0
 public void SetMesh(Mesh pMesh)
 {
     MeshSceneNode_SetMesh(_raw, pMesh.Raw);
 }
		/// <summary>
		/// Sets the mesh the shadow volume uses to be rendered
		/// </summary>
		/// <param name="mesh">The mesh</param>
		public void SetMeshToRenderFrom(Mesh mesh)
		{
			ShadowVolume_SetMeshToRenderFrom(_raw, mesh.Raw);
		}
예제 #29
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;
        }