/** 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); }
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); }
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); } }
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; }