Beispiel #1
0
        private void GetObjFace(ObjFace face, ObjItem objModel,
                                ref List <float> vertexPositions, ref List <float> vertexNormals, ref List <float> vertexTextureCoordinates, ref List <float> vertexBoneWeights, ref List <float> vertexBoneIndices, ref List <uint> indeces)
        {
            if (face.Count == 3)
            {
                for (var i = 0; i < face.Count; i++)
                {
                    var faceVertex = face[i];
                    ObjLoader.AppendObjTriangle(objModel, faceVertex, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                }
                SetFaceTriangleIndex(face, objModel);
            }
            else if (face.Count == 4)
            {
                var faceVertex0 = face[0];
                var faceVertex1 = face[1];
                var faceVertex2 = face[2];
                var faceVertex3 = face[3];

                ObjLoader.AppendObjTriangle(objModel, faceVertex0, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                ObjLoader.AppendObjTriangle(objModel, faceVertex1, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                ObjLoader.AppendObjTriangle(objModel, faceVertex2, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);

                ObjLoader.AppendObjTriangle(objModel, faceVertex2, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                ObjLoader.AppendObjTriangle(objModel, faceVertex3, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                ObjLoader.AppendObjTriangle(objModel, faceVertex0, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                SetFaceTriangleIndex(face, objModel);
            }
        }
Beispiel #2
0
        /// <summary> Accessory file saved in program. Here is a few accessories devided by groups </summary>
        private List <DynamicRenderMesh> LoadSpecialAccessoryMesh(ObjItem objModel)
        {
            var result = new List <DynamicRenderMesh>();

            foreach (var modelGroup in objModel.Groups)
            {
                var vertexPositions          = new List <float>();
                var vertexNormals            = new List <float>();
                var vertexTextureCoordinates = new List <float>();
                var vertexBoneIndices        = new List <float>();
                var vertexBoneWeights        = new List <float>();
                var indeces = new List <uint>();
                foreach (var face in modelGroup.Value.Faces)
                {
                    if (face.Count == 3)
                    {
                        for (var i = 0; i < face.Count; i++)
                        {
                            var faceVertex = face[i];
                            ObjLoader.AppendObjTriangle(objModel, faceVertex, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                        }
                    }
                    else if (face.Count == 4)
                    {
                        var faceVertex0 = face[0];
                        var faceVertex1 = face[1];
                        var faceVertex2 = face[2];
                        var faceVertex3 = face[3];

                        ObjLoader.AppendObjTriangle(objModel, faceVertex0, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                        ObjLoader.AppendObjTriangle(objModel, faceVertex1, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                        ObjLoader.AppendObjTriangle(objModel, faceVertex2, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);

                        ObjLoader.AppendObjTriangle(objModel, faceVertex2, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                        ObjLoader.AppendObjTriangle(objModel, faceVertex3, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                        ObjLoader.AppendObjTriangle(objModel, faceVertex0, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                    }
                }

                if (vertexPositions.Count == 0)
                {
                    continue;
                }

                var renderMesh = new DynamicRenderMesh(MeshType.Accessory);
                if (renderMesh.Create(vertexPositions, vertexTextureCoordinates, vertexBoneIndices, vertexBoneWeights, indeces, string.Empty, string.Empty))
                {
                    renderMesh.Title = modelGroup.Key.Name == "default" ? string.Empty : modelGroup.Key.Name;
                    renderMesh.Material.DiffuseColor = new Vector4(modelGroup.Key.DiffuseColor.X, modelGroup.Key.DiffuseColor.Y, modelGroup.Key.DiffuseColor.Z, modelGroup.Key.Transparency);

                    if (!string.IsNullOrEmpty(modelGroup.Key.DiffuseTextureMap))
                    {
                        renderMesh.Material.DiffuseTextureMap = modelGroup.Key.DiffuseTextureMap;
                    }
                    if (!string.IsNullOrEmpty(modelGroup.Key.TransparentTextureMap))
                    {
                        renderMesh.Material.TransparentTextureMap = modelGroup.Key.TransparentTextureMap;
                    }

                    var         center = Vector3.Zero;
                    var         count  = vertexPositions.Count / 3;
                    const float scale  = 246f;
                    for (var i = 0; i < count; i++)
                    {
                        center.X += vertexPositions[i * 3] * scale;
                        center.Y += vertexPositions[i * 3 + 1] * scale;
                        center.Z += vertexPositions[i * 3 + 2] * scale;
                    }
                    center /= count;
                    renderMesh.Transform = Matrix4.CreateScale(scale);

                    /*   renderMesh.Transform[3, 0] = -center.X;
                     * renderMesh.Transform[3, 1] = -center.Y;
                     * renderMesh.Transform[3, 2] = -center.Z;*/
                    renderMesh.Position = center;
                    AccesoryMeshes.Add(renderMesh);


                    result.Add(renderMesh);
                }
            }

            return(result);
        }
Beispiel #3
0
        /// <summary> Accessory file by default. Usually here is one accessory devided for differen groups. But it's not correct, so we combine it to one mesh</summary>
        public static DynamicRenderMesh LoadAccessoryMesh(ObjItem objModel)
        {
            var vertexPositions          = new List <float>();
            var vertexNormals            = new List <float>();
            var vertexTextureCoordinates = new List <float>();
            var vertexBoneIndices        = new List <float>();
            var vertexBoneWeights        = new List <float>();
            var indeces         = new List <uint>();
            var defaultMaterial = default(ObjMaterial);

            foreach (var modelGroup in objModel.Groups)
            {
                defaultMaterial = modelGroup.Key;
                foreach (var face in modelGroup.Value.Faces)
                {
                    if (face.Count == 3)
                    {
                        for (var i = 0; i < face.Count; i++)
                        {
                            var faceVertex = face[i];
                            ObjLoader.AppendObjTriangle(objModel, faceVertex, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                        }
                    }
                    else if (face.Count == 4)
                    {
                        var faceVertex0 = face[0];
                        var faceVertex1 = face[1];
                        var faceVertex2 = face[2];
                        var faceVertex3 = face[3];

                        ObjLoader.AppendObjTriangle(objModel, faceVertex0, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                        ObjLoader.AppendObjTriangle(objModel, faceVertex1, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                        ObjLoader.AppendObjTriangle(objModel, faceVertex2, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);

                        ObjLoader.AppendObjTriangle(objModel, faceVertex2, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                        ObjLoader.AppendObjTriangle(objModel, faceVertex3, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                        ObjLoader.AppendObjTriangle(objModel, faceVertex0, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces);
                    }
                }
            }

            var renderMesh = new DynamicRenderMesh(MeshType.Accessory);

            if (renderMesh.Create(vertexPositions, vertexTextureCoordinates, vertexBoneIndices, vertexBoneWeights, indeces, string.Empty, string.Empty))
            {
                renderMesh.Material.DiffuseColor = new Vector4(defaultMaterial.DiffuseColor.X, defaultMaterial.DiffuseColor.Y, defaultMaterial.DiffuseColor.Z, defaultMaterial.Transparency);

                if (!string.IsNullOrEmpty(defaultMaterial.DiffuseTextureMap))
                {
                    renderMesh.Material.DiffuseTextureMap = defaultMaterial.DiffuseTextureMap;
                }
                if (!string.IsNullOrEmpty(defaultMaterial.TransparentTextureMap))
                {
                    renderMesh.Material.TransparentTextureMap = defaultMaterial.TransparentTextureMap;
                }

                var   center = Vector3.Zero;
                var   count  = vertexPositions.Count / 3;
                float scale  = 246f;
#if WEB_APP
                scale *= ProgramCore.Project.RenderMainHelper.headMeshesController.RenderMesh.MorphScale;
#endif

                for (var i = 0; i < count; i++)
                {
                    center.X += vertexPositions[i * 3] * scale;
                    center.Y += vertexPositions[i * 3 + 1] * scale;
                    center.Z += vertexPositions[i * 3 + 2] * scale;
                }
                center /= count;
                renderMesh.Transform       = Matrix4.CreateScale(scale);
                renderMesh.Transform[3, 0] = -center.X;
                renderMesh.Transform[3, 1] = -center.Y;
                renderMesh.Transform[3, 2] = -center.Z;
                renderMesh.Position        = center;
            }
            return(renderMesh);
        }