Ejemplo n.º 1
0
        /** Load the KFB data for the selected animation, will return null if the animation does not exist in the KFB */
        private byte[] getKFBData(int animToUse)
        {
            if (kfb == null)
            {
                return(null);
            }
            if (kfbfile == null)
            {
                if (this.adb.filenameExists(this.kfb))
                {
                    kfbfile = NIFLoader.getNIF(this.kfb);
                }
                else
                {
                    return(null);
                }
                //Debug.Log("getting KFB: " + this.kfb);
            }
            /** Choose the right animation to load from the KFB file. Ideally we should use the KFM to know what index to use */
            for (int i = 0; i < kfbfile.numObjects; i += 4)
            {
                NiIntegerExtraData indexData = (NiIntegerExtraData)kfbfile.getObject(i);
                NiIntegerExtraData sizeData  = (NiIntegerExtraData)kfbfile.getObject(i + 1);
                NiBinaryExtraData  binData   = (NiBinaryExtraData)kfbfile.getObject(i + 2);
                NiBinaryExtraData  binData2  = (NiBinaryExtraData)kfbfile.getObject(i + 3);

                int animIdx = indexData.intExtraData;
                if (animIdx == animToUse)
                {
                    return(binData.getData());
                }
            }
            //Debug.LogError("[" + this.kfb + "] can't find data for anim[" + animToUse + "]");
            return(null);
        }
Ejemplo n.º 2
0
        private GameObject loadNIFForSlot(GearSlot slot, GameObject skeleton, GameObject meshHolder, string nifFile, string geo)
        {
            //Debug.Log("load nif[" + nifFile + "] for slot " + slot, this.gameObject);
            // First move all the meshes across to the skeleton
            GameObject meshes = new GameObject(slot.ToString());

            //Debug.Log("create new gameobh:" + meshes.name);
            try
            {
                NIFFile    file       = NIFLoader.getNIF(nifFile);
                GameObject newNifRoot = NIFLoader.loadNIF(file, nifFile, true);

                meshes.transform.parent = meshHolder.transform;

                //Debug.Log("Move components from loaded nif to our new gameobj");
                foreach (SkinnedMeshRenderer r in newNifRoot.GetComponentsInChildren <SkinnedMeshRenderer>(true))
                {
                    //  Debug.Log("Move renderer " + r.gameObject.name);
                    r.transform.parent = meshes.transform;
                }

                /** I'm not quite sure how bows are supposed to work yet. The quiver, bow and prop all appear to be a single mesh, so they must be moved around using bones or something..
                 * At the moment they don't even show propertly because the ROOT bone assigned while loading is not copied over and is destroyed causing the SKinnedMeshRender to behave poorly
                 * More research required.
                 */

                // weapons are a bit different
                if (!WardrobeStuff.isWeapon(slot))
                {
                    // process the NiSkinningMeshModifier
                    NIFLoader.linkBonesToMesh(file, skeleton);
                }
                else
                {
                    //Debug.Log("Treating slot (" + slot + ") as weapon and attach it to AP_r_hand on skeleton");
                    Transform t = skeleton.transform.FindDeepChild("AP_r_hand");

                    meshes.transform.parent        = t;
                    meshes.transform.localPosition = new Vector3(0, 0, 0);
                }

                this.animationNif.clearBoneMap();

                // disable the proxy geo
                enableDisableGeo(nifFile, skeleton, false);
                // special case to ensure boots are disabled as well
                if (nifFile.Contains("foot"))
                {
                    enableDisableGeo("boots", skeleton, false);
                }

                GameObject.DestroyObject(newNifRoot);
            }
            catch (Exception ex)
            {
                Debug.Log("Exception trying to load nif[" + nifFile + "]" + ex);
            }
            return(meshes);
        }
Ejemplo n.º 3
0
        static public GameObject loadNIFFromFile(string nifFile, string kfm, string kfb)
        {
            GameObject  nifmodel = NIFLoader.loadNIFFromFile(nifFile, true);
            AnimatedNif nif      = nifmodel.AddComponent <AnimatedNif>();

            nif.setParams(AssetDatabaseInst.DB, nifFile, kfm, kfb);
            nif.setSkeletonRoot(nifmodel);
            return(nifmodel);
        }
Ejemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        Material transmat = Resources.Load("transmat", typeof(Material)) as Material;
        //Debug.Log(transmat.color);
        string file = @"D:\rift_stuff\nif\A_C_keep_stillmoor_south_entry_01.nif";

        GameObject obj = NIFLoader.loadNIFFromFile(file);

        obj.transform.parent = this.gameObject.transform;
    }
