From 9f686ff776e043fe9dc5fcdef2c5c9ce27dd790e Mon Sep 17 00:00:00 2001 From: Brent Date: Sun, 21 Mar 2021 21:17:24 +0100 Subject: [PATCH] parts correctly get imported + spawned + fun physics --- Assets/Materials/BaseMaterial.mat | 4 +- Assets/Prefabs/Block.prefab | 20 + Assets/Prefabs/Part.prefab | 20 + Assets/Scenes/BlueprintTool.unity | 474 ++++++++++++++++++ .../Model/BlueprintObject/ChildObject.cs | 52 +- Assets/Scripts/Model/Shapes/Part.cs | 12 +- 6 files changed, 554 insertions(+), 28 deletions(-) diff --git a/Assets/Materials/BaseMaterial.mat b/Assets/Materials/BaseMaterial.mat index 22855ac..640b56b 100644 --- a/Assets/Materials/BaseMaterial.mat +++ b/Assets/Materials/BaseMaterial.mat @@ -58,7 +58,7 @@ Material: m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MainTex: - m_Texture: {fileID: 2800000, guid: a2a673540e2add34aaeaad3eccc6751b, type: 3} + m_Texture: {fileID: 2800000, guid: 3b33200601e49e54a8bca970fba69095, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MetallicGlossMap: @@ -101,6 +101,6 @@ Material: - _ZWrite: 1 m_Colors: - _BaseColor: {r: 1, g: 1, b: 1, a: 1} - - _Color: {r: 0.8745098, g: 0.4392157, b: 0, a: 1} + - _Color: {r: 0.6792453, g: 0.6792453, b: 0.6792453, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} diff --git a/Assets/Prefabs/Block.prefab b/Assets/Prefabs/Block.prefab index 11e4cc6..32cf5d4 100644 --- a/Assets/Prefabs/Block.prefab +++ b/Assets/Prefabs/Block.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 3296844404341013989} - component: {fileID: 3315036787694123639} - component: {fileID: -2448772888131062009} + - component: {fileID: 8889252761515623799} m_Layer: 0 m_Name: Block m_TagString: Untagged @@ -57,3 +58,22 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ab5c7186164c93c4eaed77274c54cd45, type: 3} m_Name: m_EditorClassIdentifier: + rotatedBounds: {x: 0, y: 0, z: 0} + xaxis: 0 + zaxis: 0 +--- !u!54 &8889252761515623799 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4996030810628450848} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: 0.05 + m_UseGravity: 1 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 0 + m_CollisionDetection: 0 diff --git a/Assets/Prefabs/Part.prefab b/Assets/Prefabs/Part.prefab index f9ea9a6..daf9340 100644 --- a/Assets/Prefabs/Part.prefab +++ b/Assets/Prefabs/Part.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 118241074730888341} - component: {fileID: 2886457616414624878} - component: {fileID: 1442691639726730038} + - component: {fileID: 5155092793444328200} m_Layer: 0 m_Name: Part m_TagString: Untagged @@ -57,3 +58,22 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ab5c7186164c93c4eaed77274c54cd45, type: 3} m_Name: m_EditorClassIdentifier: + rotatedBounds: {x: 0, y: 0, z: 0} + xaxis: 0 + zaxis: 0 +--- !u!54 &5155092793444328200 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5642423716957298321} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: 0.05 + m_UseGravity: 1 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 0 + m_CollisionDetection: 0 diff --git a/Assets/Scenes/BlueprintTool.unity b/Assets/Scenes/BlueprintTool.unity index 42e1e52..8b6deaf 100644 --- a/Assets/Scenes/BlueprintTool.unity +++ b/Assets/Scenes/BlueprintTool.unity @@ -1704,6 +1704,317 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1106181005} m_CullTransparentMesh: 0 +--- !u!1 &1132051712 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1132051717} + - component: {fileID: 1132051716} + - component: {fileID: 1132051715} + - component: {fileID: 1132051714} + - component: {fileID: 1132051713} + m_Layer: 0 + m_Name: Cube + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!64 &1132051713 +MeshCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1132051712} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 4 + m_Convex: 0 + m_CookingOptions: 30 + m_Mesh: {fileID: 1264523185} +--- !u!33 &1132051714 +MeshFilter: + m_ObjectHideFlags: 10 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1132051712} + m_Mesh: {fileID: 1264523185} +--- !u!23 &1132051715 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1132051712} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 25a9fb42d361f46ad89221f6d301e96e, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 2 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!114 &1132051716 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1132051712} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8233d90336aea43098adf6dbabd606a2, type: 3} + m_Name: + m_EditorClassIdentifier: + m_MeshFormatVersion: 1 + m_Faces: + - m_Indexes: 000000000100000002000000010000000300000002000000 + m_SmoothingGroup: 0 + m_Uv: + m_UseWorldSpace: 0 + m_FlipU: 0 + m_FlipV: 0 + m_SwapUV: 0 + m_Fill: 1 + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Rotation: 0 + m_Anchor: 9 + m_Material: {fileID: 0} + m_SubmeshIndex: 0 + m_ManualUV: 0 + elementGroup: -1 + m_TextureGroup: -1 + - m_Indexes: 040000000500000006000000050000000700000006000000 + m_SmoothingGroup: 0 + m_Uv: + m_UseWorldSpace: 0 + m_FlipU: 0 + m_FlipV: 0 + m_SwapUV: 0 + m_Fill: 1 + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Rotation: 0 + m_Anchor: 9 + m_Material: {fileID: 0} + m_SubmeshIndex: 0 + m_ManualUV: 0 + elementGroup: -1 + m_TextureGroup: -1 + - m_Indexes: 08000000090000000a000000090000000b0000000a000000 + m_SmoothingGroup: 0 + m_Uv: + m_UseWorldSpace: 0 + m_FlipU: 0 + m_FlipV: 0 + m_SwapUV: 0 + m_Fill: 1 + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Rotation: 0 + m_Anchor: 9 + m_Material: {fileID: 0} + m_SubmeshIndex: 0 + m_ManualUV: 0 + elementGroup: -1 + m_TextureGroup: -1 + - m_Indexes: 0c0000000d0000000e0000000d0000000f0000000e000000 + m_SmoothingGroup: 0 + m_Uv: + m_UseWorldSpace: 0 + m_FlipU: 0 + m_FlipV: 0 + m_SwapUV: 0 + m_Fill: 1 + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Rotation: 0 + m_Anchor: 9 + m_Material: {fileID: 0} + m_SubmeshIndex: 0 + m_ManualUV: 0 + elementGroup: -1 + m_TextureGroup: -1 + - m_Indexes: 100000001100000012000000110000001300000012000000 + m_SmoothingGroup: 0 + m_Uv: + m_UseWorldSpace: 0 + m_FlipU: 0 + m_FlipV: 0 + m_SwapUV: 0 + m_Fill: 1 + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Rotation: 0 + m_Anchor: 9 + m_Material: {fileID: 0} + m_SubmeshIndex: 0 + m_ManualUV: 0 + elementGroup: -1 + m_TextureGroup: -1 + - m_Indexes: 140000001500000016000000150000001700000016000000 + m_SmoothingGroup: 0 + m_Uv: + m_UseWorldSpace: 0 + m_FlipU: 0 + m_FlipV: 0 + m_SwapUV: 0 + m_Fill: 1 + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Rotation: 0 + m_Anchor: 9 + m_Material: {fileID: 0} + m_SubmeshIndex: 0 + m_ManualUV: 0 + elementGroup: -1 + m_TextureGroup: -1 + m_SharedVertices: + - m_Vertices: 000000000d00000016000000 + - m_Vertices: 010000000400000017000000 + - m_Vertices: 020000000f00000010000000 + - m_Vertices: 030000000600000011000000 + - m_Vertices: 050000000800000015000000 + - m_Vertices: 070000000a00000013000000 + - m_Vertices: 090000000c00000014000000 + - m_Vertices: 0b0000000e00000012000000 + m_SharedTextures: [] + m_Positions: + - {x: -181.52003, y: 0, z: 81.3829} + - {x: 310.75983, y: 0, z: 81.382904} + - {x: -181.52003, y: 1, z: 81.3829} + - {x: 310.75983, y: 1, z: 81.382904} + - {x: 310.75983, y: 0, z: 81.382904} + - {x: 310.75983, y: 0, z: -416.66754} + - {x: 310.75983, y: 1, z: 81.382904} + - {x: 310.75983, y: 1, z: -416.66754} + - {x: 310.75983, y: 0, z: -416.66754} + - {x: -181.52003, y: 0, z: -416.66754} + - {x: 310.75983, y: 1, z: -416.66754} + - {x: -181.52003, y: 1, z: -416.66754} + - {x: -181.52003, y: 0, z: -416.66754} + - {x: -181.52003, y: 0, z: 81.3829} + - {x: -181.52003, y: 1, z: -416.66754} + - {x: -181.52003, y: 1, z: 81.3829} + - {x: -181.52003, y: 1, z: 81.3829} + - {x: 310.75983, y: 1, z: 81.382904} + - {x: -181.52003, y: 1, z: -416.66754} + - {x: 310.75983, y: 1, z: -416.66754} + - {x: -181.52003, y: 0, z: -416.66754} + - {x: 310.75983, y: 0, z: -416.66754} + - {x: -181.52003, y: 0, z: 81.3829} + - {x: 310.75983, y: 0, z: 81.382904} + m_Textures0: + - {x: 181.52003, y: 0} + - {x: -310.75983, y: 0} + - {x: 181.52003, y: 1} + - {x: -310.75983, y: 1} + - {x: 81.382904, y: 0} + - {x: -416.66754, y: 0} + - {x: 81.382904, y: 1} + - {x: -416.66754, y: 1} + - {x: 310.75983, y: 0} + - {x: -181.52003, y: 0} + - {x: 310.75983, y: 1} + - {x: -181.52003, y: 1} + - {x: 416.66754, y: 0} + - {x: -81.3829, y: 0} + - {x: 416.66754, y: 1} + - {x: -81.3829, y: 1} + - {x: -181.52003, y: 81.3829} + - {x: 310.75983, y: 81.382904} + - {x: -181.52003, y: -416.66754} + - {x: 310.75983, y: -416.66754} + - {x: 181.52003, y: -416.66754} + - {x: -310.75983, y: -416.66754} + - {x: 181.52003, y: 81.3829} + - {x: -310.75983, y: 81.382904} + m_Textures2: [] + m_Textures3: [] + m_Tangents: + - {x: -1, y: 0, z: -0.000000015498085, w: -1} + - {x: -1, y: 0, z: -0.000000015498085, w: -1} + - {x: -1, y: 0, z: -0.000000015498085, w: -1} + - {x: -1, y: 0, z: -0.000000015498085, w: -1} + - {x: 0, y: 0, z: 1, w: -1} + - {x: 0, y: 0, z: 1, w: -1} + - {x: 0, y: 0, z: 1, w: -1} + - {x: 0, y: 0, z: 1, w: -1} + - {x: 1, y: 0, z: 0, w: -1} + - {x: 1, y: 0, z: 0, w: -1} + - {x: 1, y: 0, z: 0, w: -1} + - {x: 1, y: 0, z: 0, w: -1} + - {x: 0, y: 0, z: -1, w: -1} + - {x: 0, y: 0, z: -1, w: -1} + - {x: 0, y: 0, z: -1, w: -1} + - {x: 0, y: 0, z: -1, w: -1} + - {x: 1, y: 0, z: 0, w: -1} + - {x: 1, y: 0, z: 0, w: -1} + - {x: 1, y: 0, z: 0, w: -1} + - {x: 1, y: 0, z: 0, w: -1} + - {x: -1, y: 0, z: 0, w: -1} + - {x: -1, y: 0, z: 0, w: -1} + - {x: -1, y: 0, z: 0, w: -1} + - {x: -1, y: 0, z: 0, w: -1} + m_Colors: [] + m_UnwrapParameters: + m_HardAngle: 88 + m_PackMargin: 20 + m_AngleError: 8 + m_AreaError: 15 + m_PreserveMeshAssetOnDestroy: 0 + assetGuid: + m_Mesh: {fileID: 1264523185} + m_IsSelectable: 1 + m_SelectedFaces: + m_SelectedEdges: [] + m_SelectedVertices: +--- !u!4 &1132051717 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1132051712} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -64.29, y: -20, z: 167.69} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 7 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1249960633 GameObject: m_ObjectHideFlags: 0 @@ -1858,6 +2169,169 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1249960633} m_CullTransparentMesh: 0 +--- !u!43 &1264523185 +Mesh: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: pb_Mesh-1415626 + serializedVersion: 10 + m_SubMeshes: + - serializedVersion: 2 + firstByte: 0 + indexCount: 36 + topology: 0 + baseVertex: 0 + firstVertex: 0 + vertexCount: 24 + localAABB: + m_Center: {x: 64.619896, y: 0.5, z: -167.64232} + m_Extent: {x: 246.13992, y: 0.5, z: 249.02522} + m_Shapes: + vertices: [] + shapes: [] + channels: [] + fullWeights: [] + m_BindPose: [] + m_BoneNameHashes: + m_RootBoneNameHash: 0 + m_BonesAABB: [] + m_VariableBoneCountWeights: + m_Data: + m_MeshCompression: 0 + m_IsReadable: 1 + m_KeepVertices: 1 + m_KeepIndices: 1 + m_IndexFormat: 0 + m_IndexBuffer: 000001000200010003000200040005000600050007000600080009000a0009000b000a000c000d000e000d000f000e00100011001200110013001200140015001600150017001600 + m_VertexData: + serializedVersion: 3 + m_VertexCount: 24 + m_Channels: + - stream: 0 + offset: 0 + format: 0 + dimension: 3 + - stream: 0 + offset: 12 + format: 0 + dimension: 3 + - stream: 0 + offset: 24 + format: 0 + dimension: 4 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 40 + format: 0 + dimension: 2 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + m_DataSize: 1152 + _typelessdata: 218535c3000000000bc4a242a62085b2000000000000803f000080bf00000000a62085b2000080bf218535430000000042619b43000000000cc4a242a62085b2000000000000803f000080bf00000000a62085b2000080bf42619bc300000000218535c30000803f0bc4a242a62085b2000000000000803f000080bf00000000a62085b2000080bf218535430000803f42619b430000803f0cc4a242a62085b2000000000000803f000080bf00000000a62085b2000080bf42619bc30000803f42619b43000000000cc4a2420000803f000000000000000000000000000000000000803f000080bf0cc4a2420000000042619b43000000007255d0c30000803f000000000000000000000000000000000000803f000080bf7255d0c30000000042619b430000803f0cc4a2420000803f000000000000000000000000000000000000803f000080bf0cc4a2420000803f42619b430000803f7255d0c30000803f000000000000000000000000000000000000803f000080bf7255d0c30000803f42619b43000000007255d0c30000000000000000000080bf0000803f0000000000000000000080bf42619b4300000000218535c3000000007255d0c30000000000000000000080bf0000803f0000000000000000000080bf218535c30000000042619b430000803f7255d0c30000000000000000000080bf0000803f0000000000000000000080bf42619b430000803f218535c30000803f7255d0c30000000000000000000080bf0000803f0000000000000000000080bf218535c30000803f218535c3000000007255d0c3000080bf00000000000000000000000000000000000080bf000080bf7255d04300000000218535c3000000000bc4a242000080bf00000000000000000000000000000000000080bf000080bf0bc4a2c200000000218535c30000803f7255d0c3000080bf00000000000000000000000000000000000080bf000080bf7255d0430000803f218535c30000803f0bc4a242000080bf00000000000000000000000000000000000080bf000080bf0bc4a2c20000803f218535c30000803f0bc4a242000000000000803f000000000000803f0000000000000000000080bf218535c30bc4a24242619b430000803f0cc4a242000000000000803f000000000000803f0000000000000000000080bf42619b430cc4a242218535c30000803f7255d0c3000000000000803f000000000000803f0000000000000000000080bf218535c37255d0c342619b430000803f7255d0c3000000000000803f000000000000803f0000000000000000000080bf42619b437255d0c3218535c3000000007255d0c300000000000080bf00000000000080bf0000000000000000000080bf218535437255d0c342619b43000000007255d0c300000000000080bf00000000000080bf0000000000000000000080bf42619bc37255d0c3218535c3000000000bc4a24200000000000080bf00000000000080bf0000000000000000000080bf218535430bc4a24242619b43000000000cc4a24200000000000080bf00000000000080bf0000000000000000000080bf42619bc30cc4a242 + m_CompressedMesh: + m_Vertices: + m_NumItems: 0 + m_Range: 0 + m_Start: 0 + m_Data: + m_BitSize: 0 + m_UV: + m_NumItems: 0 + m_Range: 0 + m_Start: 0 + m_Data: + m_BitSize: 0 + m_Normals: + m_NumItems: 0 + m_Range: 0 + m_Start: 0 + m_Data: + m_BitSize: 0 + m_Tangents: + m_NumItems: 0 + m_Range: 0 + m_Start: 0 + m_Data: + m_BitSize: 0 + m_Weights: + m_NumItems: 0 + m_Data: + m_BitSize: 0 + m_NormalSigns: + m_NumItems: 0 + m_Data: + m_BitSize: 0 + m_TangentSigns: + m_NumItems: 0 + m_Data: + m_BitSize: 0 + m_FloatColors: + m_NumItems: 0 + m_Range: 0 + m_Start: 0 + m_Data: + m_BitSize: 0 + m_BoneIndices: + m_NumItems: 0 + m_Data: + m_BitSize: 0 + m_Triangles: + m_NumItems: 0 + m_Data: + m_BitSize: 0 + m_UVInfo: 0 + m_LocalAABB: + m_Center: {x: 64.619896, y: 0.5, z: -167.64232} + m_Extent: {x: 246.13992, y: 0.5, z: 249.02522} + m_MeshUsageFlags: 0 + m_BakedConvexCollisionMesh: + m_BakedTriangleCollisionMesh: + m_MeshMetrics[0]: 1 + m_MeshMetrics[1]: 1 + m_MeshOptimizationFlags: 1 + m_StreamData: + offset: 0 + size: 0 + path: --- !u!1 &1308873393 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Model/BlueprintObject/ChildObject.cs b/Assets/Scripts/Model/BlueprintObject/ChildObject.cs index dbcc89c..b3a0afd 100644 --- a/Assets/Scripts/Model/BlueprintObject/ChildObject.cs +++ b/Assets/Scripts/Model/BlueprintObject/ChildObject.cs @@ -48,11 +48,14 @@ public void SetBlueprintBounds(Data.Bounds bounds) // y and z reversed } var childMesh = gameObject.transform.GetChild(0); var scale = childMesh.transform.localScale; - (scale.x, scale.y, scale.z) = (bounds.X, bounds.Z, bounds.Y); childMesh.transform.localScale = scale; childMesh.transform.localPosition = scale / 2; + + var collider = gameObject.GetComponent(); + collider.size = scale; + collider.center = scale / 2; } /// @@ -68,65 +71,70 @@ public void SetBlueprintRotation(int xaxis, int zaxis) this.xaxis = xaxis; this.zaxis = zaxis; - bool xpos = xaxis > 0; - bool zpos = zaxis > 0; + var xAbs = Math.Abs(xaxis); + var zAbs = Math.Abs(zaxis); + int xSign = xaxis > 0 ? 1 : -1; + int zSign = zaxis > 0 ? 1 : -1; + + Vector3 right = new Vector3(xAbs == 1 ? xSign : 0, xAbs == 3 ? xSign : 0, xAbs == 2 ? xSign : 0); + Vector3 up = new Vector3(zAbs == 1 ? zSign : 0, zAbs == 3 ? zSign : 0, zAbs == 2 ? zSign : 0); + Vector3 forward = Vector3.Cross(right, up); + + //int yaxis = (int)(forward.x * 1 + forward.y * 2 + forward.z * 3); + + var rotation = gameObject.transform.rotation; + rotation.SetLookRotation(forward, up); + + // todo: create vector3D based on xaxis and zaxis, then calculate 'yaxis' vector3D and use that for forward in lookrotation + // get rid of switch case /* - int rotatex, rotatez; switch (Math.Abs(xaxis)) { case 1: - baseLinkRotatex.Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, 0, xpos ? 0 : 1), 180); - baseLinkMove.Children.Add(baseLinkRotatex); switch (Math.Abs(zaxis)) { case 1: - MessageBox.Show("Incorrect rotationset found !"); + Debug.LogError($"Incorrect rotationset found !"); break; case 2: - baseLinkRotatez.Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(zpos ? -1 : 1, 0, 0), 90); + rotation.SetLookRotation(new Vector3(-xpos, 0, 0), new Vector3(0, zpos, 0)); // ( forward (z) , up (y) ) break; case 3: - baseLinkRotatez.Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(zpos ? 0 : 1, 0, 0), 180); + rotation.SetLookRotation(new Vector3( 0, 0, xpos), new Vector3(0, zpos, 0)); break; } - baseLinkMove.Children.Add(baseLinkRotatez); break; case 2: - baseLinkRotatex.Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, 0, xpos ? 1 : -1), 90); - baseLinkMove.Children.Add(baseLinkRotatex); switch (Math.Abs(zaxis)) { case 1: - baseLinkRotatez.Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, zpos ? 1 : -1, 0), 90); + rotation.SetLookRotation(new Vector3(0, xpos, 0), new Vector3(zpos, 0, 0)); break; case 2: - MessageBox.Show("Incorrect rotationset found !"); + Debug.LogError($"Incorrect rotationset found !"); break; case 3: - baseLinkRotatez.Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, zpos ? 0 : 1, 0), 180); + rotation.SetLookRotation(new Vector3(0, xpos, 0), new Vector3(0, 0, zpos)); break; } - baseLinkMove.Children.Add(baseLinkRotatez); break; case 3: - baseLinkRotatex.Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, xpos ? -1 : 1, 0), 90); - baseLinkMove.Children.Add(baseLinkRotatex); switch (Math.Abs(zaxis)) { case 1: - baseLinkRotatez.Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, 0, (zpos == xpos) ? 1 : 0), 180); + rotation.SetLookRotation(new Vector3(0, 0, xpos), new Vector3(zpos, 0, 0)); break; case 2: - baseLinkRotatez.Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, 0, (zpos == xpos) ? -1 : 1), 90); + rotation.SetLookRotation(new Vector3(0, 0, xpos), new Vector3(0, zpos, 0)); break; case 3: - MessageBox.Show("Incorrect rotationset found !"); + Debug.LogError($"Incorrect rotationset found !"); break; } - baseLinkMove.Children.Add(baseLinkRotatez); break; } //rotations translate! //*/ + gameObject.transform.rotation = rotation; CalculateRotatedBounds(); } diff --git a/Assets/Scripts/Model/Shapes/Part.cs b/Assets/Scripts/Model/Shapes/Part.cs index 0bbf574..942514a 100644 --- a/Assets/Scripts/Model/Shapes/Part.cs +++ b/Assets/Scripts/Model/Shapes/Part.cs @@ -41,6 +41,10 @@ public override GameObject Instantiate(Transform parent) if (this.bounds == default) this.CalculateBounds(); + var collider = gameObject.GetComponent(); + collider.size = this.bounds; + collider.center = this.bounds / 2; + for (int i = 0; i < subMeshes.Length; i++) { var subMesh = subMeshes[i]; @@ -60,10 +64,10 @@ public override GameObject Instantiate(Transform parent) private void CalculateBounds() { if (partData.Box != null) - this.bounds = new Vector3(partData.Box.X, partData.Box.Y, partData.Box.Z); + this.bounds = new Vector3(partData.Box.X, partData.Box.Z, partData.Box.Y); if (partData.Hull != null) { - this.bounds = new Vector3(partData.Hull.X, partData.Hull.Y, partData.Hull.Z); + this.bounds = new Vector3(partData.Hull.X, partData.Hull.Z, partData.Hull.Y); } if (partData.Cylinder != null) { @@ -74,10 +78,10 @@ private void CalculateBounds() this.bounds = new Vector3(cylinder.Depth, cylinder.Diameter, cylinder.Diameter); break; case "y": - this.bounds = new Vector3(cylinder.Diameter, cylinder.Depth, cylinder.Diameter); + this.bounds = new Vector3(cylinder.Diameter, cylinder.Diameter, cylinder.Depth); break; case "z": - this.bounds = new Vector3(cylinder.Diameter, cylinder.Diameter, cylinder.Depth); + this.bounds = new Vector3(cylinder.Diameter, cylinder.Depth, cylinder.Diameter); break; } }