Пример #1
0
    static GameObject processNodeAndLinkToParent(NIFFile nf, NiNode niNode, GameObject parent, bool skinMesh)
    {
        GameObject goM = new GameObject();

        goM.name = niNode.name;

        foreach (NiMesh mesh in nf.getMeshes())
        {
            if (mesh.parentIndex == niNode.index)
            {
                GameObject meshGo = processMesh(nf, mesh, nf.getMeshData(mesh), skinMesh);
                if (niNode is NiTerrainNode)
                {
                    //meshGo.GetComponent<MeshRenderer>().material = new Material(Shader.Find("BasicTerrainShader"));
                    //Debug.Log("found a terrain node");
                }
                meshGo.transform.parent     = goM.transform;
                meshGo.transform.localScale = new Vector3(mesh.scale, mesh.scale, mesh.scale);
                Quaternion q = GetRotation(toMat(mesh.matrix));
                meshGo.transform.localRotation = q;
                //meshGo.transform.localEulerAngles = new Vector3(mesh.ma)
            }
        }

        nf.forEachChildNode(niNode.index, (obj) => processNodeAndLinkToParent(nf, obj, goM, skinMesh));

        goM.transform.parent = parent.transform;

        // Terrain NIFs already have their location set in the parent node, we don't need to set it for the mesh.
        if (!(niNode is NiTerrainNode))
        {
            goM.transform.localPosition = new Vector3(niNode.translation.x, niNode.translation.y, niNode.translation.z);
            Matrix4x4 mat = toMat(niNode.matrix);

            Quaternion q = GetRotation(mat);
            goM.transform.localRotation = q;

            //Debug.Log("[" + niNode.name + "]: trans:\n" + mat.GetRow(0) + "\n" + mat.GetRow(1) + "\n" + mat.GetRow(2) + "\n" + mat.GetRow(3));
            //goM.transform.localEulerAngles =
        }
        else
        {
        }
        goM.transform.localScale = new Vector3(niNode.scale, niNode.scale, niNode.scale);
        //goM.transform.localRotation
        return(goM);
    }
Пример #2
0
    public static GameObject loadNIF(NIFFile nf, string fname, bool skinMesh = false, GameObject prefab = null)
    {
        GameObject root;

        if (prefab != null)
        {
            root = prefab;
        }
        else
        {
            root = new GameObject();
        }
        root.name = Path.GetFileNameWithoutExtension(fname);
        root.transform.localPosition = Vector3.zero;

        nf.forEachChildNode(-1, (obj) => processNodeAndLinkToParent(nf, obj, root, skinMesh));

        if (skinMesh)
        {
            linkBonesToMesh(nf, root);
        }
        return(root);
    }