GameObject InstantiateNiTriShape(NiTriShape triShape, bool visual, bool collidable)
        {
            Assert(visual || collidable);
            var mesh = NiTriShapeDataToMesh((NiTriShapeData)_obj.Blocks[triShape.Data.Value]);
            var obj  = new GameObject(triShape.Name);

            if (visual)
            {
                obj.AddComponent <MeshFilter>().mesh = mesh;
                var materialProps = NiAVObjectPropertiesToMaterialProperties(triShape);
                var meshRenderer  = obj.AddComponent <MeshRenderer>();
                meshRenderer.material = _materialManager.BuildMaterialFromProperties(materialProps);
                if (Utils.ContainsBitFlags(triShape.Flags, (int)NiAVObject.NiFlags.Hidden))
                {
                    meshRenderer.enabled = false;
                }
                obj.isStatic = true;
            }
            if (collidable)
            {
                obj.AddComponent <MeshCollider>().sharedMesh = mesh;
                if (KinematicRigidbodies)
                {
                    obj.AddComponent <Rigidbody>().isKinematic = true;
                }
            }
            ApplyNiAVObject(triShape, obj);
            return(obj);
        }
示例#2
0
        private GameObject InstantiateNiTriShape(NiTriShape triShape, bool visual, bool collidable)
        {
            Debug.Assert(visual || collidable);

            var mesh = NiTriShapeDataToMesh((NiTriShapeData)file.blocks[triShape.data.value]);
            var obj  = new GameObject(triShape.name);

            if (visual)
            {
                obj.AddComponent <MeshFilter>().mesh = mesh;

                var materialProps = NiAVObjectPropertiesToMWMaterialProperties(triShape);

                var meshRenderer = obj.AddComponent <MeshRenderer>();
                meshRenderer.material = materialManager.BuildMaterialFromProperties(materialProps);

                if (Utils.ContainsBitFlags(triShape.flags, (uint)NiAVObject.Flags.Hidden))
                {
                    meshRenderer.enabled = false;
                }
            }

            if (collidable)
            {
                obj.AddComponent <MeshCollider>().sharedMesh = mesh;
                if (TESUnity.instance.useKinematicRigidbodies)
                {
                    obj.AddComponent <Rigidbody>().isKinematic = true;
                }
            }

            ApplyNiAVObject(triShape, obj);

            return(obj);
        }
示例#3
0
 public ShapeDesc()
 {
     this.shape       = (NiTriShape)null;
     this.data        = (NiTriShapeData)null;
     this.textures    = new string[2];
     this.boundingBox = new BBox();
     // relative x, y for segment
     this.x        = new float();
     this.y        = new float();
     this.segments = new List <SegmentDesc>();
 }
示例#4
0
        private void ParseShape(NiTriShape shape)
        {
            List <string> export = new List <string>();

            NiTriShapeData geometry = (NiTriShapeData)shape.Data.Object;

            // Verticles (v)
            if (geometry.HasVertices && geometry.NumVertices >= 3)
            {
                Matrix transformationMatrix = ComputeWorldMatrix(shape);
                computePolys(geometry.Triangles, geometry.Vertices, transformationMatrix);
            }
        }
示例#5
0
        public Mesh(Device device, NiHeader header, ObjectRef triShape_ref)
        {
            this.header       = header;
            this.triShape_ref = triShape_ref;

            NiTriShape triShape = header.GetObject <NiTriShape>(triShape_ref);

            Matrix triShape_local_m;

            ToMatrix(triShape.local, out triShape_local_m);

            var triShape_data = header.GetObject <NiTriShapeData>(triShape.data);

            shader_property = header.GetObject <BSLightingShaderProperty>(triShape.shader_property);
            var shader_texture_set = header.GetObject <BSShaderTextureSet>(shader_property.texture_set);
            var skin_instance      = header.GetObject <NiSkinInstance>(triShape.skin_instance);

            skin_data = header.GetObject <NiSkinData>(skin_instance.data);
            var skin_partition = header.GetObject <NiSkinPartition>(skin_instance.skin_partition);

            albedoMap_path = Path.GetFileName(shader_texture_set.textures[0]);

            num_bones = skin_instance.num_bones;
            bones     = skin_instance.bones;

            submeshes = new SubMesh[skin_partition.num_skin_partitions];
            for (int part_i = 0; part_i < skin_partition.num_skin_partitions; part_i++)
            {
                ref SkinPartition part = ref skin_partition.skin_partitions[part_i];

                // create submesh vertices/uvs from part.vertex_map

                Vector3[] positions = new Vector3[part.num_vertices];
                Vector2[] uvs       = new Vector2[part.num_vertices];

                for (int i = 0; i < part.num_vertices; i++)
                {
                    ushort x = part.vertex_map[i];
                    Vector3.TransformCoordinate(ref triShape_data.vertices[x], ref triShape_local_m, out positions[i]);
                    uvs[i] = triShape_data.uvs[x];
                }

                submeshes[part_i] = new SubMesh(device, positions, uvs, part.vertex_weights, part.bone_indices, part.triangles, part.bones);
            }
        private string ParseShape(NiTriShape shape)
        {
            if (!shape.Data.IsValid())
            {
                return("");
            }

            NiTriShapeData geometry = (NiTriShapeData)shape.Data.Object;

            // The final text
            List <string> export = new List <string>();

            Matrix transformationMatrix = ComputeWorldMatrix(shape);

            // Set Object name
            export.Add("g Shape " + shape.Name + Environment.NewLine);

            NiMaterialProperty  material = null;
            NiTexturingProperty texture  = null;

            foreach (NiRef <NiProperty> property in shape.Properties)
            {
                if (property.Object is NiMaterialProperty)
                {
                    material = property.Object as NiMaterialProperty;
                }
                if (property.Object is NiTexturingProperty)
                {
                    texture = property.Object as NiTexturingProperty;
                }
            }

            if (material != null && texture != null)
            {
                export.Add(printMaterial(material, texture));
            }

            // Verticles (v)
            if (geometry.HasVertices && geometry.NumVertices >= 3)
            {
                export.Add(printVertices(geometry.Vertices, transformationMatrix));
            }

            // Texture coordinates (vt)
            if (geometry.UVSets.Length > 0)
            {
                export.Add(printUvSets(geometry.UVSets));
            }

            // Normals (vn)
            if (geometry.HasNormals)
            {
                export.Add(printNormals(geometry.Normals, transformationMatrix));
            }

            // Parameter space vertices (vp)

            // Face Definitions (f)
            export.Add(printTriangles(geometry.Triangles, (geometry.UVSets.Length > 0)));

            return(string.Join(Environment.NewLine, export));
        }