Exemple #1
0
        public static TgcMesh FromTGCPlane(string meshName, CustomVertex.PositionTextured[] vertices, TgcTexture texture, TGCVector3?Normal)
        {
            //Crear Mesh
            var d3dMesh = new Mesh(vertices.Length / 3, vertices.Length, MeshFlags.Managed, TgcSceneLoader.DiffuseMapVertexElements, D3DDevice.Instance.Device);

            //Cargar VertexBuffer
            using (var vb = d3dMesh.VertexBuffer)
            {
                var data       = vb.Lock(0, 0, LockFlags.None);
                var ceroNormal = TGCVector3.Empty;
                var whiteColor = Color.White.ToArgb();
                for (var j = 0; j < vertices.Length; j++)
                {
                    var v      = new TgcSceneLoader.DiffuseMapVertex();
                    var vPlane = vertices[j];

                    //vertices
                    v.Position = TGCVector3.FromVector3(vPlane.Position);

                    //normals
                    v.Normal = (Normal ?? TGCVector3.Empty);

                    //texture coordinates diffuseMap
                    v.Tu = vPlane.Tu;
                    v.Tv = vPlane.Tv;

                    //color
                    v.Color = whiteColor;

                    data.Write(v);
                }
                vb.Unlock();
            }

            //Cargar IndexBuffer en forma plana
            using (var ib = d3dMesh.IndexBuffer)
            {
                var indices = new short[vertices.Length];
                for (var j = 0; j < indices.Length; j++)
                {
                    indices[j] = (short)j;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }

            //Calcular normales
            if (Normal == null)
            {
                d3dMesh.ComputeNormals();
            }

            //Malla de TGC
            var tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.DIFFUSE_MAP);

            tgcMesh.DiffuseMaps = new[] { texture.Clone() };
            tgcMesh.Materials   = new[] { D3DDevice.DEFAULT_MATERIAL };
            tgcMesh.createBoundingBox();
            tgcMesh.Enabled = true;
            return(tgcMesh);
        }
Exemple #2
0
        /// <summary>
        /// Crea un TGCMesh con DiffuseMap.
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear.</param>
        /// <param name="vertices">Vertices a utilizar para crear la malla.</param>
        /// <param name="transform">Matriz que se utiliza para aplicar transformaciones a la malla.</param>
        /// <param name="texture">Textura a utilizar.</param>
        /// <param name="alphaBlendEnable">Habilita el AlphaBlending para los modelos.</param>
        /// <returns>Un nuevo TGCMesh basado en los parametros dados.</returns>
        public static TgcMesh ToDiffuseMapMesh(string meshName, CustomVertex.PositionColoredTextured[] vertices, TGCMatrix transform, TgcTexture texture, bool alphaBlendEnable)
        {
            //Crear Mesh
            var d3dMesh = new Mesh(vertices.Length / 3, vertices.Length, MeshFlags.Managed,
                                   TgcSceneLoader.DiffuseMapVertexElements, D3DDevice.Instance.Device);

            //Cargar VertexBuffer
            using (var vb = d3dMesh.VertexBuffer)
            {
                var data = vb.Lock(0, 0, LockFlags.None);
                for (var j = 0; j < vertices.Length; j++)
                {
                    var v    = new TgcSceneLoader.DiffuseMapVertex();
                    var vBox = vertices[j];

                    //vertices
                    v.Position = TGCVector3.TransformCoordinate(TGCVector3.FromVector3(vBox.Position), transform);

                    //normals
                    v.Normal = TGCVector3.Empty;

                    //texture coordinates diffuseMap
                    v.Tu = vBox.Tu;
                    v.Tv = vBox.Tv;

                    //color
                    v.Color = vBox.Color;

                    data.Write(v);
                }
                vb.Unlock();
            }

            //Cargar IndexBuffer en forma plana
            using (var ib = d3dMesh.IndexBuffer)
            {
                var indices = new short[vertices.Length];
                for (var j = 0; j < indices.Length; j++)
                {
                    indices[j] = (short)j;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }

            //Calcular normales
            d3dMesh.ComputeNormals();

            //Malla de TGC
            var tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.DIFFUSE_MAP);

            tgcMesh.DiffuseMaps = new[] { texture.Clone() };
            tgcMesh.Materials   = new[] { D3DDevice.DEFAULT_MATERIAL };
            tgcMesh.createBoundingBox();
            tgcMesh.Enabled          = true;
            tgcMesh.AlphaBlendEnable = alphaBlendEnable;
            return(tgcMesh);
        }
