private void btnOK_Click(object sender, EventArgs e)
        {
            if (lstWheels.SelectedItem != null)
            {
                wheel = new Model();

                WheelPreview wp = wheels[lstWheels.SelectedIndex];
                CNTImporter cntImporter = new CNTImporter();

                var rim = (Model)cntImporter.Import(Path.Combine(wp.Archive, wp.Path, "rim.cnt"));
                //var tyre = (Model)cntImporter.Import(wheelsFolder + lstWheels.SelectedItem + "\\tyre.cnt");

                foreach (var mesh in rim.Meshes) { wheel.SetName(mesh.Name, wheel.AddMesh(mesh, 0)); }
                //foreach (var mesh in tyre.Meshes) { wheel.SetName(mesh.Name, wheel.AddMesh(mesh, 0)); }
            }

            this.Close();
        }
Esempio n. 2
0
        public void ProcessTree(Model m, int index, bool bReset = false)
        {
            TreeNode ParentNode;

            if (bReset || tvNodes.Nodes.Count == 0) { Reset(); }

            ParentNode = tvNodes.Nodes[0].Nodes[0];

            for (int i = 0; i < m.Bones.Count; i++)
            {
                var bone = m.Bones[i];
                var key = ModelBone.GetModelBoneKey(index, i);

                while (ParentNode != null && ParentNode.Tag != null && (int)ParentNode.Tag != ModelBone.GetModelBoneKey(index, bone.Parent.Index)) { ParentNode = ParentNode.Parent; }
                ParentNode = ParentNode.Nodes[ParentNode.Nodes.Add(CreateNode(bone, key))];
            }

            tvNodes.Nodes[0].Expand();
            if (tvNodes.Nodes[0].Nodes.Count > 0) { tvNodes.Nodes[0].Nodes[0].Expand(); }
        }
Esempio n. 3
0
        public override Asset Clone()
        {
            var m = new Model();

            m.bones = new ModelBoneCollection(this.bones);
            m.meshes = this.meshes.ConvertAll(mesh => new ModelMesh(mesh));

            foreach (var kvp in this.supportingDocuments)
            {
                m.supportingDocuments[kvp.Key] = kvp.Value;
            }

            return m;
        }
 private void btnClear_Click(object sender, EventArgs e)
 {
     wheel = null;
     this.Close();
 }
