public override void Render(ID3D11Device device, ID3D11DeviceContext deviceContext, Camera camera)
        {
            if (!DoRender)
            {
                return;
            }

            //if (!camera.CheckBBoxFrustum(Transform.TranslationVector, BoundingBox))
            //     return;

            VertexBufferView VertexBufferView = new VertexBufferView(vertexBuffer, Unsafe.SizeOf <VertexLayouts.NormalLayout.Vertex>(), 0);

            deviceContext.IASetVertexBuffers(0, VertexBufferView);
            deviceContext.IASetIndexBuffer(indexBuffer, Vortice.DXGI.Format.R32_UInt, 0);
            deviceContext.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
            deviceContext.PSSetShaderResource(2, AOTexture);

            for (int i = 0; i != LODs[0].ModelParts.Length; i++)
            {
                ModelPart Segment = LODs[0].ModelParts[i];
                Segment.Shader.SetShaderParameters(device, deviceContext, new MaterialParameters(Segment.Material, SelectionColour.Normalize()));
                Segment.Shader.SetSceneVariables(deviceContext, Transform, camera);
                Segment.Shader.Render(deviceContext, PrimitiveTopology.TriangleList, (int)(Segment.NumFaces * 3), Segment.StartIndex);
            }
        }
Exemple #2
0
        public static ModelPart CreatePlane(string name, int materialId)
        {
            var model = new ModelPart
            {
                Faces      = new ModelPartFace[1],
                Name       = name,
                MaterialId = materialId
            };

            model.Faces[0] = ModelPartFace.CreateSquare(model, 0);

            model.Faces[0].VertexIndices = new[] { 0, 1, 2, 3 };
            model.Faces[0].Triangles[0]  = new ModelTriangle(0, 1, 2, model.Faces[0], 0, 1, 2);
            model.Faces[0].Triangles[1]  = new ModelTriangle(0, 2, 3, model.Faces[0], 0, 2, 3);

            model.Vertices = new[]
            {
                new Vector3(-0.5f, 0, 0.5f),
                new Vector3(-0.5f, 0, -0.5f),
                new Vector3(0.5f, 0, -0.5f),
                new Vector3(0.5f, 0, 0.5f),
            };

            return(model);
        }
Exemple #3
0
        public ModelPartFace Clone(ModelPart parent)
        {
            var clone = new ModelPartFace(Index, parent)
            {
                Colour = Colour,
                TextureCoordinates = new Vector2[TextureCoordinates.Length]
            };

            for (var i = 0; i < TextureCoordinates.Length; i++)
            {
                clone.TextureCoordinates[i] = TextureCoordinates[i];
            }

            clone.Triangles = new ModelTriangle[Triangles.Length];
            for (var i = 0; i < Triangles.Length; i++)
            {
                clone.Triangles[i] = Triangles[i].Clone(clone);
            }

            clone.VertexIndices = new int[VertexIndices.Length];
            for (var i = 0; i < VertexIndices.Length; i++)
            {
                clone.VertexIndices[i] = VertexIndices[i];
            }

            return clone;
        }
Exemple #4
0
        private Source GetOutputSource(string id, ModelPart part, int count)
        {
            var source = new Source
            {
                Id = $"{id}-transform-output"
            };

            source.Float_Array = new Float_Array
            {
                Count = (ulong)count * 16,
                Value = GetOutputValue(part)
            };

            var accessor = new Accessor
            {
                Count  = (ulong)count,
                Source = $"#{source.Id}-array",
                Stride = 16
            };

            accessor.Param.Add(new Param
            {
                Name = "TRANSFORM",
                Type = "float4x4"
            });

            source.Technique_Common = new SourceTechnique_Common
            {
                Accessor = accessor
            };

            return(source);
        }
Exemple #5
0
        public void SetUp()
        {
            _materialCache = new MaterialCache();
            _parentMtl     = _materialCache.Add("testmtl1");
            _childMtl      = _materialCache.Add("testmtl2");

            _epicModel = new EpicModel();

            _parentCuboid            = Cuboid.CreateCuboid();
            _parentCuboid.Size       = new Vector3(2, 2, 2);
            _parentCuboid.Rotation   = new Vector3(0, 0, -(float)Math.PI / 4.0f);
            _parentCuboid.MaterialId = _parentMtl.Id;

            _connector          = _parentCuboid.AddAnchor("Connector");
            _connector.Position = new Vector3(1, 1, 0);

            _childCuboid            = Cuboid.CreateCuboid();
            _childCuboid.Position   = new Vector3(-1, -1, 0);
            _childCuboid.Rotation   = new Vector3(0, 0, -(float)Math.PI / 2.0f);
            _childCuboid.MaterialId = _childMtl.Id;


            _epicModel.ModelParts.Add(_parentCuboid);
            _childCuboid.Pivot.SetParent(_connector);

            _compiler      = new EpicModelCompiler(_epicModel);
            _compiledModel = _compiler.Compile();

            _modelInstance = new ModelInstance(_compiledModel, _materialCache);

            _modelInstance.Update(1 / 24.0f);
        }
Exemple #6
0
        public virtual void SetUp()
        {
            Model = new EpicModel();

            Cuboid = EpicEdit.Model.Factories.Cuboid.CreateCuboid();
            Cuboid.Pivot.Position = new Vector3(-0.5f, 0, 0);
            Cuboid.Position       = new Vector3(1, 1, 0);
            Cuboid.Size           = new Vector3(1, 1, 1);

            Anchor          = Cuboid.AddAnchor("Test_Anchor");
            Anchor.Position = new Vector3(0.5f, 0, 0);
            Anchor.Rotation = new Vector3();

            Model.ModelParts.Add(Cuboid);

            Animation = Model.GetAnimation(AnimationType.Walking, true);

            var frame1 = Animation.AddFrame();

            frame1.Time = 0.0f;

            var frame2 = Animation.AddFrame();

            frame2.Time = 2.0f;

            var anchorAnimState = frame2.AnchorAnimStates.Single(x => x.Anchor == Anchor);

            anchorAnimState.Rotation = new Vector3(0, 0, (float)Math.PI / 2.0f);

            var cuboidAnimState = frame2.ModelPartAnimStates.Single(x => x.ModelPart == Cuboid);

            cuboidAnimState.Position = new Vector3(0, 0, 0);
            cuboidAnimState.Rotation = new Vector3(0, 0, (float)Math.PI / 2.0f);
        }