Ejemplo n.º 5
0
        static public GameObject loadNIF(long key)
        {
            Model       model    = load7305(AssetDatabaseInst.DB, key);
            GameObject  nifmodel = NIFLoader.loadNIF(model.nifFile, true);
            AnimatedNif nif      = nifmodel.AddComponent <AnimatedNif>();

            nif.setParams(AssetDatabaseInst.DB, model.nifFile, model.kfmFile, model.kfbFile);
            nif.setSkeletonRoot(nifmodel);
            return(nifmodel);
        }
Ejemplo n.º 6
0
    public void changeNif(string newNifP)
    {
        try
        {
            Debug.Log("Change nif:" + newNifP);
            string newNif = newNifP;
            if (newNifP.Contains(":"))
            {
                newNif = newNifP.Split(':')[1];
            }
            Model       animNifModel = nifDictionary[newNif];
            AnimatedNif animNif      = gameObject.GetComponent <AnimatedNif>();
            if (animNif == null)
            {
                animNif = gameObject.AddComponent <AnimatedNif>();
            }
            animNif.setParams(adb, animNifModel.nifFile, animNifModel.kfmFile, animNifModel.kfbFile);
            this.mount = animNifModel.mount;
            if (nifmodel != null)
            {
                GameObject.DestroyImmediate(nifmodel);
            }
            Debug.Log("load nif");

            nifmodel = NIFLoader.loadNIF(animNif.nif, true);
            nifmodel.transform.parent = root.transform;

            Debug.Log("set anims dropdown");
            this.animationDropdown.ClearOptions();
            List <String> anims = new List <String>();
            foreach (KFAnimation ani in animNif.getAnimations())
            {
                //Debug.Log("Found anim [" + ani.id + "]:" + ani.sequenceFilename + ":" + ani.sequencename );
                anims.Add(ani.sequencename);
            }
            anims.Sort();
            Debug.Log("set skel root");
            animNif.setSkeletonRoot(nifmodel);
            animationNif = animNif;
            Debug.Log("set active anim");
            animationNif.setActiveAnimation(animationNif.getIdleAnimIndex());

            this.animationDropdown.AddOptions(anims);
            Debug.Log("DONE Change nif:" + newNifP);
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
    }
Ejemplo n.º 7
0
    // Use this for initialization
    void Start()
    {
        GameObject go = NIFLoader.loadNIF("human_male_wings_016.nif");

        go.transform.parent = this.transform;

        /*
         * string x = "A_TNB_embassy_01.nif";
         *
         * go = load.loadNIF(x);
         * go.transform.parent = this.transform;
         *
         * x = "N_EC_tree_07.nif";
         * go = load.loadNIF(x);
         * go.transform.parent = this.transform;
         */
    }
Ejemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
        Debug.Log("start");
        // -batchMode
        if (Assets.ScreenshotData.hash == null || Assets.ScreenshotData.hash.Length == 0)
        {
            Assets.ScreenshotData.hash = Util.hashFileName("elf_male_cape_tempest.nif");
        }
        //string str = "elf_male_cape_tempest.nif";
        //str = "elf_male_cloth_helmet_119.nif";
        Debug.Log("Trying to loading NIF with hash: " + Assets.ScreenshotData.hash);
        go = NIFLoader.loadNIF(Assets.ScreenshotData.hash);
        Debug.Log("Done NIF load");

        go.transform.position = Vector3.zero;
        //go.transform.parent = this.transform;
        Debug.Log("done load");
    }
Ejemplo n.º 9
0
    // Use this for initialization
    void Start()
    {
        this.test = NIFLoader.loadNIF("elf_giant_unseelie_king.nif");
        GameObject character = new GameObject();

        /*
         * Paperdoll mainPaperdoll = character.AddComponent<Paperdoll>();
         *
         * mainPaperdoll.setGender("male");
         * mainPaperdoll.setRace("human");
         * //mainPaperdoll.GetComponent<AnimatedNif>().animSpeed = 0.001f;
         * mainPaperdoll.animSpeed = 0.005f;
         * character.transform.localPosition = new Vector3(0, 0, 0);
         * character.transform.localRotation = Quaternion.identity;
         * mainPaperdoll.transform.localRotation = Quaternion.identity;
         * //mainPaperdoll.setAppearenceSet(1044454339);
         * //mainPaperdoll.setGearSlotKey(GearSlot.CAPE, 2131680782);
         * //mainPaperdoll.setGearSlotKey(GearSlot.RANGED, 1072509202);
         * //mainPaperdoll.setKFBPostFix("ranged_bow");
         * //mainPaperdoll.clearGearSlot(GearSlot.HEAD);
         */
    }
