public void CreateData(DFBlock.RmbBlock3dObjectRecord data, bool isExterior) { HideComponents(); type = DataType.Object3D; this.isExterior = isExterior; id = data.ModelId; objectType = data.ObjectType; }
private void AddFurnitureAction(DFBlock.RmbBlock3dObjectRecord obj, GameObject go, PlayerGPS.DiscoveredBuilding buildingData) { // Create unique LoadID for save system, using 9 lsb and the sign bit from each coord pos int ulong loadID = ((ulong)buildingData.buildingKey) << 30 | (uint)(obj.XPos << 1 & posMask) << 20 | (uint)(obj.YPos << 1 & posMask) << 10 | (uint)(obj.ZPos << 1 & posMask); DFLocation.BuildingTypes buildingType = buildingData.buildingType; // Handle shelves: if (shopShelvesObjectGroupIndices.Contains(obj.ModelIdNum - containerObjectGroupOffset)) { if (RMBLayout.IsShop(buildingType)) { // Shop shelves, so add a DaggerfallLoot component DaggerfallLoot loot = go.AddComponent <DaggerfallLoot>(); if (loot) { // Set as shelves, assign load id and create serialization object loot.ContainerType = LootContainerTypes.ShopShelves; loot.ContainerImage = InventoryContainerImages.Shelves; loot.LoadID = loadID; if (SaveLoadManager.Instance != null) { go.AddComponent <SerializableLootContainer>(); } } } else if (buildingType == DFLocation.BuildingTypes.Library || buildingType == DFLocation.BuildingTypes.GuildHall || buildingType == DFLocation.BuildingTypes.Temple) { // Bookshelves, add DaggerfallBookshelf component go.AddComponent <DaggerfallBookshelf>(); } else if (DaggerfallBankManager.IsHouseOwned(buildingData.buildingKey)) { // Player owned house, everything is a house container MakeHouseContainer(obj, go, loadID); } } // Handle generic furniture as (private) house containers: // (e.g. shelves, boxes, wardrobes, drawers etc) else if (obj.ModelIdNum / 100 == houseContainerObjectGroup || houseContainerObjectGroupIndices.Contains(obj.ModelIdNum - containerObjectGroupOffset)) { MakeHouseContainer(obj, go, loadID); } }
private static void MakeHouseContainer(DFBlock.RmbBlock3dObjectRecord obj, GameObject go, ulong loadID) { DaggerfallLoot loot = go.AddComponent <DaggerfallLoot>(); if (loot) { // Set as house container (private furniture) and assign load id loot.ContainerType = LootContainerTypes.HouseContainers; loot.ContainerImage = InventoryContainerImages.Shelves; loot.LoadID = loadID; loot.TextureRecord = (int)obj.ModelIdNum % 100; if (SaveLoadManager.Instance != null) { go.AddComponent <SerializableLootContainer>(); } } }
/// <summary> /// Gets the model scale vector, converting zeros to 1s if needed. /// </summary> /// <param name="obj">RmbBlock3dObjectRecord structure</param> /// <returns>Vector3 with the scaling factors</returns> public static Vector3 GetModelScaleVector(DFBlock.RmbBlock3dObjectRecord obj) { return(new Vector3(obj.XScale == 0 ? 1 : obj.XScale, obj.YScale == 0 ? 1 : obj.YScale, obj.ZScale == 0 ? 1 : obj.YScale)); }
public static GameObject Add3dObject(DFBlock.RmbBlock3dObjectRecord rmbBlock) { DaggerfallUnity dfUnity = DaggerfallUnity.Instance; // Get model data ModelData modelData; dfUnity.MeshReader.GetModelData(rmbBlock.ModelIdNum, out modelData); // Get model position by type (3 seems to indicate props/clutter) // Also stop these from being combined as some may carry a loot container Vector3 modelPosition; if (rmbBlock.ObjectType == (int)InteractiveObject) { // Props axis needs to be transformed to lowest Y point Vector3 bottom = modelData.Vertices[0]; for (int i = 0; i < modelData.Vertices.Length; i++) { if (modelData.Vertices[i].y < bottom.y) { bottom = modelData.Vertices[i]; } } modelPosition = new Vector3(rmbBlock.XPos, rmbBlock.YPos, rmbBlock.ZPos) * MeshReader.GlobalScale; modelPosition += new Vector3(0, -bottom.y, 0); } else { modelPosition = new Vector3(rmbBlock.XPos, -rmbBlock.YPos, rmbBlock.ZPos) * MeshReader.GlobalScale; } // Fix 3D models with 0,0,0 scale if (rmbBlock.XScale == 0) { rmbBlock.XScale = 1; } if (rmbBlock.YScale == 0) { rmbBlock.YScale = 1; } if (rmbBlock.ZScale == 0) { rmbBlock.ZScale = 1; } // Get model transform Vector3 modelRotation = new Vector3(-rmbBlock.XRotation / BlocksFile.RotationDivisor, -rmbBlock.YRotation / BlocksFile.RotationDivisor, -rmbBlock.ZRotation / BlocksFile.RotationDivisor); Vector3 modelScale = new Vector3(rmbBlock.XScale, rmbBlock.YScale, rmbBlock.ZScale); Matrix4x4 modelMatrix = Matrix4x4.TRS(modelPosition, Quaternion.Euler(modelRotation), modelScale); // Inject custom GameObject if available GameObject modelGO = MeshReplacement.ImportCustomGameobject(rmbBlock.ModelIdNum, null, modelMatrix); if (modelGO == null) { if (modelData.DFMesh.TotalVertices != 0) { modelGO = DaggerfallWorkshop.Utility.GameObjectHelper.CreateDaggerfallMeshGameObject(rmbBlock.ModelIdNum, null); modelGO.transform.position = modelMatrix.GetColumn(3); modelGO.transform.rotation = modelMatrix.rotation; modelGO.transform.localScale = modelMatrix.lossyScale; } else { Debug.LogError("Custom model not found for modelId " + rmbBlock.ModelIdNum); } } return(modelGO); }