-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(architecture): pass run test: only implement start time job
- Loading branch information
Showing
15 changed files
with
294 additions
and
41 deletions.
There are no files selected for viewing
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,133 @@ | ||
var Perf_hooks = require("perf_hooks"); | ||
|
||
var THREE = require("../reference/three.js/build/three.js"); | ||
|
||
var { set: setConfigDp } = require("../lib/js/src/run/external_layer/api/dependency/ConfigDpCPAPI.bs.js"); | ||
var { set: setSceneGraphRepoDp } = require("../lib/js/src/run/external_layer/api/dependency/SceneGraphRepoDpCPAPI.bs.js"); | ||
var { set: setTimeDp } = require("../lib/js/src/run/external_layer/api/dependency/TimeDpCPAPI.bs.js"); | ||
var { set: setConfigDp } = require("../lib/js/src/run/external_layer/api/dependency/ConfigDpCPAPI.bs.js"); | ||
|
||
var { prepare, init } = require("../lib/js/src/run/external_layer/api/DirectorCPAPI.bs.js"); | ||
|
||
|
||
let camera, scene; | ||
let mesh1, mesh2; | ||
|
||
|
||
function _init() { | ||
camera = new THREE.PerspectiveCamera(70, 1.0, 1, 1000); | ||
camera.position.z = 400; | ||
|
||
scene = new THREE.Scene(); | ||
|
||
|
||
const geometry = new THREE.BoxBufferGeometry(200, 200, 200); | ||
const material = new THREE.MeshBasicMaterial(); | ||
|
||
|
||
mesh1 = new THREE.Mesh(undefined, material); | ||
mesh1.position.y = 300; | ||
scene.add(mesh1); | ||
|
||
|
||
mesh2 = new THREE.Mesh(geometry, material); | ||
mesh2.position.x = 100; | ||
scene.add(mesh2); | ||
} | ||
|
||
function _isGeometryHasVertexData(geometry) { | ||
let attribute = geometry.getAttribute("position"); | ||
|
||
return !!attribute && attribute.length > 0; | ||
} | ||
|
||
function _setAllDp() { | ||
setConfigDp({ | ||
getIsDebug: (function () { | ||
return true; | ||
}) | ||
}); | ||
setTimeDp({ | ||
getNow: (function () { | ||
return Perf_hooks.performance.now(); | ||
}) | ||
}); | ||
|
||
var sceneGraphRepoDp = { | ||
sceneRepo: { | ||
getSceneGameObject: () => scene | ||
}, | ||
gameObjectRepo: { | ||
getTransform: (gameObject) => { | ||
return gameObject; | ||
}, | ||
getAllGeometryGameObjects: (scene) => { | ||
let result = []; | ||
|
||
scene.traverse(function (object) { | ||
if (!object.geometry) { | ||
return; | ||
} | ||
|
||
let geometry = object.geometry; | ||
|
||
if (_isGeometryHasVertexData(geometry)) { | ||
result.push(object); | ||
} | ||
}); | ||
|
||
return result; | ||
} | ||
}, | ||
transformRepo: { | ||
getLocalToWorldMatrix: (transform) => { | ||
return transform.matrix; | ||
}, | ||
getNormalMatrix: (transform) => { | ||
return transform.normalMatrix; | ||
}, | ||
getLocalPosition: (transform) => { | ||
return transform.position; | ||
}, | ||
getLocalRotation: (transform) => { | ||
return transform.quaternion; | ||
}, | ||
getLocalScale: (transform) => { | ||
return transform.scale; | ||
}, | ||
getPosition: (transform) => { | ||
let worldPosition = new THREE.Vector3(); | ||
|
||
return transform.getWorldPosition(worldPosition); | ||
}, | ||
getRotation: (transform) => { | ||
let worldRotation = new THREE.Quaternion(); | ||
|
||
return transform.getWorldQuaternion(worldRotation); | ||
}, | ||
getScale: (transform) => { | ||
let worldScale = new THREE.Vector3(); | ||
|
||
return transform.getWorldScale(worldScale); | ||
}, | ||
} | ||
}; | ||
|
||
setSceneGraphRepoDp(sceneGraphRepoDp); | ||
} | ||
|
||
async function _main() { | ||
_init(); | ||
|
||
_setAllDp(); | ||
|
||
prepare([512, 256]); | ||
|
||
await init(); | ||
} | ||
|
||
console.log("begin main"); | ||
|
||
_main().then(() => { | ||
console.log("finish main"); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
let getAllRenderGameObjects = () => { | ||
AllRenderGameObjectsDoService.getAllRenderGameObjects(); | ||
let getAllRenderGameObjects = sceneGameObject => { | ||
AllRenderGameObjectsDoService.getAllRenderGameObjects(sceneGameObject); | ||
}; | ||
|
||
let getTransform = gameObject => { | ||
GetComponentGameObjectDoService.getTransform(gameObject); | ||
}; |
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,4 @@ | ||
|
||
let getSceneGameObject = () => { | ||
SceneRoot.getSceneGameObject(); | ||
}; |
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
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
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
11 changes: 11 additions & 0 deletions
11
src/construct/domain_layer/domain/scene/scene_graph/entity/TransformEntity.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,11 @@ | ||
type t = | ||
| Transform(SceneGraphType.transform); | ||
|
||
let create = index => Transform(index); | ||
|
||
let value = transform => | ||
switch (transform) { | ||
| Transform(index) => index | ||
}; | ||
|
||
// let isSame = (tran1, tran2) => value(tran1) === value(tran2); |
4 changes: 4 additions & 0 deletions
4
src/construct/domain_layer/domain/scene/scene_graph/root/SceneRoot.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,4 @@ | ||
let getSceneGameObject = () => { | ||
DpContainer.unsafeGetSceneRepoDp().getSceneGameObject() | ||
->GameObjectEntity.create; | ||
}; |
6 changes: 4 additions & 2 deletions
6
...domain_layer/domain/scene/scene_graph/service/gameObject/AllRenderGameObjectsDoService.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
5 changes: 5 additions & 0 deletions
5
...main_layer/domain/scene/scene_graph/service/gameObject/GetComponentGameObjectDoService.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,5 @@ | ||
let getTransform = gameObject => | ||
DpContainer.unsafeGetGameObjectRepoDp().getTransform( | ||
gameObject->GameObjectEntity.value, | ||
) | ||
->OptionSt.map(TransformEntity.create); |
56 changes: 40 additions & 16 deletions
56
...ruct/domain_layer/domain/scene/scene_graph/service/transform/OperateTransformDoService.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 |
---|---|---|
@@ -1,33 +1,57 @@ | ||
open SceneGraphType; | ||
|
||
let getLocalPosition = ({localPosition}) => { | ||
localPosition->PositionVO.create; | ||
let getLocalPosition = transform => { | ||
DpContainer.unsafeGetTransformRepoDp().getLocalPosition( | ||
transform->TransformEntity.value, | ||
) | ||
->PositionVO.create; | ||
}; | ||
|
||
let getLocalRotation = ({localRotation}) => { | ||
localRotation->RotationVO.create; | ||
let getLocalRotation = transform => { | ||
DpContainer.unsafeGetTransformRepoDp().getLocalRotation( | ||
transform->TransformEntity.value, | ||
) | ||
->RotationVO.create; | ||
}; | ||
|
||
let getLocalScale = ({localScale}) => { | ||
localScale->ScaleVO.create; | ||
let getLocalScale = transform => { | ||
DpContainer.unsafeGetTransformRepoDp().getLocalScale( | ||
transform->TransformEntity.value, | ||
) | ||
->ScaleVO.create; | ||
}; | ||
|
||
let getPosition = ({worldPosition}) => { | ||
worldPosition->PositionVO.create; | ||
let getPosition = transform => { | ||
DpContainer.unsafeGetTransformRepoDp().getPosition( | ||
transform->TransformEntity.value, | ||
) | ||
->PositionVO.create; | ||
}; | ||
|
||
let getRotation = ({worldRotation}) => { | ||
worldRotation->RotationVO.create; | ||
let getRotation = transform => { | ||
DpContainer.unsafeGetTransformRepoDp().getRotation( | ||
transform->TransformEntity.value, | ||
) | ||
->RotationVO.create; | ||
}; | ||
|
||
let getScale = ({worldScale}) => { | ||
worldScale->ScaleVO.create; | ||
let getScale = transform => { | ||
DpContainer.unsafeGetTransformRepoDp().getScale( | ||
transform->TransformEntity.value, | ||
) | ||
->ScaleVO.create; | ||
}; | ||
|
||
let getLocalToWorldMatrix = ({localToWorldMatrix}) => { | ||
localToWorldMatrix->LocalToWorldMatrixVO.create; | ||
let getLocalToWorldMatrix = transform => { | ||
DpContainer.unsafeGetTransformRepoDp().getLocalToWorldMatrix( | ||
transform->TransformEntity.value, | ||
) | ||
->LocalToWorldMatrixVO.create; | ||
}; | ||
|
||
let getNormalMatrix = ({normalMatrix}) => { | ||
normalMatrix->NormalMatrixVO.create; | ||
let getNormalMatrix = transform => { | ||
DpContainer.unsafeGetTransformRepoDp().getNormalMatrix( | ||
transform->TransformEntity.value, | ||
) | ||
->NormalMatrixVO.create; | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
let getAllRenderGameObjects = () => { | ||
GameObjectApService.getAllRenderGameObjects(); | ||
let getAllRenderGameObjects = sceneGameObject => { | ||
GameObjectApService.getAllRenderGameObjects(sceneGameObject); | ||
}; | ||
|
||
let getTransform = gameObject => { | ||
GameObjectApService.getTransform(gameObject); | ||
}; |
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,3 @@ | ||
let getSceneGameObject = () => { | ||
SceneApService.getSceneGameObject(); | ||
}; |
24 changes: 22 additions & 2 deletions
24
src/run/external_layer/api/dependency/SceneGraphRepoDpCPAPI.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 |
---|---|---|
@@ -1,3 +1,23 @@ | ||
let set = dp => { | ||
SceneGraphRepoDpRunAPI.set(dp); | ||
open SceneGraphRepoDpCPType; | ||
|
||
let set = | ||
( | ||
{sceneRepo, gameObjectRepo, transformRepo}: SceneGraphRepoDpCPType.sceneGraphRepo, | ||
) => { | ||
let {getTransform, getAllGeometryGameObjects} = gameObjectRepo; | ||
|
||
SceneGraphRepoDpRunAPI.set( | ||
{ | ||
sceneRepo, | ||
gameObjectRepo: { | ||
getTransform: gameObject => { | ||
getTransform(gameObject)->OptionSt.fromNullable; | ||
}, | ||
getAllGeometryGameObjects: sceneGameObject => { | ||
getAllGeometryGameObjects(sceneGameObject)->ListSt.fromArray; | ||
}, | ||
}, | ||
transformRepo, | ||
}: ISceneGraphRepoDp.sceneGraphRepo, | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
src/run/external_layer/api/dependency/vo/SceneGraphRepoDpCPType.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,16 @@ | ||
open SceneGraphType; | ||
|
||
type sceneRepo = ISceneGraphRepoDp.sceneRepo; | ||
|
||
type gameObjectRepo = { | ||
getTransform: gameObject => Js.Nullable.t(transform), | ||
getAllGeometryGameObjects: gameObject => array(gameObject), | ||
}; | ||
|
||
type transformRepo = ISceneGraphRepoDp.transformRepo; | ||
|
||
type sceneGraphRepo = { | ||
sceneRepo, | ||
transformRepo, | ||
gameObjectRepo, | ||
}; |