Ejemplo n.º 10
0
    protected override void ThreadFunctionCDR()
    {
        // Do your threaded task. DON'T use the Unity API here

        count++;

        cacheWait[filename].WaitOne();

        lock (originals)
        {
            // if our cache contains an object, return it immediately
            if (originals.ContainsKey(filename))
            {
                return;
            }
        }
        try
        {
            niffile = NIFLoader.getNIF(filename, parent.cat);

            // extra check for terrain
            if (filename.Contains("_terrain_"))
            {
                string lodname = filename.Replace("_split", "_lod_split");
                try
                {
                    lodfile = NIFLoader.getNIF(lodname, parent.cat);
                }
                catch (Exception ex)
                {
                    Debug.Log("there was an exception while trying to load lod split:" + lodname + ": " + ex);
                }
            }
        }
        catch (Exception ex)
        {
            //Debug.Log("there was an exception while doing the thread:" + filename + ": " + ex);
        }
    }
Ejemplo n.º 11
0
    IEnumerator doWardrobe()
    {
        Debug.Log("process");

        List <ClothingItem> items = db.getClothing().ToList();

        Debug.Log("found " + items.Count + " original items to process");

        if (ExportModelData.langIDs.Count > 0)
        {
            Debug.Log("Found filter for " + ExportModelData.langIDs.Count + " items");
            items = items.Where(ci => ExportModelData.langIDs.Contains(ci.langKey)).ToList();
            Debug.Log("filtered to only " + items.Count + " items");
        }


        ecount    = 0;
        text.text = ecount + "/" + items.Count();

        foreach (ClothingItem item in items)
        {
            string appName = DBInst.lang_inst.get(item.langKey);
            string appKey  = "" + item.langKey;

            foreach (string racestr in WardrobeStuff.raceMap.Keys)
            {
                int race = WardrobeStuff.raceMap[racestr];

                foreach (string genderstr in WardrobeStuff.genderMap.Keys)
                {
                    try
                    {
                        int    gender  = WardrobeStuff.genderMap[genderstr];
                        string nifname = item.nifRef.getNif(race, gender);

                        string fname    = appKey + "_" + racestr + "_" + genderstr + "";
                        string itemName = appKey + "_" + racestr + "_" + genderstr + "";

                        List <string> additionalComments = new List <string>();
                        additionalComments.Add(nifname);
                        additionalComments.Add(appName);

                        if (go != null)
                        {
                            Destroy(go);
                        }
                        go = NIFLoader.loadNIF(Path.GetFileName(nifname));
                        NIFTexturePool.inst.process();
                        exporter.export(go, ExportModelData.outputDirectory, fname, additionalComments);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogWarning(ex.Message + ":" + ex.StackTrace);
                    }
                    yield return(new WaitForEndOfFrame());
                }
            }
            text.text = ecount++ + "/" + items.Count();
            //if (ecount > 20)
            //    yield break;
        }

        Debug.Log("quit, did " + ecount + " objects");
        // save any game data here
#if UNITY_EDITOR
        // Application.Quit() does not work in the editor so
        // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game
        UnityEditor.EditorApplication.isPlaying = false;
#else
        Application.Quit();
#endif

        /*
         *
         * ecount = 0;
         * using (StreamWriter sw = new StreamWriter(@"l:\rift\items_db.csv"))
         * {
         *  sw.WriteLine("db_id\tdb_key\thidden\tinternal name\ttext\tmaterial type\tvalid slots\ticon");
         *  foreach (ClothingItem item in items)
         *  {
         *      string slotsStr = String.Join(",", item.allowedSlots.Select(x => x.ToString()).ToArray());
         *      string iconStr = item.icon;
         *
         *      string output = String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}", new object[] { item.id, item.key, item.hidden ? "1" : "0", item.name,DBInst.lang_inst.get(item.langKey), item.type, slotsStr, iconStr }) ;
         *      sw.WriteLine(output );
         *      text.text = ecount++ + "/" + items.Count();
         *      yield return new WaitForEndOfFrame();
         *  }
         * }
         *
         *
         * using (StreamWriter sw = new StreamWriter(rootdir + "\\" + dir + "\\index"))
         * {
         *  index.ToList().ForEach(x => sw.WriteLine(x.Key + ":" + x.Value));
         * }
         */
        yield return(null);
    }