Exemple #7
0
        public static ModelPart CreateCuboid()
        {
            var model = new ModelPart();

            model.Faces = new ModelPartFace[6];
            for (var i = 0; i < 6; i++)
            {
                model.Faces[i] = ModelPartFace.CreateSquare(model, i);
            }

            const int front = (int)CuboidFaceIndices.Front;

            model.Faces[front].VertexIndices = new[] { 0, 1, 2, 3 };
            model.Faces[front].Triangles[0]  = new ModelTriangle(0, 1, 2, model.Faces[front], 0, 1, 2);
            model.Faces[front].Triangles[1]  = new ModelTriangle(0, 2, 3, model.Faces[front], 0, 2, 3);

            const int back = (int)CuboidFaceIndices.Back;

            model.Faces[back].VertexIndices = new[] { 7, 6, 5, 4 };
            model.Faces[back].Triangles[0]  = new ModelTriangle(7, 6, 5, model.Faces[back], 0, 1, 2);
            model.Faces[back].Triangles[1]  = new ModelTriangle(7, 5, 4, model.Faces[back], 0, 2, 3);

            const int left = (int)CuboidFaceIndices.Left;

            model.Faces[left].VertexIndices = new[] { 4, 5, 1, 0 };
            model.Faces[left].Triangles[0]  = new ModelTriangle(4, 5, 1, model.Faces[left], 0, 1, 2);
            model.Faces[left].Triangles[1]  = new ModelTriangle(4, 1, 0, model.Faces[left], 0, 2, 3);

            const int right = (int)CuboidFaceIndices.Right;

            model.Faces[right].VertexIndices = new[] { 3, 2, 6, 7 };
            model.Faces[right].Triangles[0]  = new ModelTriangle(3, 2, 6, model.Faces[right], 0, 1, 2);
            model.Faces[right].Triangles[1]  = new ModelTriangle(3, 6, 7, model.Faces[right], 0, 2, 3);

            const int top = (int)CuboidFaceIndices.Top;

            model.Faces[top].VertexIndices = new[] { 1, 5, 6, 2 };
            model.Faces[top].Triangles[0]  = new ModelTriangle(1, 5, 6, model.Faces[top], 0, 1, 2);
            model.Faces[top].Triangles[1]  = new ModelTriangle(1, 6, 2, model.Faces[top], 0, 2, 3);

            const int bottom = (int)CuboidFaceIndices.Bottom;

            model.Faces[bottom].VertexIndices = new[] { 4, 0, 3, 7 };
            model.Faces[bottom].Triangles[0]  = new ModelTriangle(4, 0, 3, model.Faces[bottom], 0, 1, 2);
            model.Faces[bottom].Triangles[1]  = new ModelTriangle(4, 3, 7, model.Faces[bottom], 0, 2, 3);

            model.Vertices = new[]
            {
                new Vector3(-0.5f, -0.5f, 0.5f),  // 0
                new Vector3(-0.5f, -0.5f, -0.5f), // 1
                new Vector3(0.5f, -0.5f, -0.5f),  // 2
                new Vector3(0.5f, -0.5f, 0.5f),   // 3
                new Vector3(-0.5f, 0.5f, 0.5f),   // 4
                new Vector3(-0.5f, 0.5f, -0.5f),  // 5
                new Vector3(0.5f, 0.5f, -0.5f),   // 6
                new Vector3(0.5f, 0.5f, 0.5f),    // 7
            };

            return(model);
        }
Exemple #8
0
        private string GetOutputValue(ModelPart part)
        {
            var transforms = part.Animations.RotationFrames.Select(f => f.TransformationMatrix).ToArray();

            if (!transforms.Any())
            {
                transforms = Enumerable.Repeat(Matrix4x4.Identity, part.Animations.MovementFrames.Count).ToArray();
            }

            for (var i = 0; i < transforms.Count(); i++)
            {
                if (part.Animations.MovementFrames.Count == transforms.Length)
                {
                    transforms[i].M14 = part.Animations.MovementFrames[i].X;
                    transforms[i].M24 = part.Animations.MovementFrames[i].Y;
                    transforms[i].M34 = part.Animations.MovementFrames[i].Z;
                }
                else if (part.Animations.MovementFrames.Count == 0)
                {
                    transforms[i].M14 = part.Offset.X;
                    transforms[i].M24 = part.Offset.Y;
                    transforms[i].M34 = part.Offset.Z;
                }
            }

            return(string.Join(" ", transforms.Select(t => MatrixToString(t))));
        }
Exemple #9
0
        public void ConvertMTKToRenderModel(M2TStructure structure)
        {
            List <Vertex[]> vertices = new List <Vertex[]>();

            LODs = new LOD[structure.Lods.Length];
            for (int i = 0; i != structure.Lods.Length; i++)
            {
                M2TStructure.Lod lod = structure.Lods[i];
                vertices.Add(lod.Vertices);
                LOD lod2 = new LOD();
                lod2.Indices    = lod.Indices;
                lod2.ModelParts = new ModelPart[lod.Parts.Length];
                for (int y = 0; y != lod.Parts.Length; y++)
                {
                    ModelPart part = new ModelPart();
                    part.NumFaces     = lod.Parts[y].NumFaces;
                    part.StartIndex   = lod.Parts[y].StartIndex;
                    part.MaterialHash = lod.Parts[y].Hash;


                    switch (part.MaterialHash)
                    {
                    case 1337:
                        part.Material = RenderStorageSingleton.Instance.Prefabs.GizmoRed;
                        break;

                    case 1338:
                        part.Material = RenderStorageSingleton.Instance.Prefabs.GizmoBlue;
                        break;

                    case 1339:
                        part.Material = RenderStorageSingleton.Instance.Prefabs.GizmoGreen;
                        break;

                    default:
                        part.Material = MaterialsManager.LookupMaterialByHash(part.MaterialHash);
                        break;
                    }
                    lod2.ModelParts[y] = part;
                }

                lod2.Vertices = new VertexLayouts.NormalLayout.Vertex[lod.Vertices.Length];
                for (int y = 0; y != lod.Vertices.Length; y++)
                {
                    var vertice = new VertexLayouts.NormalLayout.Vertex();
                    vertice.Position  = lod.Vertices[y].Position;
                    vertice.Normal    = lod.Vertices[y].Normal;
                    vertice.TexCoord0 = lod.Vertices[y].UVs[0];
                    vertice.TexCoord7 = lod.Vertices[y].UVs[3];
                    lod2.Vertices[y]  = vertice;
                }
                LODs[i] = lod2;
            }
            BoundingBox = new RenderBoundingBox();
            BoundingBox.Init(BoundingBoxExtenders.CalculateBounds(vertices));
            BoundingBox.SetTransform(Transform);
            BoundingBox.DoRender = false;
            SetupShaders();
        }
