Beispiel #1
0
        /// <summary>
        /// Finishes initializing an instantiated cell object.
        /// </summary>
        private void PostProcessInstantiatedCellObject(GameObject gameObject, RefCellObjInfo refCellObjInfo)
        {
            var refObjDataGroup = refCellObjInfo.refObjDataGroup;

            // Handle object transforms.
            if (refObjDataGroup.XSCL != null)
            {
                gameObject.transform.localScale = Vector3.one * refObjDataGroup.XSCL.value;
            }

            gameObject.transform.position += NIFUtils.NifPointToUnityPoint(refObjDataGroup.DATA.position);
            gameObject.transform.rotation *= NIFUtils.NifEulerAnglesToUnityQuaternion(refObjDataGroup.DATA.eulerAngles);

            var tagTarget = gameObject;
            var coll      = gameObject.GetComponentInChildren <Collider>(); // if the collider is on a child object and not on the object with the component, we need to set that object's tag instead.

            if (coll != null)
            {
                tagTarget = coll.gameObject;
            }

            ProcessObjectType <DOORRecord>(tagTarget, refCellObjInfo, "Door");
            ProcessObjectType <ACTIRecord>(tagTarget, refCellObjInfo, "Activator");
            ProcessObjectType <CONTRecord>(tagTarget, refCellObjInfo, "Container");
            ProcessObjectType <LIGHRecord>(tagTarget, refCellObjInfo, "Light");
            ProcessObjectType <LOCKRecord>(tagTarget, refCellObjInfo, "Lock");
            ProcessObjectType <PROBRecord>(tagTarget, refCellObjInfo, "Probe");
            ProcessObjectType <REPARecord>(tagTarget, refCellObjInfo, "RepairTool");
            ProcessObjectType <WEAPRecord>(tagTarget, refCellObjInfo, "Weapon");
            ProcessObjectType <CLOTRecord>(tagTarget, refCellObjInfo, "Clothing");
            ProcessObjectType <ARMORecord>(tagTarget, refCellObjInfo, "Armor");
            ProcessObjectType <INGRRecord>(tagTarget, refCellObjInfo, "Ingredient");
            ProcessObjectType <ALCHRecord>(tagTarget, refCellObjInfo, "Alchemical");
            ProcessObjectType <APPARecord>(tagTarget, refCellObjInfo, "Apparatus");
            ProcessObjectType <BOOKRecord>(tagTarget, refCellObjInfo, "Book");
            ProcessObjectType <MISCRecord>(tagTarget, refCellObjInfo, "MiscObj");
            ProcessObjectType <CREARecord>(tagTarget, refCellObjInfo, "Creature");
            ProcessObjectType <NPC_Record>(tagTarget, refCellObjInfo, "NPC");
        }
Beispiel #2
0
        private Mesh NiTriShapeDataToMesh(NiTriShapeData data)
        {
            // vertex positions
            var vertices = new Vector3[data.vertices.Length];

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = NIFUtils.NifPointToUnityPoint(data.vertices[i]);
            }

            // vertex normals
            Vector3[] normals = null;
            if (data.hasNormals)
            {
                normals = new Vector3[vertices.Length];

                for (int i = 0; i < normals.Length; i++)
                {
                    normals[i] = NIFUtils.NifVectorToUnityVector(data.normals[i]);
                }
            }

            // vertex UV coordinates
            Vector2[] UVs = null;
            if (data.hasUV)
            {
                UVs = new Vector2[vertices.Length];

                for (int i = 0; i < UVs.Length; i++)
                {
                    var NiTexCoord = data.UVSets[0, i];

                    UVs[i] = new Vector2(NiTexCoord.u, NiTexCoord.v);
                }
            }

            // triangle vertex indices
            var triangles = new int[data.numTrianglePoints];

            for (int i = 0; i < data.triangles.Length; i++)
            {
                int baseI = 3 * i;

                // Reverse triangle winding order.
                triangles[baseI]     = data.triangles[i].v1;
                triangles[baseI + 1] = data.triangles[i].v3;
                triangles[baseI + 2] = data.triangles[i].v2;
            }

            // Create the mesh.
            Mesh mesh = new Mesh();

            mesh.vertices  = vertices;
            mesh.normals   = normals;
            mesh.uv        = UVs;
            mesh.triangles = triangles;

            if (!data.hasNormals)
            {
                mesh.RecalculateNormals();
            }

            mesh.RecalculateBounds();

            return(mesh);
        }
Beispiel #3
0
 private void ApplyNiAVObject(NiAVObject anNiAVObject, GameObject obj)
 {
     obj.transform.position   = NIFUtils.NifPointToUnityPoint(anNiAVObject.translation);
     obj.transform.rotation   = NIFUtils.NifRotationMatrixToUnityQuaternion(anNiAVObject.rotation);
     obj.transform.localScale = anNiAVObject.scale * Vector3.one;
 }