Ejemplo n.º 12
0
    protected override void OnFinished()
    {
        GameObject go = null;

        try
        {
            if (filename.Contains("_terrain_"))
            {
                TerrainObj tobj = parent.gameObject.GetComponent <TerrainObj>();
                if (tobj == null)
                {
                    parent.gameObject.AddComponent <TerrainObj>();
                }
                else
                {
                    tobj.enabled = true;
                }
            }
            count--;
            // This is executed by the Unity main thread when the job is finished
            if (niffile != null)
            {
                go = NIFLoader.loadNIF(niffile, filename);
                if (lodfile != null)
                {
                    GameObject lodgo = NIFLoader.loadNIF(lodfile, filename);

                    // terrain lod
                    LODGroup group = parent.gameObject.GetComponent <LODGroup>();
                    if (group == null)
                    {
                        group = parent.gameObject.AddComponent <LODGroup>();
                    }
                    group.enabled            = true;
                    group.animateCrossFading = true;
                    group.fadeMode           = LODFadeMode.SpeedTree;
                    LOD[]      lods         = new LOD[2];
                    Renderer[] renderersMax = go.GetComponentsInChildren <Renderer>();
                    Renderer[] renderersLow = lodgo.GetComponentsInChildren <Renderer>();
                    lods[0] = new LOD(0.6f, renderersMax);
                    lods[1] = new LOD(0.03f, renderersLow);
                    //lods[1] = new LOD(1f - LODCutoff, renderers);
                    group.SetLODs(lods);

                    GameObject lodObj = new GameObject();
                    lodObj.name = "LOD-" + filename;
                    lodgo.transform.SetParent(lodObj.transform);
                    lodObj.transform.SetParent(go.transform);
                }

                lock (originals)
                {
                    originals[filename] = go;
                }
            }
            else
            {
                go = getCachedObject(filename);
            }

            if (go != null)
            {
                if (Assets.GameWorld.useColliders)
                {
                    GameObject.Destroy(parent.GetComponent <BoxCollider>());
                    GameObject.Destroy(parent.GetComponent <SphereCollider>());
                }
                go.transform.SetParent(parent.transform);
                go.transform.localScale    = Vector3.one;
                go.transform.localPosition = Vector3.zero;
                go.transform.localRotation = Quaternion.identity;

                if (parent.gameObject.GetComponent <LODGroup>() != null)
                {
                    parent.gameObject.GetComponent <LODGroup>().RecalculateBounds();
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogWarning("Unable to load nif:" + niffile + " " + filename);
            Debug.Log(ex);
            if (null != go)
            {
                GameObject.Destroy(go);
            }
        }
        finally
        {
            if (cacheWait.ContainsKey(filename))
            {
                cacheWait[filename].Release();
            }
        }
    }
Ejemplo n.º 13
0
        private void updateRaceGender()
        {
            if (state != ClassState.UPDATE)
            {
                Debug.LogError("Cannot update race/gender without being update mode");
                return;
            }


            if (refModel != null)
            {
                GameObject.Destroy(refModel);
            }
            if (costumeParts != null)
            {
                GameObject.Destroy(costumeParts);
            }

            // defines the base model
            string nif = string.Format("{0}_refbare.nif", getBaseModel());
            string kfm = string.Format("{0}.kfm", getBaseModel());
            string kfb = string.Format("{0}.kfb", getKFBBase());

            if (!"".Equals(kfbOverride))
            {
                kfb = kfbOverride;
            }


            animationNif = this.gameObject.GetComponent <AnimatedNif>();
            if (animationNif == null)
            {
                animationNif = this.gameObject.AddComponent <AnimatedNif>();
            }
            animationNif.setParams(AssetDatabaseInst.DB, nif, kfm, kfb);

            NIFFile    file = NIFLoader.getNIF(nif);
            GameObject go   = NIFLoader.loadNIF(file, nif, true);

            go.transform.parent        = this.transform;
            go.transform.localPosition = Vector3.zero;
            go.transform.localRotation = Quaternion.identity;
            refModel = go;


            if (!"".Equals(animOverride))
            {
                animationNif.setActiveAnimation(animOverride);
            }
            else
            {
                string animation = string.Format("{0}_{1}_idle", getBaseModel(), getAnimationSet());
                try
                {
                    animationNif.setActiveAnimation(animation);
                }
                catch (Exception ex)
                {
                    Debug.LogError("Unable to load animation:" + animation);
                }
            }
            animationNif.setSkeletonRoot(refModel);

            costumeParts = new GameObject("CostumeParts");
            costumeParts.transform.parent = refModel.transform;
        }