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); }
/// <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); }
/// <summary> /// Crear un nuevo mesh igual /// </summary> /// <param name="cloneName">Nombre del mesh clonado</param> /// <returns>Mesh clonado</returns> public TgcMesh clone(string cloneName) { //Clonar D3dMesh var d3dCloneMesh = d3dMesh.Clone(MeshFlags.Managed, d3dMesh.Declaration, D3DDevice.Instance.Device); //Crear mesh de TGC y cargar atributos generales var cloneMesh = new TgcMesh(d3dCloneMesh, cloneName, renderType); cloneMesh.Materials = Materials; cloneMesh.layer = layer; cloneMesh.boundingBox = boundingBox.clone(); cloneMesh.AlphaBlendEnable = AlphaBlendEnable; cloneMesh.enabled = true; cloneMesh.AutoUpdateBoundingBox = AutoUpdateBoundingBox; //Transformaciones cloneMesh.translation = translation; cloneMesh.rotation = rotation; cloneMesh.scale = scale; cloneMesh.transform = transform; cloneMesh.AutoTransformEnable = AutoTransformEnable; //Clonar userProperties if (UserProperties != null) { cloneMesh.UserProperties = new Dictionary <string, string>(); foreach (var entry in UserProperties) { cloneMesh.UserProperties.Add(entry.Key, entry.Value); } } //Clonar DiffuseMaps if (diffuseMaps != null) { cloneMesh.diffuseMaps = new TgcTexture[diffuseMaps.Length]; for (var i = 0; i < diffuseMaps.Length; i++) { cloneMesh.diffuseMaps[i] = diffuseMaps[i].Clone(); } } //Clonar LightMap if (lightMap != null) { cloneMesh.lightMap = lightMap.Clone(); } return(cloneMesh); }
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); } }