@ridp/threejs 0.2.0 → 1.1.0
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.
- package/dist/ImageLoader-CB_URfeZ.js +860 -0
- package/dist/ImageLoader-DwvBWW6h.cjs +5 -0
- package/dist/common-BHi3qsZW.cjs +15 -0
- package/dist/{common-DESmndxO.js → common-fbJUHqlj.js} +1 -1
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +7 -9
- package/dist/threejs.cjs +1 -1
- package/dist/threejs.js +17 -15
- package/dist/useGLTFLoader-DHxBLucO.js +5629 -0
- package/dist/useGLTFLoader-DM3-7jdq.cjs +4 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +15 -12
- package/esdoc/ast/source/.external-ecmascript.js.json +2802 -0
- package/esdoc/ast/source/hooks/index.js.json +739 -0
- package/esdoc/ast/source/hooks/useGLTFLoader.js.json +9111 -0
- package/esdoc/ast/source/hooks/useObb.js.json +16463 -0
- package/esdoc/ast/source/hooks/useRaycaster.js.json +15556 -0
- package/esdoc/ast/source/hooks/useThreeJs.js.json +52887 -0
- package/esdoc/ast/source/index.js.json +570 -0
- package/esdoc/ast/source/instance/IDBCache.js.json +40978 -0
- package/esdoc/ast/source/instance/index.js.json +232 -0
- package/esdoc/ast/source/utils/ImageLoader.js.json +7037 -0
- package/esdoc/ast/source/utils/common.js.json +5134 -0
- package/esdoc/ast/source/utils/css3dHelper.js.json +9101 -0
- package/esdoc/ast/source/utils/disposeObject.js.json +5978 -0
- package/esdoc/ast/source/utils/helper.js.json +10522 -0
- package/esdoc/ast/source/utils/index.js.json +908 -0
- package/esdoc/badge.svg +17 -0
- package/esdoc/class/src/instance/IDBCache.js~IDBCache.html +1299 -0
- package/esdoc/coverage.json +86 -0
- package/esdoc/css/github.css +83 -0
- package/esdoc/css/identifiers.css +37 -0
- package/esdoc/css/manual.css +134 -0
- package/esdoc/css/prettify-tomorrow.css +132 -0
- package/esdoc/css/search.css +84 -0
- package/esdoc/css/source.css +55 -0
- package/esdoc/css/style.css +608 -0
- package/esdoc/css/test.css +58 -0
- package/esdoc/file/src/hooks/index.js.html +79 -0
- package/esdoc/file/src/hooks/useGLTFLoader.js.html +146 -0
- package/esdoc/file/src/hooks/useObb.js.html +149 -0
- package/esdoc/file/src/hooks/useRaycaster.js.html +153 -0
- package/esdoc/file/src/hooks/useThreeJs.js.html +362 -0
- package/esdoc/file/src/index.js.html +78 -0
- package/esdoc/file/src/instance/IDBCache.js.html +312 -0
- package/esdoc/file/src/instance/index.js.html +76 -0
- package/esdoc/file/src/utils/ImageLoader.js.html +118 -0
- package/esdoc/file/src/utils/common.js.html +102 -0
- package/esdoc/file/src/utils/css3dHelper.js.html +131 -0
- package/esdoc/file/src/utils/disposeObject.js.html +114 -0
- package/esdoc/file/src/utils/helper.js.html +138 -0
- package/esdoc/file/src/utils/index.js.html +80 -0
- package/esdoc/function/index.html +2019 -0
- package/esdoc/identifiers.html +738 -0
- package/esdoc/image/badge.svg +17 -0
- package/esdoc/image/esdoc-logo-mini-black.png +0 -0
- package/esdoc/image/esdoc-logo-mini.png +0 -0
- package/esdoc/image/manual-badge.svg +17 -0
- package/esdoc/image/search.png +0 -0
- package/esdoc/index.html +153 -0
- package/esdoc/index.json +2051 -0
- package/esdoc/inject/css/0-cus-style.css +1 -0
- package/esdoc/lint.json +1 -0
- package/esdoc/script/inherited-summary.js +28 -0
- package/esdoc/script/inner-link.js +32 -0
- package/esdoc/script/manual.js +12 -0
- package/esdoc/script/patch-for-local.js +8 -0
- package/esdoc/script/prettify/Apache-License-2.0.txt +202 -0
- package/esdoc/script/prettify/prettify.js +46 -0
- package/esdoc/script/pretty-print.js +25 -0
- package/esdoc/script/search.js +117 -0
- package/esdoc/script/search_index.js +572 -0
- package/esdoc/script/test-summary.js +54 -0
- package/esdoc/source.html +213 -0
- package/esdoc/variable/index.html +225 -0
- package/package.json +13 -3
- package/readme.md +93 -0
- package/dist/common-nMt4tIRA.cjs +0 -15
- package/dist/disposeObject-BuI3II7v.cjs +0 -1
- package/dist/disposeObject-CmFSSgi7.js +0 -616
- package/dist/useGLTFLoader-BAoIZjEX.js +0 -2645
- package/dist/useGLTFLoader-CGOxhEOO.cjs +0 -6
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<base data-ice="baseUrl" href="../../../">
|
|
6
|
+
<title data-ice="title">src/hooks/index.js | @ridp/threejs</title>
|
|
7
|
+
<link type="text/css" rel="stylesheet" href="css/style.css">
|
|
8
|
+
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
|
|
9
|
+
<script src="script/prettify/prettify.js"></script>
|
|
10
|
+
<script src="script/manual.js"></script>
|
|
11
|
+
<link rel="stylesheet" href="./inject/css/0-cus-style.css"></head>
|
|
12
|
+
<body class="layout-container" data-ice="rootContainer">
|
|
13
|
+
|
|
14
|
+
<header>
|
|
15
|
+
<a href="./">Home</a>
|
|
16
|
+
|
|
17
|
+
<a href="identifiers.html">Reference</a>
|
|
18
|
+
<a href="source.html">Source</a>
|
|
19
|
+
|
|
20
|
+
<div class="search-box">
|
|
21
|
+
<span>
|
|
22
|
+
<img src="./image/search.png">
|
|
23
|
+
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
|
|
24
|
+
</span>
|
|
25
|
+
<ul class="search-result"></ul>
|
|
26
|
+
</div>
|
|
27
|
+
</header>
|
|
28
|
+
|
|
29
|
+
<nav class="navigation" data-ice="nav"><div>
|
|
30
|
+
<ul>
|
|
31
|
+
|
|
32
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#hooks">hooks</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useGLTFLoader">useGLTFLoader</a></span></span></li>
|
|
33
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useObb">useObb</a></span></span></li>
|
|
34
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useRaycaster">useRaycaster</a></span></span></li>
|
|
35
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useThreeJs">useThreeJs</a></span></span></li>
|
|
36
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-intersectColor">intersectColor</a></span></span></li>
|
|
37
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-obbObjects">obbObjects</a></span></span></li>
|
|
38
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#instance">instance</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/instance/IDBCache.js~IDBCache.html">IDBCache</a></span></span></li>
|
|
39
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#utils">utils</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-ImageLoader">ImageLoader</a></span></span></li>
|
|
40
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-initEnvImage">initEnvImage</a></span></span></li>
|
|
41
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getCommonParent">getCommonParent</a></span></span></li>
|
|
42
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createInfoPlane">createInfoPlane</a></span></span></li>
|
|
43
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createTagPlane">createTagPlane</a></span></span></li>
|
|
44
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-disposeThreeObject">disposeThreeObject</a></span></span></li>
|
|
45
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createArrowHelper">createArrowHelper</a></span></span></li>
|
|
46
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createAxesHelper">createAxesHelper</a></span></span></li>
|
|
47
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createBox3Helper">createBox3Helper</a></span></span></li>
|
|
48
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createCameraHelper">createCameraHelper</a></span></span></li>
|
|
49
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createGridHelper">createGridHelper</a></span></span></li>
|
|
50
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createMapControls">createMapControls</a></span></span></li>
|
|
51
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createOrbitControl">createOrbitControl</a></span></span></li>
|
|
52
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createRaycaster">createRaycaster</a></span></span></li>
|
|
53
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createStats">createStats</a></span></span></li>
|
|
54
|
+
</ul>
|
|
55
|
+
</div>
|
|
56
|
+
</nav>
|
|
57
|
+
|
|
58
|
+
<div class="content" data-ice="content"><h1 data-ice="title">src/hooks/index.js</h1>
|
|
59
|
+
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">export * from "./useThreeJs";
|
|
60
|
+
export * from "./useRaycaster";
|
|
61
|
+
export * from "./useObb";
|
|
62
|
+
export * from "./useGLTFLoader";
|
|
63
|
+
</code></pre>
|
|
64
|
+
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<footer class="footer">
|
|
68
|
+
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
|
|
69
|
+
</footer>
|
|
70
|
+
|
|
71
|
+
<script src="script/search_index.js"></script>
|
|
72
|
+
<script src="script/search.js"></script>
|
|
73
|
+
<script src="script/pretty-print.js"></script>
|
|
74
|
+
<script src="script/inherited-summary.js"></script>
|
|
75
|
+
<script src="script/test-summary.js"></script>
|
|
76
|
+
<script src="script/inner-link.js"></script>
|
|
77
|
+
<script src="script/patch-for-local.js"></script>
|
|
78
|
+
</body>
|
|
79
|
+
</html>
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<base data-ice="baseUrl" href="../../../">
|
|
6
|
+
<title data-ice="title">src/hooks/useGLTFLoader.js | @ridp/threejs</title>
|
|
7
|
+
<link type="text/css" rel="stylesheet" href="css/style.css">
|
|
8
|
+
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
|
|
9
|
+
<script src="script/prettify/prettify.js"></script>
|
|
10
|
+
<script src="script/manual.js"></script>
|
|
11
|
+
<link rel="stylesheet" href="./inject/css/0-cus-style.css"></head>
|
|
12
|
+
<body class="layout-container" data-ice="rootContainer">
|
|
13
|
+
|
|
14
|
+
<header>
|
|
15
|
+
<a href="./">Home</a>
|
|
16
|
+
|
|
17
|
+
<a href="identifiers.html">Reference</a>
|
|
18
|
+
<a href="source.html">Source</a>
|
|
19
|
+
|
|
20
|
+
<div class="search-box">
|
|
21
|
+
<span>
|
|
22
|
+
<img src="./image/search.png">
|
|
23
|
+
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
|
|
24
|
+
</span>
|
|
25
|
+
<ul class="search-result"></ul>
|
|
26
|
+
</div>
|
|
27
|
+
</header>
|
|
28
|
+
|
|
29
|
+
<nav class="navigation" data-ice="nav"><div>
|
|
30
|
+
<ul>
|
|
31
|
+
|
|
32
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#hooks">hooks</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useGLTFLoader">useGLTFLoader</a></span></span></li>
|
|
33
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useObb">useObb</a></span></span></li>
|
|
34
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useRaycaster">useRaycaster</a></span></span></li>
|
|
35
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useThreeJs">useThreeJs</a></span></span></li>
|
|
36
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-intersectColor">intersectColor</a></span></span></li>
|
|
37
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-obbObjects">obbObjects</a></span></span></li>
|
|
38
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#instance">instance</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/instance/IDBCache.js~IDBCache.html">IDBCache</a></span></span></li>
|
|
39
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#utils">utils</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-ImageLoader">ImageLoader</a></span></span></li>
|
|
40
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-initEnvImage">initEnvImage</a></span></span></li>
|
|
41
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getCommonParent">getCommonParent</a></span></span></li>
|
|
42
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createInfoPlane">createInfoPlane</a></span></span></li>
|
|
43
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createTagPlane">createTagPlane</a></span></span></li>
|
|
44
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-disposeThreeObject">disposeThreeObject</a></span></span></li>
|
|
45
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createArrowHelper">createArrowHelper</a></span></span></li>
|
|
46
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createAxesHelper">createAxesHelper</a></span></span></li>
|
|
47
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createBox3Helper">createBox3Helper</a></span></span></li>
|
|
48
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createCameraHelper">createCameraHelper</a></span></span></li>
|
|
49
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createGridHelper">createGridHelper</a></span></span></li>
|
|
50
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createMapControls">createMapControls</a></span></span></li>
|
|
51
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createOrbitControl">createOrbitControl</a></span></span></li>
|
|
52
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createRaycaster">createRaycaster</a></span></span></li>
|
|
53
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createStats">createStats</a></span></span></li>
|
|
54
|
+
</ul>
|
|
55
|
+
</div>
|
|
56
|
+
</nav>
|
|
57
|
+
|
|
58
|
+
<div class="content" data-ice="content"><h1 data-ice="title">src/hooks/useGLTFLoader.js</h1>
|
|
59
|
+
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
|
|
60
|
+
import { DRACOLoader } from "three/addons/loaders/DRACOLoader.js";
|
|
61
|
+
import { IDBCache } from "../instance/IDBCache";
|
|
62
|
+
|
|
63
|
+
/** @type { IDBCache } */
|
|
64
|
+
let idbCache;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* GLTFLoader 模型加载器
|
|
68
|
+
* @returns { Object }
|
|
69
|
+
* @property { Function } load - 模型加载方法
|
|
70
|
+
* @property { Function } asyncLoad - Promise 形式异步加载模型方法
|
|
71
|
+
* @property { Function } asyncCacheLoad - Promise 形式异步加载模型并缓存方法
|
|
72
|
+
*/
|
|
73
|
+
export const useGLTFLoader = () => {
|
|
74
|
+
const loader = new GLTFLoader();
|
|
75
|
+
const dracoLoader = new DRACOLoader();
|
|
76
|
+
dracoLoader.setDecoderPath(`/draco/`);
|
|
77
|
+
loader.setDRACOLoader(dracoLoader);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 模型加载
|
|
81
|
+
* @param { String } path - 模型路径
|
|
82
|
+
* @param {Function} onLoad - 加载完成回调
|
|
83
|
+
* @param {Function} onProgress - 进度回调
|
|
84
|
+
* @param {Function} onError - 错误回调
|
|
85
|
+
* @returns { GLTFLoader.load }
|
|
86
|
+
*/
|
|
87
|
+
function load(path, onLoad, onProgress, onError) {
|
|
88
|
+
return loader.load(path, onLoad, onProgress, onError);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Promise 形式异步加载模型
|
|
93
|
+
* @param {String} path - 模型路径
|
|
94
|
+
* @param {Function} onProgress - 进度回调
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
97
|
+
function asyncLoad(path, onProgress) {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
loader.load(path, resolve, onProgress, reject);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Promise 形式异步加载模型并缓存
|
|
105
|
+
* 使用IndexDb 对加载后的模型文件进行缓存
|
|
106
|
+
* 二次访问时直接从缓存中加载, 减少网络请求
|
|
107
|
+
* @param {*} path - 模型路径
|
|
108
|
+
* @param {*} onProgress - 进度回调
|
|
109
|
+
* @returns { Object3D }
|
|
110
|
+
*/
|
|
111
|
+
async function asyncCacheLoad(path, onProgress) {
|
|
112
|
+
if (!idbCache) idbCache = new IDBCache();
|
|
113
|
+
const cacheObj = await idbCache.loadCachedModel(path);
|
|
114
|
+
if (cacheObj) return cacheObj;
|
|
115
|
+
|
|
116
|
+
return new Promise((resolve, reject) => {
|
|
117
|
+
loader.load(path, resolve, onProgress, reject);
|
|
118
|
+
}).then(async (model) => {
|
|
119
|
+
await idbCache.cacheModel(path, model.scene);
|
|
120
|
+
return model;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
load,
|
|
126
|
+
asyncLoad,
|
|
127
|
+
asyncCacheLoad,
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
</code></pre>
|
|
131
|
+
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<footer class="footer">
|
|
135
|
+
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
|
|
136
|
+
</footer>
|
|
137
|
+
|
|
138
|
+
<script src="script/search_index.js"></script>
|
|
139
|
+
<script src="script/search.js"></script>
|
|
140
|
+
<script src="script/pretty-print.js"></script>
|
|
141
|
+
<script src="script/inherited-summary.js"></script>
|
|
142
|
+
<script src="script/test-summary.js"></script>
|
|
143
|
+
<script src="script/inner-link.js"></script>
|
|
144
|
+
<script src="script/patch-for-local.js"></script>
|
|
145
|
+
</body>
|
|
146
|
+
</html>
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<base data-ice="baseUrl" href="../../../">
|
|
6
|
+
<title data-ice="title">src/hooks/useObb.js | @ridp/threejs</title>
|
|
7
|
+
<link type="text/css" rel="stylesheet" href="css/style.css">
|
|
8
|
+
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
|
|
9
|
+
<script src="script/prettify/prettify.js"></script>
|
|
10
|
+
<script src="script/manual.js"></script>
|
|
11
|
+
<link rel="stylesheet" href="./inject/css/0-cus-style.css"></head>
|
|
12
|
+
<body class="layout-container" data-ice="rootContainer">
|
|
13
|
+
|
|
14
|
+
<header>
|
|
15
|
+
<a href="./">Home</a>
|
|
16
|
+
|
|
17
|
+
<a href="identifiers.html">Reference</a>
|
|
18
|
+
<a href="source.html">Source</a>
|
|
19
|
+
|
|
20
|
+
<div class="search-box">
|
|
21
|
+
<span>
|
|
22
|
+
<img src="./image/search.png">
|
|
23
|
+
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
|
|
24
|
+
</span>
|
|
25
|
+
<ul class="search-result"></ul>
|
|
26
|
+
</div>
|
|
27
|
+
</header>
|
|
28
|
+
|
|
29
|
+
<nav class="navigation" data-ice="nav"><div>
|
|
30
|
+
<ul>
|
|
31
|
+
|
|
32
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#hooks">hooks</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useGLTFLoader">useGLTFLoader</a></span></span></li>
|
|
33
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useObb">useObb</a></span></span></li>
|
|
34
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useRaycaster">useRaycaster</a></span></span></li>
|
|
35
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useThreeJs">useThreeJs</a></span></span></li>
|
|
36
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-intersectColor">intersectColor</a></span></span></li>
|
|
37
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-obbObjects">obbObjects</a></span></span></li>
|
|
38
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#instance">instance</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/instance/IDBCache.js~IDBCache.html">IDBCache</a></span></span></li>
|
|
39
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#utils">utils</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-ImageLoader">ImageLoader</a></span></span></li>
|
|
40
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-initEnvImage">initEnvImage</a></span></span></li>
|
|
41
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getCommonParent">getCommonParent</a></span></span></li>
|
|
42
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createInfoPlane">createInfoPlane</a></span></span></li>
|
|
43
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createTagPlane">createTagPlane</a></span></span></li>
|
|
44
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-disposeThreeObject">disposeThreeObject</a></span></span></li>
|
|
45
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createArrowHelper">createArrowHelper</a></span></span></li>
|
|
46
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createAxesHelper">createAxesHelper</a></span></span></li>
|
|
47
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createBox3Helper">createBox3Helper</a></span></span></li>
|
|
48
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createCameraHelper">createCameraHelper</a></span></span></li>
|
|
49
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createGridHelper">createGridHelper</a></span></span></li>
|
|
50
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createMapControls">createMapControls</a></span></span></li>
|
|
51
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createOrbitControl">createOrbitControl</a></span></span></li>
|
|
52
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createRaycaster">createRaycaster</a></span></span></li>
|
|
53
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createStats">createStats</a></span></span></li>
|
|
54
|
+
</ul>
|
|
55
|
+
</div>
|
|
56
|
+
</nav>
|
|
57
|
+
|
|
58
|
+
<div class="content" data-ice="content"><h1 data-ice="title">src/hooks/useObb.js</h1>
|
|
59
|
+
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import { Color, Box3, Vector3 } from 'three'
|
|
60
|
+
import { OBB } from 'three/addons'
|
|
61
|
+
|
|
62
|
+
// 按parentUid存储obb对象, 用于碰撞检测
|
|
63
|
+
export const obbObjects = []
|
|
64
|
+
export const intersectColor = new Color(0xff0000)
|
|
65
|
+
|
|
66
|
+
export const useObb = () => {
|
|
67
|
+
const resetObbs = () => {
|
|
68
|
+
obbObjects.splice(0)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const initObb = (parentUid, model) => {
|
|
72
|
+
model.traverse((child) => {
|
|
73
|
+
// 需要碰撞检测的标记
|
|
74
|
+
child && initSingleObbItem(parentUid, child)
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const initSingleObbItem = (parentUid, model) => {
|
|
79
|
+
if (model.userData.needCheck) {
|
|
80
|
+
model.autoUpdateMatrix = false
|
|
81
|
+
model.updateMatrix()
|
|
82
|
+
model.updateMatrixWorld()
|
|
83
|
+
if (model.isMesh) {
|
|
84
|
+
const box3 = new Box3(new Vector3()).setFromObject(model)
|
|
85
|
+
|
|
86
|
+
model.geometry.userData.obb = new OBB()
|
|
87
|
+
model.geometry.userData.obb.halfSize.copy(box3.getSize(new Vector3())).multiplyScalar(0.5).multiplyScalar(0.88)
|
|
88
|
+
model.userData.obb = new OBB()
|
|
89
|
+
|
|
90
|
+
model.userData.originColor = model.material.color.clone()
|
|
91
|
+
model.userData.parentUid = parentUid
|
|
92
|
+
|
|
93
|
+
obbObjects.push({
|
|
94
|
+
object: model,
|
|
95
|
+
parentUid: parentUid
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const addObbFromArray = (parentUid, arr) => {
|
|
102
|
+
for (let i = 0, il = arr.length; i < il; i++) {
|
|
103
|
+
initSingleObbItem(parentUid, arr[i])
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const getObbObjectByParentUid = (parentUid) => {
|
|
108
|
+
return obbObjects.filter((item) => item.parentUid === parentUid)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const removeObbFromArray = (obbs) => {
|
|
112
|
+
const list = obbObjects.filter((item) => !obbs.includes(item.object))
|
|
113
|
+
obbObjects.splice(0, obbObjects.length, ...list)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const removeUidObb = (parentUid) => {
|
|
117
|
+
for (let i = obbObjects.length - 1; i >= 0; i--) {
|
|
118
|
+
if (obbObjects[i].parentUid === parentUid) {
|
|
119
|
+
obbObjects.splice(i, 1)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
resetObbs,
|
|
126
|
+
initObb,
|
|
127
|
+
getObbObjectByParentUid,
|
|
128
|
+
addObbFromArray,
|
|
129
|
+
removeObbFromArray,
|
|
130
|
+
removeUidObb
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
</code></pre>
|
|
134
|
+
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<footer class="footer">
|
|
138
|
+
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
|
|
139
|
+
</footer>
|
|
140
|
+
|
|
141
|
+
<script src="script/search_index.js"></script>
|
|
142
|
+
<script src="script/search.js"></script>
|
|
143
|
+
<script src="script/pretty-print.js"></script>
|
|
144
|
+
<script src="script/inherited-summary.js"></script>
|
|
145
|
+
<script src="script/test-summary.js"></script>
|
|
146
|
+
<script src="script/inner-link.js"></script>
|
|
147
|
+
<script src="script/patch-for-local.js"></script>
|
|
148
|
+
</body>
|
|
149
|
+
</html>
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<base data-ice="baseUrl" href="../../../">
|
|
6
|
+
<title data-ice="title">src/hooks/useRaycaster.js | @ridp/threejs</title>
|
|
7
|
+
<link type="text/css" rel="stylesheet" href="css/style.css">
|
|
8
|
+
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
|
|
9
|
+
<script src="script/prettify/prettify.js"></script>
|
|
10
|
+
<script src="script/manual.js"></script>
|
|
11
|
+
<link rel="stylesheet" href="./inject/css/0-cus-style.css"></head>
|
|
12
|
+
<body class="layout-container" data-ice="rootContainer">
|
|
13
|
+
|
|
14
|
+
<header>
|
|
15
|
+
<a href="./">Home</a>
|
|
16
|
+
|
|
17
|
+
<a href="identifiers.html">Reference</a>
|
|
18
|
+
<a href="source.html">Source</a>
|
|
19
|
+
|
|
20
|
+
<div class="search-box">
|
|
21
|
+
<span>
|
|
22
|
+
<img src="./image/search.png">
|
|
23
|
+
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
|
|
24
|
+
</span>
|
|
25
|
+
<ul class="search-result"></ul>
|
|
26
|
+
</div>
|
|
27
|
+
</header>
|
|
28
|
+
|
|
29
|
+
<nav class="navigation" data-ice="nav"><div>
|
|
30
|
+
<ul>
|
|
31
|
+
|
|
32
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#hooks">hooks</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useGLTFLoader">useGLTFLoader</a></span></span></li>
|
|
33
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useObb">useObb</a></span></span></li>
|
|
34
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useRaycaster">useRaycaster</a></span></span></li>
|
|
35
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-useThreeJs">useThreeJs</a></span></span></li>
|
|
36
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-intersectColor">intersectColor</a></span></span></li>
|
|
37
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-obbObjects">obbObjects</a></span></span></li>
|
|
38
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#instance">instance</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/instance/IDBCache.js~IDBCache.html">IDBCache</a></span></span></li>
|
|
39
|
+
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#utils">utils</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-ImageLoader">ImageLoader</a></span></span></li>
|
|
40
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-initEnvImage">initEnvImage</a></span></span></li>
|
|
41
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getCommonParent">getCommonParent</a></span></span></li>
|
|
42
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createInfoPlane">createInfoPlane</a></span></span></li>
|
|
43
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createTagPlane">createTagPlane</a></span></span></li>
|
|
44
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-disposeThreeObject">disposeThreeObject</a></span></span></li>
|
|
45
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createArrowHelper">createArrowHelper</a></span></span></li>
|
|
46
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createAxesHelper">createAxesHelper</a></span></span></li>
|
|
47
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createBox3Helper">createBox3Helper</a></span></span></li>
|
|
48
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createCameraHelper">createCameraHelper</a></span></span></li>
|
|
49
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createGridHelper">createGridHelper</a></span></span></li>
|
|
50
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createMapControls">createMapControls</a></span></span></li>
|
|
51
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createOrbitControl">createOrbitControl</a></span></span></li>
|
|
52
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createRaycaster">createRaycaster</a></span></span></li>
|
|
53
|
+
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createStats">createStats</a></span></span></li>
|
|
54
|
+
</ul>
|
|
55
|
+
</div>
|
|
56
|
+
</nav>
|
|
57
|
+
|
|
58
|
+
<div class="content" data-ice="content"><h1 data-ice="title">src/hooks/useRaycaster.js</h1>
|
|
59
|
+
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import { Raycaster, Vector2 } from "three";
|
|
60
|
+
|
|
61
|
+
// Raycaster
|
|
62
|
+
export const useRaycaster = (appId = "app") => {
|
|
63
|
+
const raycaster = new Raycaster();
|
|
64
|
+
raycaster.params.Line.threshold = 8;
|
|
65
|
+
const pointer = new Vector2();
|
|
66
|
+
|
|
67
|
+
const $app = document.getElementById(appId);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 获取鼠标坐标
|
|
71
|
+
* @param {*} event HtmlEvent
|
|
72
|
+
* @param {*} container HTMLDomElement
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
function getPointer(event, container) {
|
|
76
|
+
const { scaleX, scaleY } = getScale($app);
|
|
77
|
+
const { clientWidth, clientHeight } = container;
|
|
78
|
+
const size = container.getBoundingClientRect();
|
|
79
|
+
|
|
80
|
+
const realDomWidth = clientWidth * scaleX;
|
|
81
|
+
const realDomHeight = clientHeight * scaleY;
|
|
82
|
+
|
|
83
|
+
const x = event.clientX - size.left;
|
|
84
|
+
const y = event.clientY - size.top;
|
|
85
|
+
pointer.x = ((event.clientX - size.left) / realDomWidth) * 2 - 1;
|
|
86
|
+
pointer.y = -((event.clientY - size.top) / realDomHeight) * 2 + 1;
|
|
87
|
+
return { pointer, x, y };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 获取鼠标捕获的对象
|
|
92
|
+
* @param {*} event HtmlEvent
|
|
93
|
+
* @param {*} renderDom renderer.domElement
|
|
94
|
+
* @param {*} camera Camera
|
|
95
|
+
* @param {*} catchObjects Objects3D[]
|
|
96
|
+
* @returns Objects3D[] || null
|
|
97
|
+
*/
|
|
98
|
+
function getIntersects(event, renderDom, camera, catchObjects) {
|
|
99
|
+
const { pointer, x, y } = getPointer(event, renderDom);
|
|
100
|
+
raycaster.setFromCamera(pointer, camera);
|
|
101
|
+
const intersects = raycaster.intersectObjects(catchObjects);
|
|
102
|
+
return { intersects, pointer, x, y };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 获取 DOM 的缩放比例
|
|
107
|
+
* @param {*} element
|
|
108
|
+
* @returns
|
|
109
|
+
*/
|
|
110
|
+
function getScale(element) {
|
|
111
|
+
const style = window.getComputedStyle(element);
|
|
112
|
+
const transform =
|
|
113
|
+
style.transform || style.webkitTransform || style.mozTransform;
|
|
114
|
+
|
|
115
|
+
if (transform && transform !== "none") {
|
|
116
|
+
const matrix = transform.match(/^matrix\((.+)\)$/);
|
|
117
|
+
if (matrix) {
|
|
118
|
+
const values = matrix[1].split(", ");
|
|
119
|
+
const scaleX = parseFloat(values[0]);
|
|
120
|
+
const scaleY = parseFloat(values[3]);
|
|
121
|
+
return { scaleX, scaleY };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// 如果没有缩放,返回默认值
|
|
125
|
+
return { scaleX: 1, scaleY: 1 };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
raycaster,
|
|
130
|
+
pointer,
|
|
131
|
+
|
|
132
|
+
getPointer,
|
|
133
|
+
getScale,
|
|
134
|
+
getIntersects,
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
</code></pre>
|
|
138
|
+
|
|
139
|
+
</div>
|
|
140
|
+
|
|
141
|
+
<footer class="footer">
|
|
142
|
+
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
|
|
143
|
+
</footer>
|
|
144
|
+
|
|
145
|
+
<script src="script/search_index.js"></script>
|
|
146
|
+
<script src="script/search.js"></script>
|
|
147
|
+
<script src="script/pretty-print.js"></script>
|
|
148
|
+
<script src="script/inherited-summary.js"></script>
|
|
149
|
+
<script src="script/test-summary.js"></script>
|
|
150
|
+
<script src="script/inner-link.js"></script>
|
|
151
|
+
<script src="script/patch-for-local.js"></script>
|
|
152
|
+
</body>
|
|
153
|
+
</html>
|