Exemple #10
0
        public Anchor(ModelPart modelPart, Vector3 position, string name)
        {
            Id = _nextId++;

            Name = name;
            ModelPart = modelPart;
            Position = position;
            Children = new List<ModelPart>();
        }
Exemple #11
0
 public RenderArgs(ModelPart modelPart)
 {
     MaterialId = modelPart.MaterialId;
     RenderArgsFaces = new RenderArgsFace[modelPart.Faces.Length];
     for (var i = 0; i < modelPart.Faces.Length; i++)
     {
         RenderArgsFaces[i] = new RenderArgsFace(modelPart.Faces[i].Colour);
     }
 }
    public ModelBase CreateModel(ModelPart parts)
    {
        Object     obj       = Resources.Load("Equipment/Hero/aa001/md_c_aa001");
        GameObject model     = Object.Instantiate(obj) as GameObject;
        ModelBase  modelBase = model.GetComponent <ModelBase>();

        modelBase.GenerateByModelPart(parts);
        return(modelBase);
    }
Exemple #13
0
        public void SelectModelPart(ModelPart modelPart)
        {
            ModelPart       = modelPart;
            _widget.Visible = ModelPartSelected;

            if (ModelPartSelected)
            {
                RefreshUI();
            }
        }
Exemple #14
0
        public static ModelPart GenerateTube(float Length, float Radius, int Sections, bool StartCap, bool EndCap)
        {
            ModelPart result = new ModelPart();

            int ringSize = 6;

            float Delta = Length / (float)Sections;
            Vector3 Offset = new Vector3(Radius, 0, 0);

            ModelVertex[] vertices = new ModelVertex[ringSize*(Sections-1)];
            for (int j = 0; j < Sections + 1; j++)
            {

                for (int i = 0; i < ringSize; i++)
                {
                    ModelVertex v = new ModelVertex();
                    v.Position = Vector3.Transform(
                                    Vector3.Transform(
                                            Offset,
                                            Matrix.CreateRotationY(MathHelper.TwoPi * ((float)i / (float)(ringSize)))
                                    ),
                                    Matrix.CreateTranslation(new Vector3(0, Delta * j, 0))
                                 );
                    v.BoneWeightData.X = (float)j / (float)Sections;
                    vertices[i * ringSize + i] = v;
                }
            }

            int[] indices = new int[(ringSize * 2) * Sections * 3];
            int[] quad = { 0, ringSize, ringSize + 1, 1 };
            for(int i=0;i<Sections;i++)
            {
                for (int j=0;j<ringSize-1;j++)
                {
                    int di = i * ringSize*6 + j*6;
                    indices[di++] = quad[0] + (i * ringSize)+j;
                    indices[di++] = quad[1] + (i * ringSize)+j;
                    indices[di++] = quad[2] + (i * ringSize)+j;
                    indices[di++] = quad[2] + (i * ringSize)+j;
                    indices[di++] = quad[3] + (i * ringSize)+j;
                    indices[di++] = quad[0] + (i * ringSize)+j;
                }
                int index = i * ringSize * 6 + (ringSize-1) * 6;
                indices[index++] = i * ringSize + ringSize - 1;
                indices[index++] = ringSize + i * ringSize + ringSize - 1;
                indices[index++] = ringSize + 1 + i * ringSize + ringSize - 1 - ringSize;
                indices[index++] = ringSize + 1 + i * ringSize + ringSize - 1 - ringSize;
                indices[index++] = i * ringSize + ringSize - 1-ringSize+1;
                indices[index++] = i * ringSize + ringSize - 1;
            }
            result.SetVertices(vertices);
            return result;
        }        
        /// <summary>
        /// Sends a forum subscription message to a customer
        /// </summary>
        /// <param name="topicPageIndex">Friendly forum topic page to use for URL generation (1-based)</param>
        public static CreateMessageResult SendNewForumPostMessage(this IMessageFactory factory, Customer customer, ForumPost forumPost, int topicPageIndex, int languageId = 0)
        {
            Guard.NotNull(customer, nameof(customer));
            Guard.NotNull(forumPost, nameof(forumPost));

            var bag = new ModelPart
            {
                ["TopicPageIndex"] = topicPageIndex
            };

            return(factory.CreateMessage(MessageContext.Create(MessageTemplateNames.NewForumPost, languageId, customer: customer), true, bag, forumPost, forumPost.ForumTopic, forumPost.ForumTopic.Forum));
        }
Exemple #16
0
 public ModelRenderer(ModelBase model, string boxNameIn, ModelPart part = ModelPart.None)
 {
     this.textureWidth  = 64.0F;
     this.textureHeight = 32.0F;
     this.showModel     = true;
     this.cubeList      = new List <ModelBox>();
     this.baseModel     = model;
     model.boxList.Add(this);
     this.boxName = boxNameIn;
     this.setTextureSize(model.textureWidth, model.textureHeight);
     this.part = part;
 }
Exemple #17
0
        private static bool LoadModelPart(ModelPart part, CharaModelData modelData)
        {
            if (part == ModelPart.NumModelParts)
            {
                return(false);
            }

            modelData.ModelFiles[(int)part]   = null;
            modelData.TextureFiles[(int)part] = null;

            string partFolder = modelTypes[(int)part];

            // Get Model File
            string modelDir = Path.Combine(modelData.SubModelPath, String.Format("{0}_mdl/", partFolder));
            string modelFile;

            if (Directory.Exists(modelDir))
            {
                modelFile = Path.Combine(modelDir, "0001");
            }
            else
            {
                return(false);
            }

            // Get Textures Files
            string tex1Dir = Path.Combine(modelData.SubModelPath, String.Format("{0}_tex1/", partFolder));
            string tex2Dir = Path.Combine(modelData.SubModelPath, String.Format("{0}_tex2/", partFolder));

            string texDir = null;

            if (Directory.Exists(tex2Dir))
            {
                texDir = tex2Dir;
            }
            else if (Directory.Exists(tex1Dir))
            {
                texDir = tex1Dir;
            }

            if (texDir == null)
            {
                return(false);
            }

            var textures = Directory.GetFiles(texDir);

            modelData.TextureFiles[(int)part] = new List <string>(textures);
            modelData.ModelFiles[(int)part]   = modelFile;

            return(true);
        }
Exemple #18
0
 private void CombineModel(ModelPart part)
 {
     if (!_initModel)
     {
         return;
     }
     if (part == ModelPart.ModelWeapon)
     {
     }
     else
     {
     }
 }
Exemple #19
0
        private void WriteInfo(StreamWriter writer, ModelPart part)
        {
            var text = JsonSerializer.Serialize(new
            {
                part.Texture,
                part.Offset
            }, new JsonSerializerOptions
            {
                WriteIndented = true
            });

            writer.Write(text);
        }
Exemple #20
0
    /// <summary>
    /// 根据ModelPart结构体生成模型
    /// </summary>
    public void GenerateByModelPart(ModelPart parts)
    {
        _parts = parts;

        // 角色主体骨骼上的所有挂载点
        Transform[] jointList  = GetComponentsInChildren <Transform>();
        int[]       partIDList = _parts.GetValues();                           // 部件ID数组
        int         partCount  = partIDList.Length;                            // 部件数量

        SkinnedMeshRenderer[] meshList   = new SkinnedMeshRenderer[partCount]; // 部件Mesh
        GameObject[]          partGOList = new GameObject[partCount];          // 部件GameObject

        // 收集Mesh
        for (int i = 0; i < partCount; i++)
        {
            int partID = partIDList[i];
            if (partID == 0)
            {
                continue;
            }
            GameObject tempRes = Resources.Load <GameObject>(idToPath[partID]);
            partGOList[i] = Instantiate(tempRes);
            meshList[i]   = partGOList[i].GetComponentInChildren <SkinnedMeshRenderer>();

            // 处理装备上的粒子特效
            Dictionary <GameObject, string> particleMap = FindParticles(partGOList[i]);
            foreach (var particlePair in particleMap)
            {
                Transform particleRoot = particlePair.Key.transform;
                string    jointName    = particlePair.Value;
                foreach (var joint in jointList)
                {
                    if (joint.name == jointName)
                    {
                        particleRoot.SetParent(joint, false);
                    }
                }
            }
        }
        // 合并Mesh
        CombineSkinnedMgr.Instance.CombineObject(gameObject, meshList, true);

        // 删除老部件
        foreach (GameObject partGO in partGOList)
        {
            if (partGO != null)
            {
                DestroyImmediate(partGO);
            }
        }
    }
Exemple #21
0
        private Material GetMaterial(ModelPart part, int i, string modelName)
        {
            var id = $"{modelName}-Part-{i}";

            return(new Material
            {
                Id = $"{id}-material",
                Name = $"{id}-material",
                Instance_Effect = new Instance_Effect
                {
                    Url = $"#{id}-effect"
                }
            });
        }
 private void CombineModel(ModelPart part)
 {
     if (!IsInit)
     {
         return;
     }
     if (part == ModelPart.ModelWeapon)
     {
     }
     else
     {
         CombineModel();
     }
 }
        /// <summary>
        /// Helper function used by the CustomModelProcessor
        /// to add new ModelPart information.
        /// </summary>
        public void AddModelPart(int triangleCount, int vertexCount,
                                 VertexBufferContent vertexBufferContent,
                                 IndexCollection indexCollection,
                                 MaterialContent materialContent)
        {
            ModelPart modelPart = new ModelPart();

            modelPart.TriangleCount       = triangleCount;
            modelPart.VertexCount         = vertexCount;
            modelPart.VertexBufferContent = vertexBufferContent;
            modelPart.IndexCollection     = indexCollection;
            modelPart.MaterialContent     = materialContent;

            modelParts.Add(modelPart);
        }
Exemple #24
0
            public ModelRenderer(ModelBase modelbase, string s, ModelPart flags)
            {
                textureWidth  = 64F;
                textureHeight = 32F;
                mirror        = false;
                showModel     = true;
                isHidden      = false;
                cubeList      = new List <ModelBox>();
                baseModel     = modelbase;
                modelbase.boxList.Add(this);
                boxName = s;
                setTextureSize(modelbase.textureWidth, modelbase.textureHeight);

                Flags = flags;
            }
Exemple #25
0
        /// <summary>
        /// Build Lods from retrieved data.
        /// </summary>
        public void BuildLods(FrameGeometry frameGeometry, FrameMaterial frameMaterial, VertexBuffer[] vertexBuffers, IndexBuffer[] indexBuffers)
        {
            lods = new Lod[frameGeometry.NumLods];
            for (int i = 0; i != lods.Length; i++)
            {
                FrameLOD frameLod = frameGeometry.LOD[i];
                lods[i] = new Lod
                {
                    VertexDeclaration = frameGeometry.LOD[i].VertexDeclaration
                };
                IndexBuffer  indexBuffer  = indexBuffers[i];
                VertexBuffer vertexBuffer = vertexBuffers[i];

                int vertexSize;
                Dictionary <VertexFlags, FrameLOD.VertexOffset> vertexOffsets = frameLod.GetVertexOffsets(out vertexSize);
                lods[i].Vertices = new Vertex[frameLod.NumVerts];

                if (vertexSize * frameLod.NumVerts != vertexBuffer.Data.Length)
                {
                    throw new System.Exception();
                }
                for (int v = 0; v != lods[i].Vertices.Length; v++)
                {
                    //declare data required and send to decompresser
                    byte[] data = new byte[vertexSize];
                    Array.Copy(vertexBuffers[i].Data, (v * vertexSize), data, 0, vertexSize);
                    lods[i].Vertices[v] = VertexTranslator.DecompressVertex(data, frameGeometry.LOD[i].VertexDeclaration, frameGeometry.DecompressionOffset, frameGeometry.DecompressionFactor, vertexOffsets);
                }

                lods[i].Indices = indexBuffer.GetData();
                MaterialStruct[] materials = frameMaterial.Materials[i];
                lods[i].Parts = new ModelPart[materials.Length];
                for (int x = 0; x != materials.Length; x++)
                {
                    if (string.IsNullOrEmpty(materials[x].MaterialName))
                    {
                        var material = MaterialsManager.LookupMaterialByHash(materials[x].MaterialHash);
                        materials[x].MaterialName = material.GetMaterialName();
                    }

                    ModelPart modelPart = new ModelPart();
                    modelPart.Material   = materials[x].MaterialName;
                    modelPart.StartIndex = (uint)materials[x].StartIndex;
                    modelPart.NumFaces   = (uint)materials[x].NumFaces;
                    lods[i].Parts[x]     = modelPart;
                }
            }
        }
Exemple #26
0
            public PlaneRenderer(ModelBase modelbase, string name, int i, int j, ModelPart flags)
            {
                Name           = name;
                textureWidth   = 64.0F;
                textureHeight  = 32.0F;
                compiled       = false;
                displayList    = 0;
                mirror         = false;
                showModel      = true;
                isHidden       = false;
                textureOffsetX = i;
                textureOffsetY = j;
                modelbase.boxList.Add(this);

                Flags = flags;
            }
        /// <summary>
        /// Setup constructor
        /// </summary>
        /// <param name="layerAnimations">The set of animations that this layer can use</param>
        /// <param name="part">The body part associated with this layer</param>
        public AnimationLayer( AnimationSet layerAnimations, ModelPart part )
        {
            m_Animations = layerAnimations;

            switch ( part )
            {
                case ModelPart.Head		:	m_IdleAnim = AnimationType.NumAnimations;	break;
                case ModelPart.Upper	:	m_IdleAnim = AnimationType.TorsoStand;		break;
                case ModelPart.Lower	:	m_IdleAnim = AnimationType.LegsIdle;		break;
            };

            if ( m_IdleAnim != AnimationType.NumAnimations )
            {
                PlayAnimation( m_Animations.GetAnimation( m_IdleAnim ) );
            }
        }
Exemple #28
0
 public static ModelPartFace CreateSquare(ModelPart modelPart, int index)
 {
     return new ModelPartFace(index, modelPart)
     {
         VertexIndices = new int[4],
         TextureCoordinates = new[]
         {
             new Vector2(0, 1),
             new Vector2(0, 0),
             new Vector2(1, 0),
             new Vector2(1, 1),
         },
         Colour = new Color4(1.0f, 1.0f, 1.0f, 1.0f),
         Triangles = new ModelTriangle[2]
     };
 }
    private void LoadModelBtnCall()
    {
        if (model != null)
        {
            Debug.Log("Already Added");
            return;
        }
        // 模拟这个模型的Excel表
        string partsIDList = "1001,2001,3001,4001,5001,";

        int[]     iArray = partsIDList.SplitToInt(',');
        ModelPart parts  = new ModelPart(iArray);

        model = ModelManager.Instance.CreateModel(parts);
        model.SetLocalRotation(new Vector3(0f, 180f, 0f));
    }
Exemple #30
0
        private void DrawTranslate(float dispX, float dispY, float dispZ, ModelPart part)
        {
            VertexP3fT2fC4b vertex = default(VertexP3fT2fC4b);

            VertexP3fT2fC4b[] finVertices = game.ModelCache.vertices;

            for (int i = 0; i < part.Count; i++)
            {
                ModelVertex v = vertices[part.Offset + i];
                vertex.X   = v.X + dispX; vertex.Y = v.Y + dispY; vertex.Z = v.Z + dispZ;
                vertex.Col = cols[i >> 2];

                vertex.U             = (v.U & UVMask) * uScale - (v.U >> UVMaxShift) * 0.01f * uScale;
                vertex.V             = (v.V & UVMask) * vScale - (v.V >> UVMaxShift) * 0.01f * vScale;
                finVertices[index++] = vertex;
            }
        }
Exemple #31
0
        public void SetUp()
        {
            _model = new EpicModel();

            _parent          = Cuboid.CreateCuboid();
            _parent.Position = new Vector3(0.25f, 0.25f, -0.25f);
            _model.ModelParts.Add(_parent);
            _parent.Size = new Vector3(2, 2, 2);

            _connectingAnchor          = _parent.AddAnchor("Connecting_Anchor");
            _connectingAnchor.Position = new Vector3(1, 1, -1);

            _child = Cuboid.CreateCuboid();
            _model.ModelParts.Add(_child);
            _child.Position = new Vector3(2, 2, 0);
            _child.Pivot.SetParent(_connectingAnchor);
        }
Exemple #32
0
        private void SelectFace(ModelPart modelPart, int faceIndex)
        {
            if (FocusModelPart != null)
            {
                FocusModelPart.ClearSelect();
            }

            FocusModelPart = modelPart;

            if (modelPart != null)
            {
                modelPart.SelectFace(faceIndex);

                FaceIndex = faceIndex;
                _editorWindow.ModelPartFaceWindow.SelectModelPartFace();
                _editorWindow.ModelPartWindow.SelectModelPart(modelPart);
            }
        }
        /// <summary>
        /// Helper function used by the CustomModelProcessor
        /// to add new ModelPart information.
        /// </summary>
        public void AddModelPart( int triangleCount, int vertexCount, int vertexStride,
            VertexElement[] vertexElements,
            VertexBufferContent vertexBufferContent,
            IndexCollection indexCollection,
            MaterialContent materialContent)
        {
            ModelPart modelPart = new ModelPart();

              modelPart.TriangleCount = triangleCount;
              modelPart.VertexCount = vertexCount;
              modelPart.VertexStride = vertexStride;
              modelPart.VertexElements = vertexElements;
              modelPart.VertexBufferContent = vertexBufferContent;
              modelPart.IndexCollection = indexCollection;
              modelPart.MaterialContent = materialContent;

              modelParts.Add( modelPart );
        }
        /// <summary>
        /// Helper function used by the InstancedModelProcessor
        /// to add new ModelPart information.
        /// </summary>
        public void AddModelPart(int indexCount, int vertexCount, int vertexStride,
                                 VertexElement[] vertexElements,
                                 VertexBufferContent vertexBufferContent,
                                 IndexCollection indexCollection,
                                 MaterialContent materialContent)
        {
            ModelPart modelPart = new ModelPart();

            modelPart.IndexCount          = indexCount;
            modelPart.VertexCount         = vertexCount;
            modelPart.VertexStride        = vertexStride;
            modelPart.VertexElements      = vertexElements;
            modelPart.VertexBufferContent = vertexBufferContent;
            modelPart.IndexCollection     = indexCollection;
            modelPart.MaterialContent     = materialContent;

            modelParts.Add(modelPart);
        }