Esempio n. 5
0
        public static void PreProcess(Model model, PreProcessOptions options)
        {
            if (options.HasFlag(PreProcessOptions.SplitMeshPart))
            {
                // Specific to C:R, I'll abstract this out as and when necessary
                foreach (ModelMesh mesh in model.Meshes)
                {
                    int partCount = mesh.MeshParts.Count;

                    for (int i = partCount - 1; i >= 0; i--)
                    {
                        ModelMeshPart part = mesh.MeshParts[i];

                        if (part.VertexBuffer.Data.Count > 16383)
                        {
                            while (part.IndexBuffer.Data.Count > 0)
                            {
                                var buffer = part.IndexBuffer.Data;
                                HashSet<int> usedVerts = new HashSet<int>();
                                int total = buffer.Count;

                                for (int j = 0; j < buffer.Count; j += 3)
                                {
                                    usedVerts.Add(buffer[j + 0]);
                                    usedVerts.Add(buffer[j + 1]);
                                    usedVerts.Add(buffer[j + 2]);

                                    int chunkSize = Math.Min(buffer.Count, 16383);

                                    if (j + 3 == buffer.Count || usedVerts.Count >= chunkSize)
                                    {
                                        if (usedVerts.Count == chunkSize) { j += 3; }

                                        Dictionary<int, int> indexLUT = new Dictionary<int, int>();

                                        var newPart = new ModelMeshPart();
                                        newPart.Material = part.Material;

                                        for (int k = 0; k < j; k++)
                                        {
                                            if (!indexLUT.ContainsKey(buffer[k]))
                                            {
                                                indexLUT.Add(buffer[k], newPart.VertexBuffer.AddVertex(part.VertexBuffer.Data[buffer[k]]));
                                            }

                                            newPart.IndexBuffer.AddIndex(indexLUT[buffer[k]]);
                                        }

                                        buffer.RemoveRange(0, j);

                                        mesh.AddModelMeshPart(newPart);

                                        SceneManager.Current.UpdateProgress(string.Format("Allocated {0:n0} of {1:n0}", j * chunkSize, total));
                                        break;
                                    }
                                }
                            }

                            mesh.MeshParts.RemoveAt(i);
                        }
                    }
                }
            }

            if (options.HasFlag(PreProcessOptions.Dedupe))
            {
                foreach (ModelMesh mesh in model.Meshes)
                {
                    foreach (ModelMeshPart part in mesh.MeshParts)
                    {
                        part.Optimise();
                    }
                }
            }

            if (options.HasFlag(PreProcessOptions.ResolveNonManifold))
            {
                foreach (ModelMesh mesh in model.Meshes)
                {
                    foreach (ModelMeshPart part in mesh.MeshParts)
                    {
                        Dictionary<int, int> edgeCounts = new Dictionary<int, int>();
                        List<int> buffer = part.IndexBuffer.Data;
                        bool bFixedNonManifoldMesh = false;

                        for (int i = 0; i < buffer.Count; i += 3)
                        {
                            int[] edges = new int[3];

                            for (int j = 0; j < 3; j++)
                            {
                                int oppositeIndex = (j + 1 < 3 ? j + 1 : 0);

                                edges[j] = Math.Max(buffer[i + j], buffer[i + oppositeIndex]) << 24 + Math.Min(buffer[i + j], buffer[i + oppositeIndex]);

                                if (edgeCounts.ContainsKey(edges[j]))
                                {
                                    if (edgeCounts[edges[j]] == 2)
                                    {
                                        buffer[i + j] = part.VertexBuffer.AddVertex(part.VertexBuffer.Data[buffer[i + j]].Clone());
                                        buffer[i + oppositeIndex] = part.VertexBuffer.AddVertex(part.VertexBuffer.Data[buffer[i + oppositeIndex]].Clone());

                                        j--;

                                        bFixedNonManifoldMesh = true;
                                    }
                                    else
                                    {
                                        edgeCounts[edges[j]]++;
                                    }
                                }
                                else
                                {
                                    edgeCounts.Add(edges[j], 1);
                                }
                            }
                        }

                        if (bFixedNonManifoldMesh)
                        {
                            part.IndexBuffer.Initialise();
                            part.VertexBuffer.Initialise();
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        public static void Freeze(Model model, Matrix4 matrix)
        {
            foreach (ModelMesh mesh in model.Meshes)
            {
                Matrix4 o = mesh.Parent.Transform;
                Vector3 p = Vector3.Transform(o.ExtractTranslation(), matrix);
                Vector3 e = o.ExtractRotation().ToEuler(RotationOrder.OrderXYZ);

                o = Matrix4.CreateFromQuaternion(
                    Quaternion.FromAxisAngle(OpenTK.Vector3.UnitX, MathHelper.DegreesToRadians( e.X)) *
                    Quaternion.FromAxisAngle(OpenTK.Vector3.UnitZ, MathHelper.DegreesToRadians(-e.Y)) *
                    Quaternion.FromAxisAngle(OpenTK.Vector3.UnitY, MathHelper.DegreesToRadians(-e.Z))
                );

                o.M41 = p.X;
                o.M42 = p.Y;
                o.M43 = p.Z;

                mesh.Parent.Transform = matrix;

                ModelManipulator.Freeze(mesh, FreezeComponents.Rotation);

                mesh.Parent.Transform = o;
            }
        }
Esempio n. 7
0
        public void Draw()
        {
            if (Linked)
            {
                var parentTransform = ((ModelBone)link).CombinedTransform;

                if (linkType == LinkType.All)
                {
                    transform = parentTransform;
                }
                else
                {
                    transform = Matrix4.Identity;

                    var v = parentTransform.ExtractTranslation();
                    parentTransform.Normalize();
                    parentTransform.M41 = v.X;
                    parentTransform.M42 = v.Y;
                    parentTransform.M43 = v.Z;

                    if ((linkType & LinkType.Rotation) == LinkType.Rotation) { transform *= Matrix4.CreateFromQuaternion(parentTransform.ExtractRotation()); }
                    if ((linkType & LinkType.Scale)    == LinkType.Scale)    { transform *= Matrix4.CreateScale(parentTransform.ExtractScale()); }
                    if ((linkType & LinkType.Position) == LinkType.Position) { transform *= Matrix4.CreateTranslation(parentTransform.ExtractTranslation()); }
                }
            }

            var mS = SceneManager.Current.Transform;
            var mT = transform;

            switch (assetType)
            {
                case AssetType.Model:
                    var model = asset as Model;
                    if (model != null)
                    {
                        GL.PushMatrix();

                        GL.MultMatrix(ref mS);
                        GL.MultMatrix(ref mT);

                        model.Draw();

                        GL.PopMatrix();
                    }
                    break;

                case AssetType.Sprite:
                    if (asset == null)
                    {
                        var sprite = new ModelMeshPart();
                        sprite.AddVertex(new Vector3(-0.25f, -0.25f, 0.0f), Vector3.UnitY, new Vector2(0, 1));
                        sprite.AddVertex(new Vector3(-0.25f,  0.25f, 0.0f), Vector3.UnitY, new Vector2(0, 0));
                        sprite.AddVertex(new Vector3( 0.25f,  0.25f, 0.0f), Vector3.UnitY, new Vector2(1, 0));
                        sprite.AddVertex(new Vector3( 0.25f, -0.25f, 0.0f), Vector3.UnitY, new Vector2(1, 1));

                        sprite.AddVertex(new Vector3( 0.25f, -0.25f, 0.0f), Vector3.UnitY, new Vector2(0, 1));
                        sprite.AddVertex(new Vector3( 0.25f,  0.25f, 0.0f), Vector3.UnitY, new Vector2(0, 0));
                        sprite.AddVertex(new Vector3(-0.25f,  0.25f, 0.0f), Vector3.UnitY, new Vector2(1, 0));
                        sprite.AddVertex(new Vector3(-0.25f, -0.25f, 0.0f), Vector3.UnitY, new Vector2(1, 1));
                        sprite.IndexBuffer.Initialise();
                        sprite.VertexBuffer.Initialise();
                        sprite.Material = new Material { Name = "Entity.Asset", Texture = SceneManager.Current.Content.Load<Texture, PNGImporter>("entity_" + entityType.ToString().ToLower(), Path.GetDirectoryName(Application.ExecutablePath) + @"\data\icons\") };
                        sprite.PrimitiveType = PrimitiveType.Quads;
                        var spritemesh = new ModelMesh();
                        spritemesh.AddModelMeshPart(sprite);
                        var spritemodel = new Model();
                        spritemodel.AddMesh(spritemesh);
                        asset = spritemodel;
                    }

                    GL.PushMatrix();

                    var position = Matrix4.CreateTranslation(mT.ExtractTranslation());

                    GL.MultMatrix(ref mS);
                    GL.MultMatrix(ref position);

                    GL.Enable(EnableCap.Blend);
                    GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                    ((Model)asset).Draw();
                    GL.Disable(EnableCap.Blend);

                    GL.PopMatrix();
                    break;
            }
        }