예제 #1
0
        /// <summary>
        /// Tomar los valores configurados y crear el SkyBox
        /// </summary>
        public void updateValues()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear cada cara
            for (int i = 0; i < faces.Length; i++)
            {
                //Crear mesh de D3D
                Mesh     m       = new Mesh(2, 4, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.DiffuseMapVertexElements, d3dDevice);
                SkyFaces skyFace = (SkyFaces)i;

                // Cargo los vértices
                using (VertexBuffer vb = m.VertexBuffer)
                {
                    GraphicsStream data     = vb.Lock(0, 0, LockFlags.None);
                    int            colorRgb = this.color.ToArgb();
                    cargarVertices(skyFace, data, colorRgb);
                    vb.Unlock();
                }

                // Cargo los índices
                using (IndexBuffer ib = m.IndexBuffer)
                {
                    short[] ibArray = new short[6];
                    cargarIndices(ibArray);
                    ib.SetData(ibArray, 0, LockFlags.None);
                }

                //Crear TgcMesh
                string  faceName = Enum.GetName(typeof(SkyFaces), skyFace);
                TgcMesh faceMesh = new TgcMesh(m, "SkyBox-" + faceName, TgcMesh.MeshRenderType.DIFFUSE_MAP);
                faceMesh.Materials = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
                faceMesh.createBoundingBox();
                faceMesh.Enabled = true;

                //textura
                TgcTexture texture = TgcTexture.createTexture(d3dDevice, faceTextures[i]);
                faceMesh.DiffuseMaps = new TgcTexture[] { texture };

                faces[i] = faceMesh;
            }
        }
        /// <summary>
        ///     Tomar los valores configurados y crear el SkyBox. Solo invocar en tiempo de INIT!!!
        /// </summary>
        public void Init()
        {
            //Crear cada cara
            for (var i = 0; i < Faces.Length; i++)
            {
                //Crear mesh de D3D
                var m = new Mesh(2, 4, MeshFlags.Managed, TgcSceneLoader.DiffuseMapVertexElements,
                                 D3DDevice.Instance.Device);
                var skyFace = (SkyFaces)i;

                // Cargo los vértices
                using (var vb = m.VertexBuffer)
                {
                    var data     = vb.Lock(0, 0, LockFlags.None);
                    var colorRgb = Color.ToArgb();
                    cargarVertices(skyFace, data, colorRgb);
                    vb.Unlock();
                }

                // Cargo los índices
                using (var ib = m.IndexBuffer)
                {
                    var ibArray = new short[6];
                    cargarIndices(ibArray);
                    ib.SetData(ibArray, 0, LockFlags.None);
                }

                //Crear TgcMesh
                var faceName = Enum.GetName(typeof(SkyFaces), skyFace);
                var faceMesh = new TgcMesh(m, "SkyBox-" + faceName, TgcMesh.MeshRenderType.DIFFUSE_MAP);
                faceMesh.Materials = new[] { D3DDevice.DEFAULT_MATERIAL };
                faceMesh.createBoundingBox();
                faceMesh.Enabled             = true;
                faceMesh.AutoTransformEnable = false;

                //textura
                var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, FaceTextures[i]);
                faceMesh.DiffuseMaps = new[] { texture };

                Faces[i] = faceMesh;
            }
        }
        public virtual void creaDisparo(Vector3 posicion)
        {
            string  sonido = env.MediaDir + "MySounds\\MachineGun.wav";
            var     loader = new TgcSceneLoader();
            var     scene  = loader.loadSceneFromFile(env.MediaDir + "MeshCreator\\Meshes\\Objetos\\Bala\\Bala-TgcScene.xml");
            TgcMesh mesh   = scene.Meshes[0];
            Vector3 scale  = new Vector3(0.3f, 0.3f, 0.3f);

            mesh.Scale = scale;
            mesh.AutoUpdateBoundingBox = true;
            mesh.createBoundingBox();
            mesh.Position = posicion;


            Arma arma = new Arma(mesh, this.env, sonido, 40, this.orientacion, this.anguloFinal, scale, this.getMesh(), true);

            //arma.mover();
            ControladorDeVehiculos.getInstance().agregarArma(arma);
            base.agregarArma(arma);
        }
        private void creaUnItem(string fileMesh, Vector3 posicion, float rotacion)
        {
            var     sceneCura = loader.loadSceneFromFile(fileMesh);
            TgcMesh meshCura  = sceneCura.Meshes[0];

            meshCura.AutoTransformEnable   = true;
            meshCura.AutoUpdateBoundingBox = true;
            meshCura.createBoundingBox();
            meshCura.Position = posicion;
            meshCura.rotateX(rotacion);
            meshCura.Scale = new Vector3(0.5f, 0.5f, 0.5f);
            meshCura.move(0, 20, 0);
            //cura.BoundingBox.transform(Matrix.Scaling(new Vector3(0.1f, 3, 0.1f)) * Matrix.Translation(new Vector3(posteDeLuz.Position.X + 33, posteDeLuz.Position.Y, posteDeLuz.Position.Z)));

            /*Item cura = new Item(this.env.MediaDir, this.env.ShadersDir);
             * cura.setMesh(meshCura);
             * cura.setFileNameSound(MediaDir + "MySounds\\PickUp2.wav");*/

            items.Add(meshCura);
        }