Exemple #35
0
        public virtual void Parse(XmlNode node)
        {
            foreach (XmlNode child in node.ChildNodes)
            {
                string name = child.Name.ToLower();

                if (name == "animation")
                {
                    continue;                     // skip animation
                }
                else if (name == "ismirrored")
                {
                    IsMirrored = bool.Parse(child.InnerText);
                }
                else if (name == "offset")
                {
                    Offset = Mesh.StringToVertex3(child.InnerText);
                }
                else if (name == "position")
                {
                    Position = Mesh.StringToVertex3(child.InnerText);
                }
                else if (name == "rotation")
                {
                    Rotation = Mesh.StringToVertex3(child.InnerText);
                }
                else if (name == "size")
                {
                    Size = Mesh.StringToVertex3(child.InnerText);
                }
                else if (name == "scale")
                {
                    Scale = float.Parse(child.InnerText, CultureInfo.InvariantCulture.NumberFormat);
                }
                else if (name == "textureoffset")
                {
                    TextureOffset = Mesh.StringToVertex2(child.InnerText);
                }
                else if (name == "part")
                {
                    Part = (ModelPart)Enum.Parse(typeof(ModelPart), child.InnerText);
                }
            }
        }
Exemple #36
0
 private void SetupShaders()
 {
     for (int x = 0; x != LODs[0].ModelParts.Length; x++)
     {
         ModelPart part = LODs[0].ModelParts[x];
         if (part.Material == null)
         {
             part.Shader = RenderStorageSingleton.Instance.ShaderManager.shaders[0];
         }
         else
         {
             //Debug.WriteLine(LODs[0].ModelParts[x].Material.MaterialName + "\t" + LODs[0].ModelParts[x].Material.ShaderHash);
             part.Shader = (RenderStorageSingleton.Instance.ShaderManager.shaders.ContainsKey(LODs[0].ModelParts[x].Material.ShaderHash)
                 ? RenderStorageSingleton.Instance.ShaderManager.shaders[LODs[0].ModelParts[x].Material.ShaderHash]
                 : RenderStorageSingleton.Instance.ShaderManager.shaders[0]);
         }
         LODs[0].ModelParts[x] = part;
     }
 }
Exemple #37
0
        void CheckQuickPartState(ModelPart part)
        {
            var meshes = new List<Mesh>();
            var item = _partItems[(int)part];
            var button = _partButtons[(int)part];

            foreach (var m in CurrentModel.Meshes)
                if (m.Part == part)
                    meshes.Add(m);

            if (meshes.Count == 0)
            {
                item.Enabled = button.Enabled = false;
                return;
            }

            item.Enabled = button.Enabled = true;
            item.Checked = button.Checked = true;

            foreach (var m in meshes)
            {
                if (CurrentModel.PartsEnabled[CurrentModel.Meshes.IndexOf(m)])
                    continue;

                item.Checked = button.Checked = false;
                break;
            }
        }
Exemple #38
0
 public bool Ignores(ModelPart modelPart)
 {
     return _ignoredModelParts.Contains(modelPart);
 }
        void ParseSMDTriangles(StreamReader file)
        {
            if (this.modelGroups != null)
                return;

            SortedList<string, List<VertexPNTTB>> vertexLists = new SortedList<string, List<VertexPNTTB>>();
            SortedList<string, List<ushort>> indicesList = new SortedList<string, List<ushort>>();
            while (!file.EndOfStream)
            {
                string text = file.ReadLine();
                if (text == "end")
                {
                    break;
                }

                string materialName = text.Split('.')[0];
                if (!vertexLists.ContainsKey(materialName))
                {
                    vertexLists.Add(materialName, new List<VertexPNTTB>());
                    indicesList.Add(materialName, new List<ushort>());
                }

                VertexPNTTB[] vertices = new VertexPNTTB[3];
                for (int i = 0; i < 3; i++)
                {
                    text = file.ReadLine();
                    string[] data = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    Vector4 bone = new Vector4(int.Parse(data[0]), 0, 0, 0);
                    Vector4 boneWeights = new Vector4(1.0f, 0, 0, 0);
                    Vector3 pos;
                    pos.X = float.Parse(data[1]);
                    pos.Y = float.Parse(data[2]);
                    pos.Z = float.Parse(data[3]);
                    Vector3 normal;
                    normal.X = float.Parse(data[4]);
                    normal.Y = float.Parse(data[5]);
                    normal.Z = float.Parse(data[6]);
                    normal.Normalize();
                    Vector2 texcoord;
                    texcoord.X = float.Parse(data[7]);
                    texcoord.Y = float.Parse(data[8]);
                    if (data.Length > 10) //Code for multiple blendweights
                    {
                        int boneBlendCount = int.Parse(data[9]);
                        for (int m = 0; m < boneBlendCount; m++)
                        {
                            int index = m * 2 + 10;
                            switch (m)
                            {
                                case 0:
                                    bone.Y = int.Parse(data[index]);
                                    boneWeights.Y = float.Parse(data[index + 1]);
                                    break;
                                case 1:
                                    bone.Z = int.Parse(data[index]);
                                    boneWeights.Z = float.Parse(data[index + 1]);
                                    break;
                                case 2:
                                    bone.W = int.Parse(data[index]);
                                    boneWeights.W = float.Parse(data[index + 1]);
                                    break;
                            }
                        }
                        float sum = Vector4.Dot(boneWeights, Vector4.One);
                        boneWeights.X = 1.0f - sum;
                    }
                    vertices[i] = new VertexPNTTB(pos, normal, texcoord, bone, boneWeights, Vector3.Zero);
                    indicesList[materialName].Add((ushort)(vertexLists[materialName].Count+i));
                }

                //Compute our tangent vectors
                MathUtils.ComputeTangent(ref vertices[0], vertices[1], vertices[2]);
                MathUtils.ComputeTangent(ref vertices[1], vertices[2], vertices[0]);
                MathUtils.ComputeTangent(ref vertices[2], vertices[0], vertices[1]);
                vertexLists[materialName].AddRange(vertices);
            }

            this.modelGroups = new ModelPart[vertexLists.Keys.Count];
            for (int i = 0; i < vertexLists.Keys.Count; i++)
            {
                string key = vertexLists.Keys[i];

                VertexBuffer vertexBuffer = new VertexBuffer(GFX.Device, vertexLists[key].Count * VertexPNTTB.SizeInBytes, BufferUsage.WriteOnly);
                vertexBuffer.SetData<VertexPNTTB>(vertexLists[key].ToArray());

                IndexBuffer indexBuffer = new IndexBuffer(GFX.Device, sizeof(ushort) * indicesList[key].Count, BufferUsage.WriteOnly, IndexElementSize.SixteenBits);
                indexBuffer.SetData<ushort>(indicesList[key].ToArray());

                Vector3 pos = new Vector3(vertexLists[key][0].Position.X, vertexLists[key][0].Position.Y, vertexLists[key][0].Position.Z);
                BoundingBox bounds = new BoundingBox(pos, pos);
                for (int j = 0; j < vertexLists[key].Count; j++)
                {
                    pos = new Vector3(vertexLists[key][j].Position.X, vertexLists[key][j].Position.Y, vertexLists[key][j].Position.Z);
                    bounds.Max = Vector3.Max(bounds.Max, pos);
                    bounds.Min = Vector3.Min(bounds.Min, pos);
                }

                modelGroups[i] = new ModelPart(key, vertexBuffer, indexBuffer, bounds);
            }
        }