Exemple #3
0
        public static TgcMesh FromTGCSphere(string meshName, TgcTexture texture, List <int> indices, List <TGCSphere.Vertex.PositionColoredTexturedNormal> vertices, TGCMatrix transform, bool alphaBlendEnable)
        {
            //Crear mesh con DiffuseMap
            if (texture != null)
            {
                //Crear Mesh
                var d3dMesh = new Mesh(indices.Count / 3, indices.Count, MeshFlags.Managed,
                                       TgcSceneLoader.DiffuseMapVertexElements, D3DDevice.Instance.Device);

                //Cargar VertexBuffer
                using (var vb = d3dMesh.VertexBuffer)
                {
                    var data = vb.Lock(0, 0, LockFlags.None);
                    for (var j = 0; j < indices.Count; j++)
                    {
                        var v       = new TgcSceneLoader.DiffuseMapVertex();
                        var vSphere = vertices[indices[j]];

                        //vertices
                        v.Position = TGCVector3.TransformCoordinate(vSphere.getPosition(), transform);

                        //normals
                        v.Normal = vSphere.getNormal();

                        //texture coordinates diffuseMap
                        v.Tu = vSphere.Tu;
                        v.Tv = vSphere.Tv;

                        //color
                        v.Color = vSphere.Color;

                        data.Write(v);
                    }
                    vb.Unlock();
                }

                //Cargar IndexBuffer en forma plana
                using (var ib = d3dMesh.IndexBuffer)
                {
                    var vIndices = new short[indices.Count];
                    for (var j = 0; j < vIndices.Length; j++)
                    {
                        vIndices[j] = (short)j;
                    }
                    ib.SetData(vIndices, 0, LockFlags.None);
                }

                //Calcular normales
                //d3dMesh.ComputeNormals();

                //Malla de TGC
                var tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.DIFFUSE_MAP);
                tgcMesh.DiffuseMaps = new[] { texture.Clone() };
                tgcMesh.Materials   = new[] { D3DDevice.DEFAULT_MATERIAL };
                tgcMesh.createBoundingBox();
                tgcMesh.Enabled = true;
                return(tgcMesh);
            }

            //Crear mesh con solo color
            else
            {
                //Crear Mesh
                var d3dMesh = new Mesh(indices.Count / 3, indices.Count, MeshFlags.Managed,
                                       TgcSceneLoader.VertexColorVertexElements, D3DDevice.Instance.Device);

                //Cargar VertexBuffer
                using (var vb = d3dMesh.VertexBuffer)
                {
                    var data = vb.Lock(0, 0, LockFlags.None);
                    for (var j = 0; j < indices.Count; j++)
                    {
                        var v       = new TgcSceneLoader.VertexColorVertex();
                        var vSphere = vertices[indices[j]];

                        //vertices
                        v.Position = TGCVector3.TransformCoordinate(vSphere.getPosition(), transform);

                        //normals
                        v.Normal = vSphere.getNormal();

                        //color
                        v.Color = vSphere.Color;

                        data.Write(v);
                    }
                    vb.Unlock();
                }

                //Cargar IndexBuffer en forma plana
                using (var ib = d3dMesh.IndexBuffer)
                {
                    var vIndices = new short[indices.Count];
                    for (var j = 0; j < vIndices.Length; j++)
                    {
                        vIndices[j] = (short)j;
                    }
                    ib.SetData(vIndices, 0, LockFlags.None);
                }

                //Malla de TGC
                var tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.VERTEX_COLOR);
                tgcMesh.Materials = new[] { D3DDevice.DEFAULT_MATERIAL };
                tgcMesh.createBoundingBox();
                tgcMesh.Enabled          = true;
                tgcMesh.AlphaBlendEnable = alphaBlendEnable;
                return(tgcMesh);
            }
        }