diff --git a/Assets/Models/tetra_trafo_normals2.fbx b/Assets/Models/tetra_trafo_normals2.fbx new file mode 100644 index 0000000000000000000000000000000000000000..6948910ed8dc8fc534157b9f11981a7c095d3001 --- /dev/null +++ b/Assets/Models/tetra_trafo_normals2.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:083bebe2c456acbad152a41f40bce1564f736dbdc1cd88cff040e7577bb506e8 +size 5737292 diff --git a/Assets/Models/tetra_trafo_normals2.fbx.meta b/Assets/Models/tetra_trafo_normals2.fbx.meta new file mode 100644 index 0000000000000000000000000000000000000000..2d75da8399b2e3a26dc1ffcfe2acff2c845a8220 --- /dev/null +++ b/Assets/Models/tetra_trafo_normals2.fbx.meta @@ -0,0 +1,114 @@ +fileFormatVersion: 2 +guid: cbd9713bd330c064b8c327427eb068e1 +ModelImporter: + serializedVersion: 22200 + internalIDToNameTable: [] + externalObjects: + - first: + type: UnityEngine:Material + assembly: UnityEngine.CoreModule + name: Material + second: {fileID: 2100000, guid: 03ecaad411917a84e835e76107a484b3, type: 2} + materials: + materialImportMode: 2 + materialName: 0 + materialSearch: 1 + materialLocation: 1 + animations: + legacyGenerateAnimations: 4 + bakeSimulation: 0 + resampleCurves: 1 + optimizeGameObjects: 0 + removeConstantScaleCurves: 0 + motionNodeName: + rigImportErrors: + rigImportWarnings: + animationImportErrors: + animationImportWarnings: + animationRetargetingWarnings: + animationDoRetargetingWarnings: 0 + importAnimatedCustomProperties: 0 + importConstraints: 0 + animationCompression: 1 + animationRotationError: 0.5 + animationPositionError: 0.5 + animationScaleError: 0.5 + animationWrapMode: 0 + extraExposedTransformPaths: [] + extraUserProperties: [] + clipAnimations: [] + isReadable: 1 + meshes: + lODScreenPercentages: [] + globalScale: 1 + meshCompression: 0 + addColliders: 0 + useSRGBMaterialColor: 1 + sortHierarchyByName: 1 + importPhysicalCameras: 1 + importVisibility: 1 + importBlendShapes: 1 + importCameras: 1 + importLights: 1 + nodeNameCollisionStrategy: 1 + fileIdsGeneration: 2 + swapUVChannels: 0 + generateSecondaryUV: 0 + useFileUnits: 1 + keepQuads: 0 + weldVertices: 1 + bakeAxisConversion: 0 + preserveHierarchy: 0 + skinWeightsMode: 0 + maxBonesPerVertex: 4 + minBoneWeight: 0.001 + optimizeBones: 1 + meshOptimizationFlags: 0 + indexFormat: 0 + secondaryUVAngleDistortion: 8 + secondaryUVAreaDistortion: 15.000001 + secondaryUVHardAngle: 88 + secondaryUVMarginMethod: 1 + secondaryUVMinLightmapResolution: 40 + secondaryUVMinObjectScale: 1 + secondaryUVPackMargin: 4 + useFileScale: 0 + strictVertexDataChecks: 0 + tangentSpace: + normalSmoothAngle: 60 + normalImportMode: 0 + tangentImportMode: 2 + normalCalculationMode: 1 + legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0 + blendShapeNormalImportMode: 2 + normalSmoothingSource: 3 + referencedClips: [] + importAnimation: 1 + humanDescription: + serializedVersion: 3 + human: [] + skeleton: [] + armTwist: 0.5 + foreArmTwist: 0.5 + upperLegTwist: 0.5 + legTwist: 0.5 + armStretch: 0.05 + legStretch: 0.05 + feetSpacing: 0 + globalScale: 1 + rootMotionBoneName: + hasTranslationDoF: 0 + hasExtraRoot: 0 + skeletonHasParents: 1 + lastHumanDescriptionAvatarSource: {instanceID: 0} + autoGenerateAvatarMappingIfUnspecified: 1 + animationType: 2 + humanoidOversampling: 1 + avatarSetup: 0 + addHumanoidExtraRootOnlyWhenUsingAvatar: 1 + importBlendShapeDeformPercent: 1 + remapMaterialsIfMaterialImportModeIsNone: 0 + additionalBone: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/PointChecker.cs b/Assets/PointChecker.cs index 7b3e5a610aa78246685ae11d613aeb02c3ae1cc3..d23003603e3a4fba906527160a0a42a93daa28bb 100644 --- a/Assets/PointChecker.cs +++ b/Assets/PointChecker.cs @@ -24,7 +24,10 @@ public class PointChecker : MonoBehaviour Vector3[] normals = _mesh.normals; for (int i = 0; i < 60; i++) { - Debug.Log(vertices[i].ToString() + "is connected to normal: " + normals[i].ToString()); + Vector3 vertex = vertices[i]; + Vector3 multiplied = normals[i] * vertex.magnitude; + float difference = Vector3.Distance(vertex, multiplied); + Debug.Log(vertex.ToString() + "is connected to normal: " + normals[i].ToString() + " multiplied by abs: " + multiplied.ToString() + " difference " + difference); } Debug.Log("checking mesh"); } diff --git a/Assets/Prefabs/BlockSelect.prefab b/Assets/Prefabs/BlockSelect.prefab index d2f9b761b96d7a871a15929a4e1c152626283b5a..cd12e9e8e4924444a615500b21ac11b499a8d35b 100644 --- a/Assets/Prefabs/BlockSelect.prefab +++ b/Assets/Prefabs/BlockSelect.prefab @@ -102,6 +102,7 @@ MonoBehaviour: m_EditorClassIdentifier: deformAnchorPrefab: {fileID: 2720765159515821108, guid: 46377d8bcd3914149bbb7c475d721f56, type: 3} wrapDistance: 0.01 + isSelection: 1 --- !u!64 &3268846158774871891 MeshCollider: m_ObjectHideFlags: 0 @@ -253,3 +254,4 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2f2c9d2fbf2ef104992bb5e55dae6b42, type: 3} m_Name: m_EditorClassIdentifier: + selectPointsController: {fileID: 0} diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index f5a9d9b5ccf25e4cd5821f857d62aea8e01cfe6b..1a459deebf13d9e73d3d6ef22bf44cf6ebbe94a9 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -4106,6 +4106,78 @@ RectTransform: m_CorrespondingSourceObject: {fileID: 8072890477496077224, guid: 085ce58b196caa446a8545c9dd388793, type: 3} m_PrefabInstance: {fileID: 266946677} m_PrefabAsset: {fileID: 0} +--- !u!1001 &291343767 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalScale.x + value: 1 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalScale.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalScale.z + value: 1 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalPosition.x + value: -5.32 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalPosition.y + value: 1.913 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalPosition.z + value: -8.95 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalRotation.w + value: 0.7071068 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalRotation.x + value: -0.7071068 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: -90 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -8679921383154817045, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 919132149155446097, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + propertyPath: m_Name + value: tetra_trafo_normals2 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + insertIndex: -1 + addedObject: {fileID: 1565662008} + m_SourcePrefab: {fileID: 100100000, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} --- !u!1 &295595497 stripped GameObject: m_CorrespondingSourceObject: {fileID: -4618025148844850862, guid: af3a609f3b06600409a356f4e8ba91ba, type: 3} @@ -5692,7 +5764,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: pointClouds: - - {fileID: 1163381647} + - {fileID: 1565662007} selectPointsEventAction: {fileID: -1827717145013635445, guid: c348712bda248c246b8c49b3db54643f, type: 3} --- !u!1001 &427008753 PrefabInstance: @@ -14283,7 +14355,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 919132149155446097, guid: 1d38bbb85fb049347b6bf6b167e94d22, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] @@ -18789,6 +18861,23 @@ PrefabInstance: addedObject: {fileID: 1416212407} m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 085ce58b196caa446a8545c9dd388793, type: 3} +--- !u!1 &1565662007 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + m_PrefabInstance: {fileID: 291343767} + m_PrefabAsset: {fileID: 0} +--- !u!114 &1565662008 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1565662007} + m_Enabled: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7b54aaf8f9e28124eb09d6c4a9a7e85a, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!114 &1567186874 MonoBehaviour: m_ObjectHideFlags: 0 @@ -27461,3 +27550,4 @@ SceneRoots: - {fileID: 426651920} - {fileID: 140882063} - {fileID: 1583744429} + - {fileID: 291343767} diff --git a/Assets/Scrips/Components/Block/BlockDeform.cs b/Assets/Scrips/Components/Block/BlockDeform.cs index 1f0b3d04b87ef0397c1aff96dde5853571833e7d..b7624ad90a73e14f562a8c11a818fd68b86da3d3 100644 --- a/Assets/Scrips/Components/Block/BlockDeform.cs +++ b/Assets/Scrips/Components/Block/BlockDeform.cs @@ -6,6 +6,7 @@ public class BlockDeform : MonoBehaviour { public GameObject deformAnchorPrefab; public float wrapDistance; + public bool isSelection = false; private Mesh _mesh; private readonly DeformAnchor[] _deformAnchors = new DeformAnchor[6]; @@ -112,6 +113,8 @@ public class BlockDeform : MonoBehaviour { if (!this.loadedType) InitAnchors(); + + EditState.Instance.RegisterListener(EditChangeHandler); } private void InitAnchors() @@ -170,12 +173,19 @@ public class BlockDeform : MonoBehaviour UpdateDeformAnchors(); } - private void FixedUpdate() + public void EditChangeHandler() { EditState.EditType mode = EditState.Instance.ActiveEditState; foreach (GameObject anchor in _spawnedAnchors) { - anchor.SetActive(mode == EditState.EditType.Deform); + if (!isSelection) + { + anchor.SetActive(mode == EditState.EditType.Deform); + } + else + { + anchor.SetActive(mode == EditState.EditType.Select); + } } } diff --git a/Assets/Scrips/Components/Selection.meta b/Assets/Scrips/Components/Selection.meta new file mode 100644 index 0000000000000000000000000000000000000000..a0dc2cbae138857e9cb1cf7da3e3e55de04fec25 --- /dev/null +++ b/Assets/Scrips/Components/Selection.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c53117d7a7453f942a7b2f3957877b27 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BlockSelect.cs b/Assets/Scrips/Components/Selection/BlockSelect.cs similarity index 100% rename from Assets/BlockSelect.cs rename to Assets/Scrips/Components/Selection/BlockSelect.cs diff --git a/Assets/BlockSelect.cs.meta b/Assets/Scrips/Components/Selection/BlockSelect.cs.meta similarity index 100% rename from Assets/BlockSelect.cs.meta rename to Assets/Scrips/Components/Selection/BlockSelect.cs.meta diff --git a/Assets/SelectPointsController.cs b/Assets/Scrips/Controllers/SelectPointsController.cs similarity index 60% rename from Assets/SelectPointsController.cs rename to Assets/Scrips/Controllers/SelectPointsController.cs index e1ae225391f2d735b8a353d32526438e1d5a2a06..49d587664b5711602912e2ab6d239c046d9f1f85 100644 --- a/Assets/SelectPointsController.cs +++ b/Assets/Scrips/Controllers/SelectPointsController.cs @@ -19,6 +19,8 @@ public class SelectPointsController : MonoBehaviour private List<Vector3> _debugPoints; + private List<Vector3> _recalculatedPoints; + private void Awake() { _inputSelectPoints = new(selectPointsEventAction, SelectPointsHandler); @@ -28,17 +30,52 @@ public class SelectPointsController : MonoBehaviour private void SelectPointsHandler(InputAction.CallbackContext context) { + // double epsilon = 1E-6; List<Vector3> selectedPoints = new(); - MeshCollider collider = _blockSelections[0].GetComponent<MeshCollider>(); - Mesh pointCloudMesh = pointClouds[0].GetComponent<MeshFilter>().mesh; Transform cloudTransform = pointClouds[0].transform; - foreach (Vector3 pt in pointCloudMesh.vertices) + // Mesh pointCloudMesh = pointClouds[0].GetComponent<MeshFilter>().mesh; + // Vector3[] cloudVertices = pointCloudMesh.vertices; + // Vector3[] cloudNormals = pointCloudMesh.normals; + // Vector3 cloudNormal = cloudNormals[0]; + // List<Vector3> normalsPerFace = new() + // { + // cloudNormals[0] * pointCloudMesh.vertices[0].magnitude + // }; + for (int i = 0; i < _recalculatedPoints.Count; i++) { - Vector3 ptGlobal = cloudTransform.rotation * pt + cloudTransform.position; - if (collider.bounds.Contains(ptGlobal)) + // Vector3 pt = cloudVertices[i]; + // if (Vector3.Distance(cloudNormals[i], cloudNormal) < epsilon) + // { + // normalsPerFace.Add(cloudNormals[i] * pt.magnitude); + // } + // else + // { + // Vector3 normalAverage = normalsPerFace[0]; + // if (normalsPerFace.Count > 1) + // { + // for (int j = 1; j < normalsPerFace.Count; j++) + // { + // normalAverage += normalsPerFace[j]; + // } + + // normalAverage /= normalsPerFace.Count; + // } + + foreach (GameObject blockSelection in _blockSelections) { - selectedPoints.Add(ptGlobal); + MeshCollider collider = blockSelection.GetComponent<MeshCollider>(); + Vector3 ptGlobal = cloudTransform.rotation * _recalculatedPoints[i] + cloudTransform.position; + if (collider.bounds.Contains(ptGlobal)) + { + selectedPoints.Add(ptGlobal); + } } + + // cloudNormal = cloudNormals[i]; + // normalsPerFace.Clear(); + // normalsPerFace.Add(cloudNormals[i] * pt.magnitude); + // } + } CalculatePlane(selectedPoints); // CalculatePlaneByAvg(selectedPoints); @@ -112,9 +149,11 @@ public class SelectPointsController : MonoBehaviour Svd<float> svd = G.Svd(true); Matrix<float> vt = svd.VT; + // vt = vt.Transpose(); Vector<float> planeEq = vt.Row(3); Vector3 planeNormal = new(planeEq[0], planeEq[1], planeEq[2]); + // planeNormal = pointClouds[0].transform.rotation * planeNormal; planeNormal.Normalize(); float d = planeNormal.x * points[0].x + planeNormal.y * points[0].y + planeNormal.z * points[0].z; @@ -165,7 +204,47 @@ public class SelectPointsController : MonoBehaviour // Start is called before the first frame update void Start() { + _recalculatedPoints = new(); + + float epsilon = 0.005f; + + Mesh pointCloudMesh = pointClouds[0].GetComponent<MeshFilter>().mesh; + Vector3[] cloudVertices = pointCloudMesh.vertices; + Vector3[] cloudNormals = pointCloudMesh.normals; + Vector3 cloudNormal = cloudNormals[0]; + List<Vector3> normalsPerFace = new() + { + cloudNormals[0] * pointCloudMesh.vertices[0].magnitude + }; + for (int i = 1; i < pointCloudMesh.vertices.Length; i++) + { + Vector3 pt = cloudVertices[i]; + float distance = Vector3.Distance(cloudNormals[i], cloudNormal); + if (distance < epsilon) + { + normalsPerFace.Add(cloudNormals[i] * pt.magnitude); + } + else + { + Vector3 normalAverage = normalsPerFace[0]; + if (normalsPerFace.Count > 1) + { + for (int j = 1; j < normalsPerFace.Count; j++) + { + normalAverage += normalsPerFace[j]; + } + + normalAverage /= normalsPerFace.Count; + } + + _recalculatedPoints.Add(normalAverage); + + cloudNormal = cloudNormals[i]; + normalsPerFace.Clear(); + normalsPerFace.Add(cloudNormals[i] * pt.magnitude); + } + } } // Update is called once per frame diff --git a/Assets/SelectPointsController.cs.meta b/Assets/Scrips/Controllers/SelectPointsController.cs.meta similarity index 100% rename from Assets/SelectPointsController.cs.meta rename to Assets/Scrips/Controllers/SelectPointsController.cs.meta diff --git a/Assets/Settings/Project Configuration/SampleScene.scenetemplate b/Assets/Settings/Project Configuration/SampleScene.scenetemplate index 50209629e81de1a0a5489f8c2f82371bce8e22c4..c5491cd07adb4ddcef46cfe801e31a894d4659ee 100644 --- a/Assets/Settings/Project Configuration/SampleScene.scenetemplate +++ b/Assets/Settings/Project Configuration/SampleScene.scenetemplate @@ -342,6 +342,8 @@ MonoBehaviour: instantiationMode: 0 - dependency: {fileID: 919132149155446097, guid: da7215fc737ba47489f5c28303aa0d81, type: 3} instantiationMode: 0 + - dependency: {fileID: 919132149155446097, guid: cbd9713bd330c064b8c327427eb068e1, type: 3} + instantiationMode: 0 - dependency: {fileID: 919132149155446097, guid: a7a48ffe8eca1b6418fba110a2d48baa, type: 3} instantiationMode: 0 - dependency: {fileID: 13400000, guid: 10bde48ef542d6a4fbee12145283824a, type: 2} @@ -358,6 +360,8 @@ MonoBehaviour: instantiationMode: 0 - dependency: {fileID: 919132149155446097, guid: a8211a3e0e87d014e8326e23ae022d39, type: 3} instantiationMode: 0 + - dependency: {fileID: 2100000, guid: 03ecaad411917a84e835e76107a484b3, type: 2} + instantiationMode: 0 - dependency: {fileID: 8126816444565180231, guid: f24fe5caf4a57c148bd86d63b19a1248, type: 3} instantiationMode: 0 - dependency: {fileID: 2800000, guid: 7461125ec591a1548883bd61123e9138, type: 3}