@xrift/world-components 0.30.0 → 0.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,10 @@ import { type Object3D } from 'three';
|
|
|
2
2
|
/**
|
|
3
3
|
* Y軸ビルボードフック
|
|
4
4
|
* 対象の Object3D を毎フレームカメラに向けてY軸のみ回転させる
|
|
5
|
+
* 親のワールド回転を考慮し、ローカル回転として正しい値を設定する
|
|
6
|
+
*
|
|
7
|
+
* sentinel Mesh の onBeforeRender を使用することで、
|
|
8
|
+
* Mirror(Reflector)の virtualCamera でも正しい回転が適用される
|
|
5
9
|
*/
|
|
6
10
|
export declare const useBillboardY: <T extends Object3D>() => import("react").RefObject<T>;
|
|
7
11
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/components/BillboardY/hooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/components/BillboardY/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,QAAQ,EAId,MAAM,OAAO,CAAA;AAed;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,QAAQ,mCA6C/C,CAAA"}
|
|
@@ -1,22 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Vector3 } from 'three';
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { BoxGeometry, Euler, Mesh, MeshBasicMaterial, Quaternion, Vector3, } from 'three';
|
|
4
3
|
import { getBillboardYRotation } from './utils';
|
|
5
4
|
const _cameraWorldPos = new Vector3();
|
|
6
5
|
const _targetWorldPos = new Vector3();
|
|
6
|
+
const _parentQuat = new Quaternion();
|
|
7
|
+
const _euler = new Euler();
|
|
8
|
+
const SENTINEL_GEOMETRY = new BoxGeometry(0.001, 0.001, 0.001);
|
|
9
|
+
const SENTINEL_MATERIAL = new MeshBasicMaterial({
|
|
10
|
+
colorWrite: false,
|
|
11
|
+
depthWrite: false,
|
|
12
|
+
depthTest: false,
|
|
13
|
+
});
|
|
7
14
|
/**
|
|
8
15
|
* Y軸ビルボードフック
|
|
9
16
|
* 対象の Object3D を毎フレームカメラに向けてY軸のみ回転させる
|
|
17
|
+
* 親のワールド回転を考慮し、ローカル回転として正しい値を設定する
|
|
18
|
+
*
|
|
19
|
+
* sentinel Mesh の onBeforeRender を使用することで、
|
|
20
|
+
* Mirror(Reflector)の virtualCamera でも正しい回転が適用される
|
|
10
21
|
*/
|
|
11
22
|
export const useBillboardY = () => {
|
|
12
23
|
const ref = useRef(null);
|
|
13
|
-
|
|
24
|
+
useEffect(() => {
|
|
14
25
|
if (!ref.current)
|
|
15
26
|
return;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
const target = ref.current;
|
|
28
|
+
const sentinel = new Mesh(SENTINEL_GEOMETRY, SENTINEL_MATERIAL);
|
|
29
|
+
sentinel.frustumCulled = false;
|
|
30
|
+
sentinel.renderOrder = -Infinity;
|
|
31
|
+
sentinel.onBeforeRender = (_renderer, _scene, camera) => {
|
|
32
|
+
camera.getWorldPosition(_cameraWorldPos);
|
|
33
|
+
target.getWorldPosition(_targetWorldPos);
|
|
34
|
+
const worldRotationY = getBillboardYRotation(_cameraWorldPos, _targetWorldPos);
|
|
35
|
+
if (target.parent) {
|
|
36
|
+
target.parent.getWorldQuaternion(_parentQuat);
|
|
37
|
+
_euler.setFromQuaternion(_parentQuat, 'YXZ');
|
|
38
|
+
target.rotation.y = worldRotationY - _euler.y;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
target.rotation.y = worldRotationY;
|
|
42
|
+
}
|
|
43
|
+
target.updateWorldMatrix(false, true);
|
|
44
|
+
};
|
|
45
|
+
target.add(sentinel);
|
|
46
|
+
return () => {
|
|
47
|
+
sentinel.onBeforeRender = () => { };
|
|
48
|
+
target.remove(sentinel);
|
|
49
|
+
};
|
|
50
|
+
}, []);
|
|
20
51
|
return ref;
|
|
21
52
|
};
|
|
22
53
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/components/BillboardY/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/components/BillboardY/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EACL,WAAW,EACX,KAAK,EACL,IAAI,EACJ,iBAAiB,EAEjB,UAAU,EAEV,OAAO,GACR,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAE/C,MAAM,eAAe,GAAG,IAAI,OAAO,EAAE,CAAA;AACrC,MAAM,eAAe,GAAG,IAAI,OAAO,EAAE,CAAA;AACrC,MAAM,WAAW,GAAG,IAAI,UAAU,EAAE,CAAA;AACpC,MAAM,MAAM,GAAG,IAAI,KAAK,EAAE,CAAA;AAE1B,MAAM,iBAAiB,GAAG,IAAI,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;AAC9D,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC;IAC9C,UAAU,EAAE,KAAK;IACjB,UAAU,EAAE,KAAK;IACjB,SAAS,EAAE,KAAK;CACjB,CAAC,CAAA;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAuB,EAAE;IACpD,MAAM,GAAG,GAAG,MAAM,CAAI,IAAI,CAAC,CAAA;IAE3B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,GAAG,CAAC,OAAO;YAAE,OAAM;QAExB,MAAM,MAAM,GAAG,GAAG,C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