Exemple #40
0
        public virtual void Parse(XmlNode node)
        {
            foreach (XmlNode child in node.ChildNodes)
            {
                string name = child.Name.ToLower();

                if (name == "animation")
                    continue; // skip animation
                else if (name == "ismirrored")
                    IsMirrored = bool.Parse(child.InnerText);
                else if (name == "offset")
                    Offset = Mesh.StringToVertex3(child.InnerText);
                else if (name == "position")
                    Position = Mesh.StringToVertex3(child.InnerText);
                else if (name == "rotation")
                    Rotation = Mesh.StringToVertex3(child.InnerText);
                else if (name == "size")
                    Size = Mesh.StringToVertex3(child.InnerText);
                else if (name == "scale")
                    Scale = float.Parse(child.InnerText, CultureInfo.InvariantCulture.NumberFormat);
                else if (name == "textureoffset")
                    TextureOffset = Mesh.StringToVertex2(child.InnerText);
                else if (name == "part")
                    Part = (ModelPart)Enum.Parse(typeof(ModelPart), child.InnerText);
            }
        }
Exemple #41
0
 public void Include(ModelPart modelPart)
 {
     _ignoredModelParts.Remove(modelPart);
 }
 /// <summary>
 /// Nests one model part's mesh inside another, using a named tag as a transform
 /// </summary>
 private static void NestMesh( Model model, ModelPart parent, ModelPart child, string tagName )
 {
     model.GetPartMesh( parent ).AddNestedPart( child, model.GetPartMesh( parent ).GetTagIndex( tagName ) );
 }
Exemple #43
0
        private void ReadModelPartVertices(ModelPart modelPart)
        {
            var vertexCount = _reader.ReadInt32();

            modelPart.Vertices = new Vector3[vertexCount];
            for (var i = 0; i < vertexCount; i++)
            {
                var vertex = _reader.ReadVector();
                modelPart.Vertices[i] = vertex;
            }
        }
 /// <summary>
 /// Gets the mesh for a specified body part
 /// </summary>
 public ModelMesh GetPartMesh( ModelPart part )
 {
     return m_PartMeshes[ ( int )part ];
 }
        /// <summary>
        /// Loads an MD3 mesh resource from a stream
        /// </summary>
        private static ModelMesh LoadMd3( ISource source, Model model, ModelPart part, Matrix44 transform, ISource md3Source, IDictionary<string, ITexture2d> surfaceTextureTable )
        {
            using ( Stream inputStream = OpenStream( md3Source ) )
            {
                BinaryReader reader = new BinaryReader( inputStream );

                //	http://icculus.org/homepages/phaethon/q3a/formats/md3format.html

                //	Make sure of the MD3 identity
                byte[] ident		= reader.ReadBytes( 4 );
                if ( ( ident[ 0 ] != 'I' ) || ( ident[ 1 ] != 'D' ) || ( ident[ 2 ] != 'P' ) || ( ident[ 3 ] != '3' ) )
                {
                    throw new ApplicationException( "Failed to load MD3 resource - stream did not start with 'IDP3' MD3 identifier" );
                }

                //	Read in header
                //int version			=
                reader.ReadInt32( );
                //string name			=
                ReadString( reader, MaxPathLength );
                //int flags			=
                reader.ReadInt32( );
                int numFrames		= reader.ReadInt32( );
                int numTags			= reader.ReadInt32( );
                int numSurfaces		= reader.ReadInt32( );
                //int numSkins		=
                reader.ReadInt32( );
                int framesOffset	= reader.ReadInt32( );
                int tagsOffset		= reader.ReadInt32( );
                int surfacesOffset	= reader.ReadInt32( );
                //int eofOffset		=
                reader.ReadInt32( );

                //	TODO: Can load directly into mesh frame, tag and surface structures - don't do this intermediate step
                ModelMesh mesh = new ModelMesh( model, part );

                ReadFrames( reader, framesOffset, numFrames, mesh, transform );
                ReadTags( reader, tagsOffset, numTags, numFrames, mesh, transform );
                ReadSurfaces( source, reader, surfacesOffset, numSurfaces, numFrames, mesh, surfaceTextureTable, transform );

                //	TODO: REMOVE. test frames
                string md3Name = md3Source.ToString( );
                if ( md3Name.IndexOf( "Upper" ) != -1 )
                {
                    mesh.DefaultFrame = 151;
                }
                else if ( md3Name.IndexOf( "Head" ) != -1 )
                {
                    mesh.DefaultFrame = 0;
                }
                else
                {
                    mesh.DefaultFrame = 0;
                }

                return mesh;
            }
        }
Exemple #46
0
 public Anchor Clone(ModelPart parent)
 {
     return new Anchor(parent, Position, Name);
 }
