private static GameObject AddStandaloneModel( DaggerfallUnity dfUnity, ref ModelData modelData, Matrix4x4 matrix, Transform parent) { uint modelID = (uint)modelData.DFMesh.ObjectId; // Add GameObject GameObject go = GameObjectHelper.CreateDaggerfallMeshGameObject(modelID, parent, dfUnity.Option_SetStaticFlags); go.transform.position = matrix.GetColumn(3); go.transform.rotation = matrix.rotation; go.transform.localScale = matrix.lossyScale; // Is this a city gate? if (IsCityGate(modelID)) { go.AddComponent <DaggerfallCityGate>(); } // Is this a bulletin board? if (IsBulletinBoard(modelID)) { go.AddComponent <DaggerfallBulletinBoard>(); } return(go); }
/// <summary> /// Adds action door to scene. /// </summary> private static GameObject AddActionDoor(DaggerfallUnity dfUnity, uint modelId, DFBlock.RdbObject obj, Transform parent, long loadID = 0) { if (dfUnity.Option_DungeonDoorPrefab == null) { return(null); } // Get model data and matrix ModelData modelData; dfUnity.MeshReader.GetModelData(modelId, out modelData); Matrix4x4 modelMatrix = GetModelMatrix(obj); // Instantiate door prefab and add model GameObject go = GameObjectHelper.InstantiatePrefab(dfUnity.Option_DungeonDoorPrefab.gameObject, string.Empty, parent, Vector3.zero); GameObjectHelper.CreateDaggerfallMeshGameObject(modelId, parent, false, go, true); // Resize box collider to new mesh bounds BoxCollider boxCollider = go.GetComponent <BoxCollider>(); MeshRenderer meshRenderer = go.GetComponent <MeshRenderer>(); if (boxCollider != null && meshRenderer != null) { boxCollider.center = meshRenderer.bounds.center; boxCollider.size = meshRenderer.bounds.size; } // Get rotation angle for each axis float degreesX = -obj.Resources.ModelResource.XRotation / BlocksFile.RotationDivisor; float degreesY = -obj.Resources.ModelResource.YRotation / BlocksFile.RotationDivisor; float degreesZ = -obj.Resources.ModelResource.ZRotation / BlocksFile.RotationDivisor; // Apply transforms go.transform.Rotate(0, degreesY, 0, Space.World); go.transform.Rotate(degreesX, 0, 0, Space.World); go.transform.Rotate(0, 0, degreesZ, Space.World); go.transform.localPosition = modelMatrix.GetColumn(3); // Get action door script DaggerfallActionDoor actionDoor = go.GetComponent <DaggerfallActionDoor>(); // Set starting lock value if (obj.Resources.ModelResource.TriggerFlag_StartingLock >= 16) { actionDoor.StartingLockValue = (int)obj.Resources.ModelResource.TriggerFlag_StartingLock; } // Set LoadID actionDoor.LoadID = loadID; return(go); }
/// <summary> /// Add a standalone model when not combining. /// </summary> private static GameObject AddStandaloneModel( DaggerfallUnity dfUnity, ref ModelData modelData, Matrix4x4 matrix, Transform parent, bool overrideStatic = false, bool ignoreCollider = false) { // Determine static flag bool isStatic = (dfUnity.Option_SetStaticFlags && !overrideStatic) ? true : false; // Add GameObject uint modelID = (uint)modelData.DFMesh.ObjectId; GameObject go = GameObjectHelper.CreateDaggerfallMeshGameObject(modelID, parent, isStatic, null, ignoreCollider); go.transform.position = matrix.GetColumn(3); go.transform.rotation = GameObjectHelper.QuaternionFromMatrix(matrix); return(go); }
private static GameObject AddStandaloneModel( DaggerfallUnity dfUnity, ref ModelData modelData, Matrix4x4 matrix, Transform parent) { uint modelID = (uint)modelData.DFMesh.ObjectId; // Add GameObject GameObject go = GameObjectHelper.CreateDaggerfallMeshGameObject(modelID, parent, dfUnity.Option_SetStaticFlags); go.transform.position = matrix.GetColumn(3); go.transform.rotation = GameObjectHelper.QuaternionFromMatrix(matrix); // Is this a city gate? if (IsCityGate(modelID)) { go.AddComponent <DaggerfallCityGate>(); } return(go); }
private void AddRDBModel(DFBlock.RdbObject obj, out List <StaticDoor> doorsOut, Transform parent) { bool overrideCombine = false; doorsOut = new List <StaticDoor>(); // Get model reference index and id int modelReference = obj.Resources.ModelResource.ModelIndex; uint modelId = blockData.RdbBlock.ModelReferenceList[modelReference].ModelIdNum; // Get rotation angle for each axis float degreesX = -obj.Resources.ModelResource.XRotation / BlocksFile.RotationDivisor; float degreesY = -obj.Resources.ModelResource.YRotation / BlocksFile.RotationDivisor; float degreesZ = -obj.Resources.ModelResource.ZRotation / BlocksFile.RotationDivisor; // Calcuate transform Vector3 position = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale; // Calculate matrix Vector3 rx = new Vector3(degreesX, 0, 0); Vector3 ry = new Vector3(0, degreesY, 0); Vector3 rz = new Vector3(0, 0, degreesZ); Matrix4x4 modelMatrix = Matrix4x4.identity; modelMatrix *= Matrix4x4.TRS(position, Quaternion.identity, Vector3.one); modelMatrix *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(rz), Vector3.one); modelMatrix *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(rx), Vector3.one); modelMatrix *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(ry), Vector3.one); // Get model data ModelData modelData; dfUnity.MeshReader.GetModelData(modelId, out modelData); // Discard static exit doors not in starting block // Exit doors are just a model slapped over wall or doorway // This allows Daggerfall to toggle exits on and off if (modelData.DFMesh.ObjectId == 70300) { if (!isStartingBlock) { return; } } // Doors - there are no working static building doors inside dungeons, just the exits and action doors bool isActionDoor = IsActionDoor(blockData, obj, modelReference); if (isActionDoor) { parent = doorsNode.transform; } else if (modelData.Doors != null) { doorsOut.AddRange(GameObjectHelper.GetStaticDoors(ref modelData, blockData.Index, 0, modelMatrix)); } // Action records bool hasAction = HasAction(blockData, obj, modelReference); if (hasAction) { parent = actionModelsNode.transform; } // Flags bool isStatic = dfUnity.Option_SetStaticFlags; if (isActionDoor || hasAction) { // Moving objects are never static or combined isStatic = false; overrideCombine = true; } // Add to scene if (dfUnity.Option_CombineRDB && !overrideCombine) { combiner.Add(ref modelData, modelMatrix); } else { // Spawn mesh gameobject GameObject go = GameObjectHelper.CreateDaggerfallMeshGameObject(modelId, parent, isStatic); go.GetComponent <DaggerfallMesh>().SetDungeonTextures(textureTable); // Apply transforms go.transform.Rotate(0, degreesY, 0, Space.World); go.transform.Rotate(degreesX, 0, 0, Space.World); go.transform.Rotate(0, 0, degreesZ, Space.World); go.transform.localPosition = position; // Add action door if (isActionDoor) { DaggerfallActionDoor dfActionDoor = go.AddComponent <DaggerfallActionDoor>(); // Add action door audio if (dfUnity.Option_DefaultSounds) { AddActionDoorAudioSource(go); dfActionDoor.SetDungeonDoorSounds(); } } // Add action component if (hasAction && !isActionDoor) { AddAction(go, blockData, obj, modelReference); } } }