-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(focus): now calc currentSceneTreeNode's all children and its sel…
…f->aabb
- Loading branch information
Showing
6 changed files
with
237 additions
and
259 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/core/utils/engine/job/init/initHotKeysJob/FocusUtils.re
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
let _setArcballCameraControllerFocusRelatedAttribute = | ||
(arcballCameraController, (distance, target), engineState) => { | ||
Js.log(distance); | ||
|
||
engineState | ||
|> ArcballCameraEngineService.setArcballCameraControllerTarget( | ||
arcballCameraController, | ||
target, | ||
) | ||
|> ArcballCameraEngineService.setArcballCameraControllerDistance( | ||
distance, | ||
arcballCameraController, | ||
); | ||
}; | ||
|
||
let _getTargetGameObjectMaxScale = (targetGameObjectTransform, engineState) => { | ||
let (scaleX, scaleY, scaleZ) = | ||
engineState |> TransformEngineService.getScale(targetGameObjectTransform); | ||
|
||
Js.Math.max_float(scaleX, scaleY) |> Js.Math.max_float(scaleZ); | ||
}; | ||
|
||
let _buildAllPointsAndLocalToWolrdMatrices = (targetGameObject, engineState) => | ||
engineState | ||
|> HierarchyGameObjectEngineService.getAllGameObjects(targetGameObject) | ||
|> Js.Array.filter(gameObject => | ||
GameObjectComponentEngineService.hasGeometryComponent( | ||
gameObject, | ||
engineState, | ||
) | ||
) | ||
|> Js.Array.map(gameObject => { | ||
let geometry = | ||
engineState | ||
|> GameObjectComponentEngineService.unsafeGetGeometryComponent( | ||
gameObject, | ||
); | ||
|
||
( | ||
engineState |> GeometryEngineService.getGeometryVertices(geometry), | ||
engineState | ||
|> TransformGameObjectEngineService.getLocalToWorldMatrixTypeArray( | ||
gameObject, | ||
), | ||
); | ||
}); | ||
|
||
let _calcGeometrySphereCenterAndRadius = (targetGameObject, engineState) => { | ||
let aabb = | ||
AABBShapeUtils.setFromAllPointsAndLocalToWolrdMatrices( | ||
_buildAllPointsAndLocalToWolrdMatrices(targetGameObject, engineState), | ||
); | ||
let center = AABBShapeUtils.getCenter(aabb); | ||
|
||
(center, AABBShapeUtils.calcRadiusOfAABB(aabb, center)); | ||
}; | ||
|
||
let _calcArcballCameraControllerDistance = | ||
(distance, targetGameObjectTransform, engineState) => | ||
_getTargetGameObjectMaxScale(targetGameObjectTransform, engineState) | ||
*. distance | ||
*. 2.5; | ||
|
||
let setEditorCameraFocusTargetGameObject = | ||
(editCamera, targetGameObject, editorState, engineState) => { | ||
WonderLog.Contract.requireCheck( | ||
() => | ||
WonderLog.( | ||
Contract.( | ||
Operators.( | ||
test( | ||
Log.buildAssertMessage( | ||
~expect= | ||
{j|the editor camera should has arcballCameraController component|j}, | ||
~actual={j|not|j}, | ||
), | ||
() => | ||
GameObjectComponentEngineService.hasArcballCameraControllerComponent( | ||
editCamera, | ||
engineState, | ||
) | ||
|> assertTrue | ||
) | ||
) | ||
) | ||
), | ||
StateEditorService.getStateIsDebug(), | ||
); | ||
|
||
let editorCameraArcballControllerComponent = | ||
GameObjectComponentEngineService.unsafeGetArcballCameraControllerComponent( | ||
editCamera, | ||
engineState, | ||
); | ||
let targetGameObjectTransform = | ||
engineState | ||
|> GameObjectComponentEngineService.unsafeGetTransformComponent( | ||
targetGameObject, | ||
); | ||
|
||
let (center, radius) = | ||
engineState |> _calcGeometrySphereCenterAndRadius(targetGameObject); | ||
|
||
_setArcballCameraControllerFocusRelatedAttribute( | ||
editorCameraArcballControllerComponent, | ||
( | ||
engineState | ||
|> _calcArcballCameraControllerDistance( | ||
radius, | ||
targetGameObjectTransform, | ||
), | ||
center, | ||
), | ||
engineState, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.