예제 #5
0
        /// <summary>
        /// Convierte el box en un TgcMesh
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear</param>
        public TgcMesh toMesh(string meshName)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Obtener matriz para transformar vertices
            if (autoTransformEnable)
            {
                this.transform = Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.Translation(translation);
            }

            //Crear mesh con DiffuseMap
            if (texture != null)
            {
                //Crear Mesh
                Mesh d3dMesh = new Mesh(vertices.Length / 3, vertices.Length, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.DiffuseMapVertexElements, d3dDevice);

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

                        //vertices
                        v.Position = Vector3.TransformCoordinate(vBox.Position, this.transform);

                        //normals
                        v.Normal = Vector3.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 (IndexBuffer ib = d3dMesh.IndexBuffer)
                {
                    short[] indices = new short[vertices.Length];
                    for (int j = 0; j < indices.Length; j++)
                    {
                        indices[j] = (short)j;
                    }
                    ib.SetData(indices, 0, LockFlags.None);
                }

                //Calcular normales
                d3dMesh.ComputeNormals();

                //Malla de TGC
                TgcMesh tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.DIFFUSE_MAP);
                tgcMesh.DiffuseMaps = new TgcTexture[] { texture.clone() };
                tgcMesh.Materials   = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
                tgcMesh.createBoundingBox();
                tgcMesh.Enabled          = true;
                tgcMesh.AlphaBlendEnable = this.alphaBlendEnable;
                return(tgcMesh);
            }

            //Crear mesh con solo color
            else
            {
                //Crear Mesh
                Mesh d3dMesh = new Mesh(vertices.Length / 3, vertices.Length, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.VertexColorVertexElements, d3dDevice);

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

                        //vertices
                        v.Position = Vector3.TransformCoordinate(vBox.Position, this.transform);

                        //normals
                        v.Normal = Vector3.Empty;

                        //color
                        v.Color = vBox.Color;

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

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


                //Malla de TGC
                TgcMesh tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.VERTEX_COLOR);
                tgcMesh.Materials = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
                tgcMesh.createBoundingBox();
                tgcMesh.Enabled = true;
                return(tgcMesh);
            }
        }
예제 #6
0
        /// <summary>
        ///     Convierte el TgcSphere en un TgcMesh
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear</param>
        public TgcMesh toMesh(string meshName)
        {
            //Obtener matriz para transformar vertices
            if (AutoTransformEnable)
            {
                Transform = Matrix.Scaling(radius, radius, radius) * Matrix.Scaling(Scale) *
                            Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) *
                            Matrix.Translation(translation);
            }

            //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 = Vector3.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 = Vector3.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;
                return(tgcMesh);
            }
        }
예제 #7
0
        /// <summary>
        ///     Adaptar mesh de DirectX a mesh de TGC
        /// </summary>
        public TgcMesh CreateTgcMesh(BspMap bspMap, Mesh mesh, int surfaceId)
        {
            var surface = bspMap.Data.drawSurfaces[surfaceId];

            var lightmap = surface.lightmapNum >= 0 ? lightMaps[surface.lightmapNum] : null;

            var texture = textures[surface.shaderNum];

            //asigno el shader si es que tiene
            bspMap.Data.shaderXSurface[surfaceId] = shaderXTextura[surface.shaderNum];
            if (bspMap.Data.shaderXSurface[surfaceId] != null)
            {
                bspMap.Data.shaderXSurface[surfaceId].BuildFx();
            }

            if (texture == null && bspMap.Data.shaderXSurface[surfaceId] != null)
            {
                foreach (var stage in bspMap.Data.shaderXSurface[surfaceId].Stages)
                {
                    if (stage.Textures.Count > 0)
                    {
                        texture = stage.Textures[0];
                        break;
                    }
                }
            }

            //Cargar lightMap
            var tgcLightMap = lightmap;

            if (lightmap == null)
            {
                tgcLightMap = emptyLightMap;
            }

            var meshTextures = new TgcTexture[1];

            if (texture != null)
            {
                meshTextures[0] = texture;
            }
            else
            {
                meshTextures[0] = emptyTexture;
            }

            var renderType = TgcMesh.MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP;

            var mat = new Material();

            mat.Ambient = Color.White;

            //Crear mesh de TGC
            var tgcMesh = new TgcMesh(mesh, "mesh" + surfaceId, renderType);

            tgcMesh.Materials   = new[] { mat };
            tgcMesh.DiffuseMaps = meshTextures;
            tgcMesh.LightMap    = tgcLightMap;
            tgcMesh.Enabled     = true;
            tgcMesh.createBoundingBox();

            return(tgcMesh);
        }
예제 #8
0
        /// <summary>
        /// Convierte el Triángulo en un TgcMesh
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear</param>
        public TgcMesh toMesh(string meshName)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear Mesh con solo color
            Mesh d3dMesh = new Mesh(1, 3, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.VertexColorVertexElements, d3dDevice);

            //Calcular normal: left-handed
            Vector3 normal = computeNormal();
            int     ci     = color.ToArgb();

            //Cargar VertexBuffer
            using (VertexBuffer vb = d3dMesh.VertexBuffer)
            {
                GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                TgcSceneLoader.TgcSceneLoader.VertexColorVertex v;

                //a
                v          = new TgcSceneLoader.TgcSceneLoader.VertexColorVertex();
                v.Position = a;
                v.Normal   = normal;
                v.Color    = ci;
                data.Write(v);

                //b
                v          = new TgcSceneLoader.TgcSceneLoader.VertexColorVertex();
                v.Position = b;
                v.Normal   = normal;
                v.Color    = ci;
                data.Write(v);

                //c
                v          = new TgcSceneLoader.TgcSceneLoader.VertexColorVertex();
                v.Position = c;
                v.Normal   = normal;
                v.Color    = ci;
                data.Write(v);

                vb.Unlock();
            }

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


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

            tgcMesh.Materials = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
            tgcMesh.createBoundingBox();
            tgcMesh.Enabled = true;
            return(tgcMesh);
        }