Exemple #47
0
 private static void WriteModelPartFaces(BinaryWriter writer, ModelPart modelPart)
 {
     writer.Write(modelPart.Faces.Length);
     foreach (var modelPartFace in modelPart.Faces)
     {
         WriteModelPartFace(writer, modelPartFace);
     }
 }
Exemple #48
0
 private static void WriteModelPartVertices(BinaryWriter writer, ModelPart modelPart)
 {
     writer.Write(modelPart.Vertices.Length);
     foreach (var vector3 in modelPart.Vertices)
     {
         writer.Write(vector3);
     }
 }
 /// <summary>
 /// Returns the default skin filename for a part
 /// </summary>
 private static ISource DefaultSkinFile( ISource source, ModelPart part )
 {
     return AssetUtils.GetRelativeFile( source, part + "_default.skin" );
 }
Exemple #50
0
        private void WriteModelPart(BinaryWriter writer, ModelPart modelPart)
        {
            writer.Write(modelPart.Id);
            writer.Write(modelPart.Name);
            writer.Write(modelPart.Position);
            writer.Write(modelPart.Rotation); // new for EMF2

            writer.Write(_materialTranslator.Translate(modelPart.MaterialId));

            WriteModelPartAnchors(writer, modelPart);
            WriteModelPartFaces(writer, modelPart);
            WriteModelPartVertices(writer, modelPart);
        }
Exemple #51
0
        private void ToggleVisiblePart(ModelPart part)
        {
            var meshes = new List<Mesh>();
            var item = _partItems[(int)part];
            var button = _partButtons[(int)part];

            foreach (var m in CurrentModel.Meshes)
                if (m.Part == part)
                    meshes.Add(m);

            if (meshes.Count != 0)
            {
                item.Checked = button.Checked = !item.Checked;

                foreach (var m in meshes)
                    CurrentModel.PartsEnabled[CurrentModel.Meshes.IndexOf(m)] = item.Checked;
            }

            CalculateMatrices();
            Renderer.Invalidate();
        }
Exemple #52
0
 private void ReadModelPartAnchors(ModelPart modelPart)
 {
     var anchorCount = _reader.ReadInt32();
     modelPart.Anchors.Clear();
     for (int i = 0; i < anchorCount; i++)
     {
         modelPart.Anchors.Add(ReadAnchor(modelPart));
     }
 }
Exemple #53
0
        private ModelPartFace ReadModelPartFace(ModelPart modelPart)
        {
            var index = _reader.ReadInt32();

            var modelPartFace = new ModelPartFace(index, modelPart) {Colour = _reader.ReadColour()};

            var texCoordinateCount = _reader.ReadInt32();
            modelPartFace.TextureCoordinates = new Vector2[texCoordinateCount];
            for (var i = 0; i < texCoordinateCount; i++)
            {
                modelPartFace.TextureCoordinates[i] = _reader.ReadVectorXY();
            }

            var vertexIndexCount = _reader.ReadInt32();
            modelPartFace.VertexIndices = new int[vertexIndexCount];
            for (var i = 0; i < vertexIndexCount; i++)
            {
                modelPartFace.VertexIndices[i] = _reader.ReadInt32();
            }

            ReadModelPartFaceTriangles(modelPartFace);

            return modelPartFace;
        }
Exemple #54
0
        private void ReadModelPartFaces(ModelPart modelPart)
        {
            var faceCount = _reader.ReadInt32();

            modelPart.Faces = new ModelPartFace[faceCount];
            for (var i = 0; i < faceCount; i++)
            {
                var face = ReadModelPartFace(modelPart);
                modelPart.Faces[i] = face;
            }
        }
 /// <summary>
 /// Returns the mesh filename for a part
 /// </summary>
 private static ISource MeshFile( ISource source, ModelPart part )
 {
     return AssetUtils.GetRelativeFile( source, part + ".md3" );
 }
Exemple #56
0
        private Anchor ReadAnchor(ModelPart modelPart)
        {
            int? id = null;

            if (_modelFormat >= ModelFormat.Emf4)
            {
                id = _reader.ReadInt32();
            }

            var position = _reader.ReadVector();
            var name = _reader.ReadString();

            var rotation = new Vector3();
            if (_modelFormat >= ModelFormat.Emf3)
            {
                rotation = _reader.ReadVector();
            }

            var anchor = new Anchor(modelPart, position, name)
            {
                Rotation = rotation
            };

            if (id.HasValue)
            {
                anchor.Id = id.Value;
            }

            var childCount = _reader.ReadInt32();

            for (var i = 0; i < childCount; i++)
            {
                if (!_childIds.ContainsKey(anchor))
                {
                    _childIds[anchor] = new List<int>();
                }

                var childId = _reader.ReadInt32();
                _childIds[anchor].Add(childId);
            }
            return anchor;
        }
 /// <summary>
 /// Sets the mesh for a specified body part
 /// </summary>
 public void SetPartMesh( ModelPart part, ModelMesh mesh )
 {
     m_PartMeshes[ ( int )part ] = mesh;
 }
Exemple #58
0
 private static void WriteModelPartAnchors(BinaryWriter writer, ModelPart modelPart)
 {
     writer.Write(modelPart.Anchors.Count);
     foreach (var anchor in modelPart.Anchors)
     {
         WriteAnchor(writer, anchor);
     }
 }
Exemple #59
0
        public void RemoveChild(ModelPart modelPart)
        {
            if (!Children.Contains(modelPart))
            {
                throw new Exception("Cannot remove modelPart from this Anchor. This Anchor is not a parent of the ModelPart.");
            }

            var childAnchor = modelPart.Pivot;

            childAnchor.DetachFromParent();
        }
Exemple #60
0
        private void ReadModelPart()
        {
            var id = _reader.ReadInt32();
            var modelPart = new ModelPart(id)
            {
                Name = _reader.ReadString(),
                Position = _reader.ReadVector()
            };

            if (_modelFormat >= ModelFormat.Emf2)
            {
                modelPart.Rotation = _reader.ReadVector();
            }

            var materialName = _reader.ReadString();
            modelPart.MaterialId = _materialTranslator.Translate(materialName);

            ReadModelPartAnchors(modelPart);
            ReadModelPartFaces(modelPart);
            ReadModelPartVertices(modelPart);

            _model.ModelParts.Add(modelPart);
        }