Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
AVVR-Unity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GDP Project 4
AVVR-Unity
Commits
afaeedc2
Commit
afaeedc2
authored
6 months ago
by
mhby1g21
Browse files
Options
Downloads
Patches
Plain Diff
added scale to target dimensions functionality
parent
d88c7af1
No related branches found
No related tags found
2 merge requests
!7
added #if UNITY_EDITOR #endif directives to all editor related scripts
,
!6
added subjective and objective evaluation scenes, with improvements on meshdimension script and xr origin prefab
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
AVVR/Assets/_Scripts/MeshDimension/MeshDimensionCalculator.cs
+71
-0
71 additions, 0 deletions
.../Assets/_Scripts/MeshDimension/MeshDimensionCalculator.cs
with
71 additions
and
0 deletions
AVVR/Assets/_Scripts/MeshDimension/MeshDimensionCalculator.cs
+
71
−
0
View file @
afaeedc2
...
@@ -142,6 +142,37 @@ public static class MeshDimensionCalculatorLogic
...
@@ -142,6 +142,37 @@ public static class MeshDimensionCalculatorLogic
targetObject
.
transform
.
localScale
=
Vector3
.
one
;
targetObject
.
transform
.
localScale
=
Vector3
.
one
;
Debug
.
Log
(
"Target object scale has been reset to (1, 1, 1)."
);
Debug
.
Log
(
"Target object scale has been reset to (1, 1, 1)."
);
}
}
public
static
Vector3
CalculateScaleFactorsForTargetDimensions
(
Vector3
currentDimensions
,
Vector3
targetDimensions
)
{
if
(
currentDimensions
==
Vector3
.
zero
)
{
Debug
.
LogError
(
"Current dimensions are zero. Please calculate dimensions first!"
);
return
Vector3
.
one
;
}
return
new
Vector3
(
targetDimensions
.
x
/
currentDimensions
.
x
,
targetDimensions
.
y
/
currentDimensions
.
y
,
targetDimensions
.
z
/
currentDimensions
.
z
);
}
public
static
void
ScaleToTargetDimensions
(
GameObject
targetObject
,
Vector3
currentDimensions
,
Vector3
targetDimensions
)
{
if
(
targetObject
==
null
)
{
Debug
.
LogError
(
"Target object is not assigned!"
);
return
;
}
Vector3
scaleFactors
=
CalculateScaleFactorsForTargetDimensions
(
currentDimensions
,
targetDimensions
);
Undo
.
RecordObject
(
targetObject
.
transform
,
"Scale To Target Dimensions"
);
Vector3
currentScale
=
targetObject
.
transform
.
localScale
;
Vector3
newScale
=
Vector3
.
Scale
(
currentScale
,
scaleFactors
);
targetObject
.
transform
.
localScale
=
newScale
;
Debug
.
Log
(
$"Scaled object to target dimensions. New scale:
{
newScale
}
"
);
}
}
}
// MonoBehaviour Component
// MonoBehaviour Component
...
@@ -150,6 +181,7 @@ public class MeshDimensionCalculator : MonoBehaviour
...
@@ -150,6 +181,7 @@ public class MeshDimensionCalculator : MonoBehaviour
public
GameObject
targetObject
;
public
GameObject
targetObject
;
private
DimensionResults
results
;
private
DimensionResults
results
;
[
SerializeField
]
private
Vector3
targetDimensions
=
Vector3
.
one
;
[
SerializeField
]
private
Vector3
scaleFactors
=
Vector3
.
one
;
[
SerializeField
]
private
Vector3
scaleFactors
=
Vector3
.
one
;
[
SerializeField
]
private
float
uniformScaleFactor
=
1f
;
[
SerializeField
]
private
float
uniformScaleFactor
=
1f
;
...
@@ -187,6 +219,17 @@ public class MeshDimensionCalculator : MonoBehaviour
...
@@ -187,6 +219,17 @@ public class MeshDimensionCalculator : MonoBehaviour
{
{
MeshDimensionCalculatorLogic
.
ResetScale
(
targetObject
);
MeshDimensionCalculatorLogic
.
ResetScale
(
targetObject
);
}
}
public
void
ScaleToTargetDimensions
()
{
if
(
results
==
null
||
results
.
dimensions
==
Vector3
.
zero
)
{
Debug
.
LogWarning
(
"Please calculate dimensions first!"
);
return
;
}
MeshDimensionCalculatorLogic
.
ScaleToTargetDimensions
(
targetObject
,
results
.
dimensions
,
targetDimensions
);
}
}
}
// Inspector UI for the MonoBehaviour component
// Inspector UI for the MonoBehaviour component
...
@@ -194,12 +237,14 @@ public class MeshDimensionCalculator : MonoBehaviour
...
@@ -194,12 +237,14 @@ public class MeshDimensionCalculator : MonoBehaviour
public
class
MeshDimensionCalculatorEditor
:
Editor
public
class
MeshDimensionCalculatorEditor
:
Editor
{
{
SerializedProperty
targetObjectProperty
;
SerializedProperty
targetObjectProperty
;
SerializedProperty
targetDimensionsProperty
;
SerializedProperty
scaleFactorsProperty
;
SerializedProperty
scaleFactorsProperty
;
SerializedProperty
uniformScaleFactorProperty
;
SerializedProperty
uniformScaleFactorProperty
;
private
void
OnEnable
()
private
void
OnEnable
()
{
{
targetObjectProperty
=
serializedObject
.
FindProperty
(
"targetObject"
);
targetObjectProperty
=
serializedObject
.
FindProperty
(
"targetObject"
);
targetDimensionsProperty
=
serializedObject
.
FindProperty
(
"targetDimensions"
);
scaleFactorsProperty
=
serializedObject
.
FindProperty
(
"scaleFactors"
);
scaleFactorsProperty
=
serializedObject
.
FindProperty
(
"scaleFactors"
);
uniformScaleFactorProperty
=
serializedObject
.
FindProperty
(
"uniformScaleFactor"
);
uniformScaleFactorProperty
=
serializedObject
.
FindProperty
(
"uniformScaleFactor"
);
}
}
...
@@ -227,6 +272,15 @@ public class MeshDimensionCalculatorEditor : Editor
...
@@ -227,6 +272,15 @@ public class MeshDimensionCalculatorEditor : Editor
calculator
.
ResetFloorToZero
();
calculator
.
ResetFloorToZero
();
}
}
EditorGUILayout
.
Space
();
EditorGUILayout
.
LabelField
(
"Target Dimensions"
,
EditorStyles
.
boldLabel
);
EditorGUILayout
.
PropertyField
(
targetDimensionsProperty
,
new
GUIContent
(
"Target Dimensions (X, Y, Z)"
));
if
(
GUILayout
.
Button
(
"Scale To Target Dimensions"
))
{
calculator
.
ScaleToTargetDimensions
();
}
EditorGUILayout
.
Space
();
EditorGUILayout
.
Space
();
EditorGUILayout
.
LabelField
(
"Scaling Options"
,
EditorStyles
.
boldLabel
);
EditorGUILayout
.
LabelField
(
"Scaling Options"
,
EditorStyles
.
boldLabel
);
...
@@ -260,6 +314,7 @@ public class MeshDimensionCalculatorWindow : EditorWindow
...
@@ -260,6 +314,7 @@ public class MeshDimensionCalculatorWindow : EditorWindow
{
{
private
GameObject
targetObject
;
private
GameObject
targetObject
;
private
DimensionResults
results
;
private
DimensionResults
results
;
private
Vector3
targetDimensions
=
Vector3
.
one
;
private
Vector3
scaleFactors
=
Vector3
.
one
;
private
Vector3
scaleFactors
=
Vector3
.
one
;
private
float
uniformScaleFactor
=
1f
;
private
float
uniformScaleFactor
=
1f
;
...
@@ -301,6 +356,22 @@ public class MeshDimensionCalculatorWindow : EditorWindow
...
@@ -301,6 +356,22 @@ public class MeshDimensionCalculatorWindow : EditorWindow
}
}
}
}
EditorGUILayout
.
Space
();
EditorGUILayout
.
LabelField
(
"Target Dimensions"
,
EditorStyles
.
boldLabel
);
targetDimensions
=
EditorGUILayout
.
Vector3Field
(
"Target Dimensions (X, Y, Z)"
,
targetDimensions
);
if
(
GUILayout
.
Button
(
"Scale To Target Dimensions"
))
{
if
(
results
!=
null
)
{
MeshDimensionCalculatorLogic
.
ScaleToTargetDimensions
(
targetObject
,
results
.
dimensions
,
targetDimensions
);
}
else
{
EditorUtility
.
DisplayDialog
(
"Error"
,
"Please calculate dimensions first!"
,
"OK"
);
}
}
EditorGUILayout
.
Space
();
EditorGUILayout
.
Space
();
EditorGUILayout
.
LabelField
(
"Scaling Options"
,
EditorStyles
.
boldLabel
);
EditorGUILayout
.
LabelField
(
"Scaling Options"
,
EditorStyles
.
boldLabel
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment