Ejemplo n.º 1
0
        internal void ResolveMaterials()
        {
            Action <CActor> resolver = null;

            resolver = (actor) =>
            {
                if (actor.MaterialName != null)
                {
                    actor.Material = ResourceCache.GetMaterial(actor.MaterialName);
                }
                foreach (CActor child in actor.Children)
                {
                    resolver(child);
                }
            };
            resolver(Root);
        }
Ejemplo n.º 2
0
        public Vehicle(string filename, IDriver driver)
        {
            Driver         = driver;
            Driver.Vehicle = this;

            Config = new VehicleFile(filename);

            if (driver is PlayerDriver)
            {
                if (Config.WindscreenMaterial != "none")
                {
                    Config.Funks.Add(new WindscreenFunk(Config.WindscreenMaterial, this));
                }
            }

            _model = new VehicleModel(Config, false);

            Audio = new VehicleAudio(this);

            Chassis = new VehicleChassis(this);

            CActor actor2 = _model.GetActor(Path.GetFileNameWithoutExtension(_model.ModelName));

            if (actor2 != null)
            {
                _deformableModel          = (CDeformableModel)actor2.Model;
                _deformableModel._actor   = Chassis.Actor;
                _deformableModel._carFile = Config;
            }

            _crushSection = Config.CrushSections[1];

            CMaterial crashMat = ResourceCache.GetMaterial(Config.CrashMaterialFiles[0]);

            _vehicleBitsEmitter = new ParticleEmitter(new VehicleBitsParticleSystem(crashMat), 3, Vector3.Zero);
            _vehicleBitsEmitter.DumpsPerSecond = 0.7f;

            DamageSmokeEmitter         = new ParticleEmitter(new DamageSmokeParticleSystem(Color.Gray), 5, Vector3.Zero);
            DamageSmokeEmitter.Enabled = false;

            _flames        = new PixmapBillboard(new Vector2(0.7f, 0.25f), "flames.pix");
            SkidMarkBuffer = new SkidMarkBuffer(this, 150);
        }
Ejemplo n.º 3
0
        public override void Resolve(List <ushort> indices, List <VertexPositionNormalTexture> vertices, List <Vector2> vertexTextureMap, List <Vector3> vertexPositions)
        {
            List <UInt16> indices2 = new List <UInt16>();

            foreach (Polygon poly in Polygons)
            {
                poly.NbrPrims = 1;
                indices2.Add(poly.Vertex1); indices2.Add(poly.Vertex2); indices2.Add(poly.Vertex3);
            }

            _originalPositions = new Vector3[VertexCount];
            _repairPoisitons   = new Vector3[VertexCount];
            vertexPositions.CopyTo(VertexBaseIndex, _originalPositions, 0, VertexCount);

            Polygon currentPoly = null;

            foreach (Polygon poly in Polygons)
            {
                poly.NbrPrims = 1;
                if (poly.MaterialIndex >= 0 && MaterialNames != null)
                {
                    CMaterial material = ResourceCache.GetMaterial(MaterialNames[poly.MaterialIndex]);

                    if (material != null)
                    {
                        poly.DoubleSided = material.DoubleSided;
                        poly.Material    = material;
                    }

                    if (currentPoly != null && poly.MaterialIndex == currentPoly.MaterialIndex)
                    {
                        poly.Skip            = true;
                        currentPoly.NbrPrims = currentPoly.NbrPrims + 1;
                    }
                    else
                    {
                        currentPoly = poly;
                    }
                }
            }

            _localVertices = new VertexPositionNormalTexture[VertexCount];
            for (int i = 0; i < VertexCount; i++)
            {
                Vector3 normal = Polygons[i / 3].Normal;
                if (TextureMapCount > 0)
                {
                    _localVertices[i] = new VertexPositionNormalTexture(vertexPositions[i + VertexBaseIndex], normal, vertexTextureMap[i + VertexBaseIndex]);
                }
                else
                {
                    _localVertices[i] = new VertexPositionNormalTexture(vertexPositions[i + VertexBaseIndex], normal, Vector2.Zero);
                }

                _originalPositions[i] = _localVertices[i].Position;
            }

            // link up vertices which share the same position so when we crush we avoid gaps
            _vertexLinks = new List <int> [_originalPositions.Length];
            for (int i = 0; i < _originalPositions.Length; i++)
            {
                for (int j = 0; j < _originalPositions.Length; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    if (_originalPositions[i] == _originalPositions[j])
                    {
                        if (_vertexLinks[i] == null)
                        {
                            _vertexLinks[i] = new List <int>();
                        }
                        _vertexLinks[i].Add(j);
                    }
                }
            }

            for (int i = 0; i < _localVertices.Length; i++)
            {
                _localVertices[i].Normal = Vector3.Zero;
            }

            for (int i = 0; i < indices2.Count / 3; i++)
            {
                Vector3 firstvec  = _localVertices[indices2[i * 3 + 1]].Position - _localVertices[indices2[i * 3]].Position;
                Vector3 secondvec = _localVertices[indices2[i * 3]].Position - _localVertices[indices2[i * 3 + 2]].Position;
                Vector3 normal    = Vector3.Cross(firstvec, secondvec);
                normal.Normalize();
                _localVertices[indices2[i * 3]].Normal     += normal;
                _localVertices[indices2[i * 3 + 1]].Normal += normal;
                _localVertices[indices2[i * 3 + 2]].Normal += normal;
            }
            for (int i = 0; i < _localVertices.Length; i++)
            {
                _localVertices[i].Normal.Normalize();
            }

            int size = VertexPositionNormalTexture.SizeInBytes * _localVertices.Length;

            _vertexBuffer = new VertexBuffer(Engine.Device, size, BufferUsage.WriteOnly);
            _vertexBuffer.SetData(_localVertices);

            _indexBuffer = new IndexBuffer(Engine.Device, typeof(UInt16), indices2.Count, BufferUsage.WriteOnly);
            _indexBuffer.SetData(indices2.ToArray());
        }
