diff --git a/Assets/Prefabs/VertexPoint.prefab b/Assets/Prefabs/VertexPoint.prefab index 2780af8518e2d75d4971cd9762b167847b5dadd8..a48fadfed519339815db96df0f5b39c2f01cdfbe 100644 --- a/Assets/Prefabs/VertexPoint.prefab +++ b/Assets/Prefabs/VertexPoint.prefab @@ -287,7 +287,7 @@ MonoBehaviour: m_AttachPointCompatibilityMode: 0 m_StartingSingleGrabTransformers: [] m_StartingMultipleGrabTransformers: [] - m_AddDefaultGrabTransformers: 1 + m_AddDefaultGrabTransformers: 0 --- !u!114 &1183694293685742046 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index b9b3e57f8941732ce0b7d54936f79d4218fa636d..48e84956e0086ac8d772e0b09f139e0ec10c606a 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -18387,7 +18387,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5443163050158697355, guid: fa5ef3b56cfeb4f4ba855cdf2610a578, type: 3} propertyPath: m_Enabled - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 6150670977401591343, guid: fa5ef3b56cfeb4f4ba855cdf2610a578, type: 3} propertyPath: m_AnchorMax.y @@ -22151,7 +22151,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5443163050158697355, guid: fa5ef3b56cfeb4f4ba855cdf2610a578, type: 3} propertyPath: m_Enabled - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 6150670977401591343, guid: fa5ef3b56cfeb4f4ba855cdf2610a578, type: 3} propertyPath: m_AnchorMax.y @@ -22191,7 +22191,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 7753147258609537286, guid: fa5ef3b56cfeb4f4ba855cdf2610a578, type: 3} propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName - value: LoadProgram + value: ExportMesh objectReference: {fileID: 0} - target: {fileID: 7753147258609537286, guid: fa5ef3b56cfeb4f4ba855cdf2610a578, type: 3} propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName diff --git a/Assets/Scrips/Components/Block/BlockDeform.cs b/Assets/Scrips/Components/Block/BlockDeform.cs index b7624ad90a73e14f562a8c11a818fd68b86da3d3..eac6053e6ab4353f9fe735a12030b62bc655eafc 100644 --- a/Assets/Scrips/Components/Block/BlockDeform.cs +++ b/Assets/Scrips/Components/Block/BlockDeform.cs @@ -115,6 +115,12 @@ public class BlockDeform : MonoBehaviour InitAnchors(); EditState.Instance.RegisterListener(EditChangeHandler); + EditChangeHandler(); + } + + private void OnDestroy() + { + EditState.Instance.RemoveListener(EditChangeHandler); } private void InitAnchors() diff --git a/Assets/Scrips/Components/Block/BlockRotate.cs b/Assets/Scrips/Components/Block/BlockRotate.cs index 6853fb4fc4b025a39826252cd5197c4e736e11c1..47f2f9479d14982f3630fe5fb2d6e9f4d40042a3 100644 --- a/Assets/Scrips/Components/Block/BlockRotate.cs +++ b/Assets/Scrips/Components/Block/BlockRotate.cs @@ -89,8 +89,13 @@ public class BlockRotate : MonoBehaviour { _rotateAnchor = Instantiate(RotateAnchorPrefab, this.transform.position, Quaternion.identity); _rotateAnchor.GetComponent<RotateAnchor>().Initialize(this); - _rotateAnchor.SetActive(false); EditState.Instance.RegisterListener(EditStateHandler); + EditStateHandler(); + } + + private void OnDestroy() + { + EditState.Instance.RemoveListener(EditStateHandler); } private void EditStateHandler() diff --git a/Assets/Scrips/Components/Quad/FittedQuad.cs b/Assets/Scrips/Components/Quad/FittedQuad.cs index 42c9fb5afc0132a8ebf3fb4e178a34fbf66f5387..37ee8bfc99e95492bbf647ddb4942b2fe33c8217 100644 --- a/Assets/Scrips/Components/Quad/FittedQuad.cs +++ b/Assets/Scrips/Components/Quad/FittedQuad.cs @@ -19,6 +19,12 @@ public class FittedQuad : MonoBehaviour { InitAnchors(); EditState.Instance.RegisterListener(EditStateHandler); + EditStateHandler(); + } + + private void OnDestroy() + { + EditState.Instance.RemoveListener(EditStateHandler); } private void EditStateHandler() @@ -47,12 +53,19 @@ public class FittedQuad : MonoBehaviour } } - public void UpdateVertices() + public void UpdateVertices(bool globalCoordinates = false) { Vector3[] vertices = _mesh.vertices; for (int i = 0; i < vertices.Length; i++) { - vertices[i] = _vertexAnchors[i].transform.localPosition; + if (globalCoordinates) + { + vertices[i] = Quaternion.Inverse(_vertexAnchors[i].transform.rotation) * (_vertexAnchors[i].transform.position - this.transform.position); + } + else + { + vertices[i] = _vertexAnchors[i].transform.localPosition; + } } _mesh.vertices = vertices; @@ -63,11 +76,15 @@ public class FittedQuad : MonoBehaviour public void SetAnchors(Vector3[] positions) { - for (int i = 0; i < positions.Length; i++) + Vector3[] vertices = _mesh.vertices; + for (int i = 0; i < vertices.Length; i++) { - _vertexAnchors[i].transform.localPosition = positions[i]; + vertices[i] = positions[i]; } - UpdateVertices(); + _mesh.vertices = vertices; + _mesh.RecalculateBounds(); + MeshCollider collider = GetComponent<MeshCollider>(); + collider.sharedMesh = _mesh; } } diff --git a/Assets/Scrips/Components/Quad/VertexPoint.cs b/Assets/Scrips/Components/Quad/VertexPoint.cs index 74b0bf1d432b3bad25c40b2db89e890d17a91a98..f266ed44f4158a8b4615fbe966e24642f052d71a 100644 --- a/Assets/Scrips/Components/Quad/VertexPoint.cs +++ b/Assets/Scrips/Components/Quad/VertexPoint.cs @@ -35,6 +35,6 @@ public class VertexPoint : MonoBehaviour private void FixedUpdate() { - if (_isSelected) _parentQuad.UpdateVertices(); + if (_isSelected) _parentQuad.UpdateVertices(true); } } diff --git a/Assets/Scrips/Contexts/EditState.cs b/Assets/Scrips/Contexts/EditState.cs index 05caf7cbdfab4ada3f31e1fcb35bd41d6b34d5e3..952eb4136448595021b1a6839cd9e773c3aff55c 100644 --- a/Assets/Scrips/Contexts/EditState.cs +++ b/Assets/Scrips/Contexts/EditState.cs @@ -58,4 +58,12 @@ public class EditState : MonoBehaviour _registeredListeners.Add(listener); } } + + public void RemoveListener(Action listener) + { + if (_registeredListeners.Contains(listener)) + { + _registeredListeners.Remove(listener); + } + } } diff --git a/Assets/Scrips/Controllers/ProgramController.cs b/Assets/Scrips/Controllers/ProgramController.cs index 90e800e50295ce6914c95493363f92cfa42ea513..a480726f7136497622b08b268e1a66405d86036a 100644 --- a/Assets/Scrips/Controllers/ProgramController.cs +++ b/Assets/Scrips/Controllers/ProgramController.cs @@ -6,6 +6,8 @@ using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using UnityEngine; using UnityEngine.InputSystem; +using UnityEditor.Formats.Fbx.Exporter; +using Autodesk.Fbx; public class ProgramController : MonoBehaviour { @@ -138,9 +140,39 @@ public class ProgramController : MonoBehaviour UserTransform.position = save.UserTransform[0]; UserTransform.eulerAngles = save.UserTransform[1]; spawnBlockEvent.LoadBlocks(save.Blocks, save.BlockAnchors); + selectPointsController.LoadPlanes(save.Quads); + } + } + + public void ExportMesh() + { + string filePath = Path.Combine(Application.dataPath, "mesh.fbx"); + ModelExporter.ExportObject(filePath, this.gameObject); + } + + protected void ExportScene(string fileName) + { + using (FbxManager fbxManager = FbxManager.Create()) + { + // configure IO settings. + fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT)); + + // Export the scene + using (FbxExporter exporter = FbxExporter.Create(fbxManager, "myExporter")) + { + + // Initialize the exporter. + bool status = exporter.Initialize(fileName, -1, fbxManager.GetIOSettings()); + // Create a new scene to export + FbxScene scene = FbxScene.Create(fbxManager, "myScene"); + + // Export the scene to the file. + exporter.Export(scene); + } } } + } diff --git a/Assets/Scrips/Controllers/SelectPointsController.cs b/Assets/Scrips/Controllers/SelectPointsController.cs index 2ad5cec1718832b00bb1200c395d00b6e5625ca1..eeab8790087a0c975ba2892e285c2d98c3c81126 100644 --- a/Assets/Scrips/Controllers/SelectPointsController.cs +++ b/Assets/Scrips/Controllers/SelectPointsController.cs @@ -143,14 +143,14 @@ public class SelectPointsController : MonoBehaviour return projectedPoint; } - private void OnDrawGizmosSelected() - { - Gizmos.color = Color.red; - foreach (Vector3 pt in _debugPoints) - { - Gizmos.DrawSphere(pt, 0.05f); - } - } + // private void OnDrawGizmosSelected() + // { + // Gizmos.color = Color.red; + // foreach (Vector3 pt in _debugPoints) + // { + // Gizmos.DrawSphere(pt, 0.05f); + // } + // } public void AddSelection(GameObject selection) { diff --git a/Packages/manifest.json b/Packages/manifest.json index 2fda25c4a4dbce55bf521d315f314629879e91e2..ad258d26f678398579954f2ee96c20628b4ea7a8 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -3,6 +3,7 @@ "com.unity.collab-proxy": "2.3.1", "com.unity.feature.development": "1.0.1", "com.unity.feature.vr": "1.0.0", + "com.unity.formats.fbx": "4.2.1", "com.unity.learn.iet-framework": "3.1.3", "com.unity.render-pipelines.universal": "14.0.10", "com.unity.textmeshpro": "3.0.6", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index bd608f98dd060e4655396498b9547532691ccdb7..709428217c80cdfe3b6c9bfa043a1156a7310746 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,5 +1,12 @@ { "dependencies": { + "com.autodesk.fbx": { + "version": "4.2.1", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, "com.unity.burst": { "version": "1.8.12", "depth": 1, @@ -54,6 +61,16 @@ "com.unity.xr.openxr": "1.9.1" } }, + "com.unity.formats.fbx": { + "version": "4.2.1", + "depth": 0, + "source": "registry", + "dependencies": { + "com.autodesk.fbx": "4.2.1", + "com.unity.timeline": "1.7.1" + }, + "url": "https://packages.unity.com" + }, "com.unity.ide.rider": { "version": "3.0.27", "depth": 1, @@ -201,9 +218,9 @@ "depth": 0, "source": "registry", "dependencies": { + "com.unity.modules.audio": "1.0.0", "com.unity.modules.director": "1.0.0", "com.unity.modules.animation": "1.0.0", - "com.unity.modules.audio": "1.0.0", "com.unity.modules.particlesystem": "1.0.0" }, "url": "https://packages.unity.com" @@ -241,14 +258,14 @@ "depth": 0, "source": "registry", "dependencies": { + "com.unity.ugui": "1.0.0", "com.unity.inputsystem": "1.7.0", "com.unity.mathematics": "1.2.6", - "com.unity.ugui": "1.0.0", - "com.unity.xr.core-utils": "2.2.3", - "com.unity.xr.legacyinputhelpers": "2.1.10", "com.unity.modules.audio": "1.0.0", "com.unity.modules.imgui": "1.0.0", - "com.unity.modules.physics": "1.0.0" + "com.unity.xr.core-utils": "2.2.3", + "com.unity.modules.physics": "1.0.0", + "com.unity.xr.legacyinputhelpers": "2.1.10" }, "url": "https://packages.unity.com" }, @@ -267,9 +284,9 @@ "depth": 0, "source": "registry", "dependencies": { - "com.unity.modules.subsystems": "1.0.0", "com.unity.modules.vr": "1.0.0", "com.unity.modules.xr": "1.0.0", + "com.unity.modules.subsystems": "1.0.0", "com.unity.xr.legacyinputhelpers": "2.1.7" }, "url": "https://packages.unity.com" @@ -288,10 +305,10 @@ "depth": 0, "source": "registry", "dependencies": { - "com.unity.xr.management": "4.4.0", - "com.unity.xr.legacyinputhelpers": "2.1.2", "com.unity.inputsystem": "1.6.3", - "com.unity.xr.core-utils": "2.1.1" + "com.unity.xr.core-utils": "2.1.1", + "com.unity.xr.management": "4.4.0", + "com.unity.xr.legacyinputhelpers": "2.1.2" }, "url": "https://packages.unity.com" },