RefCellObjInfo[] GetRefCellObjInfos(CELLRecord cell) { var refCellObjInfos = new RefCellObjInfo[cell.RefObjs.Length]; for (var i = 0; i < cell.RefObjs.Length; i++) { var refObjInfo = new RefCellObjInfo { RefObj = cell.RefObjs[i] }; // Get the record the RefObjDataGroup references. var refObj = (CELLRecord.RefObj)refObjInfo.RefObj; _data.objectsByIDString.TryGetValue(refObj.Name, out refObjInfo.ReferencedRecord); if (refObjInfo.ReferencedRecord != null) { var modelFileName = RecordUtils.GetModelFileName(refObjInfo.ReferencedRecord); // If the model file name is valid, store the model file path. if (!string.IsNullOrEmpty(modelFileName)) { refObjInfo.ModelFilePath = modelFileName; } } refCellObjInfos[i] = refObjInfo; } return(refCellObjInfos); }
RefCellObjInfo[] GetRefCellObjInfos(CELLRecord cell) { if (_data.Format != GameFormatId.TES3) { return(new RefCellObjInfo[0]); } var refCellObjInfos = new RefCellObjInfo[cell.RefObjs.Count]; for (var i = 0; i < cell.RefObjs.Count; i++) { var refObjInfo = new RefCellObjInfo { RefObj = cell.RefObjs[i] }; // Get the record the RefObjDataGroup references. var refObj = (CELLRecord.RefObj)refObjInfo.RefObj; _data._MANYsById.TryGetValue(refObj.EDID.Value, out refObjInfo.ReferencedRecord); if (refObjInfo.ReferencedRecord != null) { var modelFileName = (refObjInfo.ReferencedRecord is IHaveMODL modl ? modl.MODL.Value : null); // If the model file name is valid, store the model file path. if (!string.IsNullOrEmpty(modelFileName)) { refObjInfo.ModelFilePath = "meshes\\" + modelFileName; } } refCellObjInfos[i] = refObjInfo; } return(refCellObjInfos); }
/// <summary> /// Instantiates an object in a cell. Called by InstantiateCellObjectsCoroutine after the object's assets have been pre-loaded. /// </summary> void InstantiateCellObject(CELLRecord cell, GameObject parent, RefCellObjInfo refCellObjInfo) { if (refCellObjInfo.ReferencedRecord != null) { GameObject modelObj = null; // If the object has a model, instantiate it. if (refCellObjInfo.ModelFilePath != null) { modelObj = _asset.CreateObject(refCellObjInfo.ModelFilePath); PostProcessInstantiatedCellObject(modelObj, refCellObjInfo); modelObj.transform.parent = parent.transform; } // If the object has a light, instantiate it. if (refCellObjInfo.ReferencedRecord is LIGHRecord) { var lightObj = InstantiateLight((LIGHRecord)refCellObjInfo.ReferencedRecord, cell.IsInterior); // If the object also has a model, parent the model to the light. if (modelObj != null) { // Some SIF files have nodes named "AttachLight". Parent it to the light if it exists. var attachLightObj = GameObjectUtils.FindChildRecursively(modelObj, "AttachLight"); if (attachLightObj == null) { //attachLightObj = GameObjectUtils.FindChildWithNameSubstringRecursively(modelObj, "Emitter"); attachLightObj = modelObj; } if (attachLightObj != null) { lightObj.transform.position = attachLightObj.transform.position; lightObj.transform.rotation = attachLightObj.transform.rotation; lightObj.transform.parent = attachLightObj.transform; } else // If there is no "AttachLight", center the light in the model's bounds. { lightObj.transform.position = GameObjectUtils.CalcVisualBoundsRecursive(modelObj).center; lightObj.transform.rotation = modelObj.transform.rotation; lightObj.transform.parent = modelObj.transform; } } else // If the light has no associated model, instantiate the light as a standalone object. { PostProcessInstantiatedCellObject(lightObj, refCellObjInfo); lightObj.transform.parent = parent.transform; } } } else { Utils.Log("Unknown Object: " + ((CELLRecord.RefObj)refCellObjInfo.RefObj).Name); } }
void ProcessObjectType <RecordType>(GameObject gameObject, RefCellObjInfo info, string tag) where RecordType : Record { var record = info.ReferencedRecord; if (record is RecordType) { var obj = GameObjectUtils.FindTopLevelObject(gameObject); if (obj == null) { return; } //var component = GenericObjectComponent.Create(obj, record, tag); ////only door records need access to the cell object data group so far //if (record is DOORRecord) // ((DoorComponent)component).RefObj = info.RefObj; } }
//const bool RenderLightShadows = false; //const bool RenderExteriorCellLights = false; //GameObject InstantiateLight(LIGHRecord LIGH, bool indoors) //{ // var lightObj = new GameObject("Light") { isStatic = true }; // var lightComponent = lightObj.AddComponent<Light>(); // lightComponent.range = 3 * (LIGH.DATA.Radius / ConvertUtils.MeterInUnits); // lightComponent.color = LIGH.DATA.LightColor.ToColor32(); // lightComponent.intensity = 1.5f; // lightComponent.bounceIntensity = 0f; // lightComponent.shadows = RenderLightShadows ? LightShadows.Soft : LightShadows.None; // if (!indoors && !RenderExteriorCellLights) // disabling exterior cell lights because there is no day/night cycle // lightComponent.enabled = false; // return lightObj; //} /// <summary> /// Finishes initializing an instantiated cell object. /// </summary> void PostProcessInstantiatedCellObject(GameObject gameObject, RefCellObjInfo refCellObjInfo) { var refObj = (CELLRecord.FixedObject)refCellObjInfo.RefObj; // Handle object transforms. //if (refObj.XSCL != null) // gameObject.transform.localScale = Vector3.one * refObj.XSCL.Value.Value; //gameObject.transform.position += refObj.DATA.Position.ToVector3().ToUnityVector(ConvertUtils.MeterInUnits); //gameObject.transform.rotation *= refObj.DATA.EulerAngles.ToVector3().ToUnityQuaternionAsEulerAngles(); 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 <BOOKRecord>(tagTarget, refCellObjInfo, "Book"); }
/// <summary> /// Finishes initializing an instantiated cell object. /// </summary> void PostProcessInstantiatedCellObject(GameObject gameObject, RefCellObjInfo refCellObjInfo) { var refObj = (CELLRecord.RefObj)refCellObjInfo.RefObj; // Handle object transforms. if (refObj.Scale != null) { gameObject.transform.localScale = Vector3.one * refObj.Scale.Value; } gameObject.transform.position += SifUtils.SifPointToUnityPoint(refObj.Position); gameObject.transform.rotation *= SifUtils.SifEulerAnglesToUnityQuaternion(refObj.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"); }