Ejemplo n.º 4
0
Archivo: CModel.cs Proyecto: q4a/OpenC1
        public virtual void Resolve(List <UInt16> indices, List <VertexPositionNormalTexture> vertices, List <Vector2> vertexTextureMap, List <Vector3> vertexPositions)
        {
            bool    injectHardEdges = true;
            Polygon currentPoly     = null;

            foreach (Polygon poly in Polygons)
            {
                poly.NbrPrims = 1;
                indices.Add(poly.Vertex1); indices.Add(poly.Vertex2); indices.Add(poly.Vertex3);

                if (injectHardEdges)
                {
                    Vector2 uv = Vector2.Zero;
                    if (TextureMapCount > 0 && poly.Vertex1 + VertexBaseIndex < vertexTextureMap.Count)
                    {
                        uv = vertexTextureMap[poly.Vertex1 + VertexBaseIndex];
                    }
                    vertices.Add(new VertexPositionNormalTexture(vertexPositions[poly.Vertex1 + VertexBaseIndex], poly.Normal, uv));
                    if (TextureMapCount > 0 && poly.Vertex2 + VertexBaseIndex < vertexTextureMap.Count)
                    {
                        uv = vertexTextureMap[poly.Vertex2 + VertexBaseIndex];
                    }
                    vertices.Add(new VertexPositionNormalTexture(vertexPositions[poly.Vertex2 + VertexBaseIndex], poly.Normal, uv));
                    if (TextureMapCount > 0 && poly.Vertex3 + VertexBaseIndex < vertexTextureMap.Count)
                    {
                        uv = vertexTextureMap[poly.Vertex3 + VertexBaseIndex];
                    }
                    vertices.Add(new VertexPositionNormalTexture(vertexPositions[poly.Vertex3 + VertexBaseIndex], poly.Normal, uv));
                }

                if (MaterialNames != null)
                {
                    CMaterial material;
                    if (poly.MaterialIndex < 0)
                    {
                        material = ResourceCache.GetMaterial("drkcurb.mat");
                    }
                    else
                    {
                        material = ResourceCache.GetMaterial(MaterialNames[poly.MaterialIndex]);
                    }

                    if (material != null)
                    {
                        poly.DoubleSided = material.DoubleSided;
                        poly.Material    = material;
                    }

                    if (currentPoly != null && poly.MaterialIndex == currentPoly.MaterialIndex)
                    {
                        poly.Skip            = true;
                        currentPoly.NbrPrims = currentPoly.NbrPrims + 1;
                    }
                    else
                    {
                        currentPoly = poly;
                    }
                }
            }
            if (!injectHardEdges)
            {
                //for (int i = 0; i < VertexCount; i++)
                //{
                //    Vector3 normal = Polygons[i / 3].Normal;
                //    if (TextureMapCount > 0)
                //        vertices.Add(new VertexPositionNormalTexture(vertexPositions[i + VertexBaseIndex], normal, vertexTextureMap[i + VertexBaseIndex]));
                //    else
                //        vertices.Add(new VertexPositionNormalTexture(vertexPositions[i + VertexBaseIndex], normal, Vector2.Zero));
                //}

                //for (int i = 0; i < indices.Count / 3; i++)
                //{
                //    Vector3 firstvec = vertices[indices[i * 3 + 1]].Position - vertices[indices[i * 3]].Position;
                //    Vector3 secondvec = vertices[indices[i * 3]].Position - vertices[indices[i * 3 + 2]].Position;
                //    Vector3 normal = Vector3.Cross(firstvec, secondvec);
                //    normal.Normalize();
                //    VertexPositionNormalTexture vpnt = vertices[indices[i * 3]];
                //    vpnt.Normal += normal;
                //    vpnt = vertices[indices[i * 3 + 1]];
                //    vpnt.Normal += normal;
                //    vpnt = vertices[indices[i * 3 + 2]];
                //    vpnt.Normal += normal;
                //}
                //for (int i = 0; i < vertices.Count; i++)
                //    vertices[i].Normal.Normalize();
            }
        }