{"id":34170,"date":"2024-11-25T17:08:00","date_gmt":"2024-11-25T09:08:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34170\/"},"modified":"2024-11-25T17:08:00","modified_gmt":"2024-11-25T09:08:00","slug":"%e6%b5%85%e6%9e%90%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%b8%ad%e8%a6%81%e6%80%8e%e4%b9%88%e7%94%a8threejs","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34170\/","title":{"rendered":"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs"},"content":{"rendered":"<p>\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\uff1f\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u548c\u5927\u5bb6\u4e00\u8d77\u804a\u804a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u4f7f\u7528threejs\u7684\u65b9\u6cd5\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/024\/61c52e3f1bd1d955.jpg\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe\" \/><\/p>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u672c\u8eab\u63d0\u4f9b\u4e86\u9002\u914d\u7248\uff0c\u4f46\u662f\u7248\u672c\u592a\u65e7\u4e86, \u800c\u4e14\u9002\u914d\u7684\u4e0d\u5168\uff0c\u5c1d\u8bd5\u81ea\u5df1\u624b\u52a8\u9002\u914d\u4e00\u4e0b\u3002 \u8fd9\u662f\u5b98\u65b9\u9002\u914dthreejs\u7684github\u94fe\u63a5https:\/\/github.com\/wechat-miniprogram\/threejs-miniprogram<\/p>\n<h2><strong>\u6548\u679c\u5c55\u793a<\/strong><\/h2>\n<p>\u9002\u914d\u540e\u7684\u5c0f\u7a0b\u5e8f\u4ee3\u7801\u7247\u6bb5<br \/>https:\/\/developers.weixin.qq.com\/s\/y5tDPImr7xvs<\/p>\n<h2><strong>1. \u7b80\u5355\u4f7f\u7528<\/strong><\/h2>\n<p>GitHub\u5730\u5740: https:\/\/github.com\/mrdoob\/three.js\uff0c\u5c06\u6574\u4e2a\u9879\u76ee\u62c9\u4e0b\u6765\uff0c\u540e\u9762\u9700\u8981\u4fee\u6539\u5176\u4e2d\u7684\u4ee3\u7801\u3002build\u76ee\u5f55\u4e0b\u5df2\u6709\u4e09\u4e2a\u7f16\u8bd1\u597d\u7684\u6587\u4ef6\uff0c\u7531\u4e8e\u5927\u5c0f\u8d85\u8fc7500k,\u4f1a\u8df3\u8fc7es6\u8f6ces5,\u4e0d\u80fd\u4f7f\u7528three.module.js,\u4e3a\u4e86\u8c03\u8bd5\u65b9\u4fbf\u770b\u62a5\u9519\u7684\u4f4d\u7f6e,\u5c06\u672a\u538b\u7f29\u7684three.js\u653e\u5230\u9879\u76ee\u4e2d\u3002\u5c1d\u8bd5\u5f15\u7528\u3002<\/p>\n<pre>import&nbsp;*&nbsp;as&nbsp;THREE&nbsp;from&nbsp;'..\/libs\/three.js'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u62a5\u9519\uff01\uff01\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/484\/126\/437\/1640311891680605.jpg\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe1\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe1\" \/><\/p>\n<p>\u7ecf\u8fc7\u6d4b\u8bd5\uff0c\u662f\u57fa\u7840\u5e93\u6700\u65b0\u51e0\u4e2a\u7248\u672c\u7684bug, \u7ed9\u5fae\u4fe1\u5b98\u65b9\u53cd\u9988\u4e86\uff0c\u53cd\u9988\u5730\u5740\uff08https:\/\/developers.weixin.qq.com\/community\/develop\/doc\/0002ca77aa420880162d1b08d5b800\uff09\uff0c\u5b98\u65b9\u4eba\u5458\u89e3\u51b3\u95ee\u9898\u5f88\u5feb\uff0c<\/p>\n<p>\u5176\u5b9e\uff0c\u4e0d\u89e3\u51b3\u4e5f\u4e0d\u5f71\u54cd\uff0c\u8c03\u4f4e\u7248\u672c\u5e93\u7248\u672c\u52302.19.6\u6216\u4f7f\u7528require\u5bfc\u5165\u4e5f\u53ef\u4ee5\u89e3\u51b3<\/p>\n<h3><strong>\u89e3\u51b3\u62a5\u9519<\/strong><\/h3>\n<h4><strong>\u95ee\u98981 \u7531\u4e8e\u53c2\u8003\u7684\u4ee3\u7801\u592a\u65e7\u4e86\uff0c\u62a5\u4e86\u4e00\u4e2aCubeGeometry\u7684\u9519\u8bef<\/strong><\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/244\/985\/752\/1640311894751667.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe2\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe2\" \/><\/p>\n<p>\u67e5\u627e\u53d1\u73b0\u8fd9\u4e2aCubeGeometry\u65e9\u6539\u540d\u4e86<\/p>\n<p>\u66f4\u65b0\u65e5\u5fd7\uff1ahttps:\/\/github.com\/mrdoob\/three.js\/wiki\/Migration-Guide<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/469\/895\/821\/1640311899683484.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe3\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe3\" \/><\/p>\n<h4><strong>\u95ee\u98982 addEventListener\u62a5\u9519<\/strong><\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/521\/242\/321\/1640311904358324.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe4\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe4\" \/><\/p>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6ca1\u6709addEventListener\uff0c\u4f1a\u81ea\u52a8\u7ba1\u7406canvas\u7684\u91cd\u8f7d\uff0c\u6ce8\u91ca\u6389three.js\u4e2d\u4e0b\u9762\u7684\u4ee3\u7801<\/p>\n<pre>_canvas.addEventListener('webglcontextlost',&nbsp;onContextLost,&nbsp;false);\n_canvas.addEventListener('webglcontextrestored',&nbsp;onContextRestore,&nbsp;false);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4><strong>\u95ee\u98983 canvas type\u6709\u95ee\u9898<\/strong><\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/136\/287\/776\/1640311908124429.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe5\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe5\" \/><\/p>\n<p>\u4ed4\u7ec6\u67e5\u770b\u4ee3\u7801\u53d1\u73b0\u662f_canvas.getContext\u8fd9\u91cc\u62a5\u9519\u4e86\uff0c\u7c7b\u578b\u6539\u4e3awebgl\u3002<\/p>\n<pre>const&nbsp;context&nbsp;=&nbsp;_canvas.getContext('webgl',&nbsp;contextAttributes);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684canvas\u6709\u4e24\u79cd\u4f7f\u7528\u65b9\u5f0f\uff0cwebgl\u548c2d\uff0c2d\u4e0d\u4ee3\u8868\u662fwebgl2,<\/p>\n<pre>const&nbsp;contextNames&nbsp;=&nbsp;['webgl2',&nbsp;'webgl',&nbsp;'experimental-webgl'];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u800c\u4e14contextNames\u91cc\u6ca1\u67092d\uff0c\u4ee3\u7801\u91cc\u53ea\u6709\u56fe\u7247\u76f8\u5173\u7684\u65b9\u6cd5\u7528\u5230\u4e862d\u3002 \u89e3\u51b3\u5b8c\u4e0a\u9762\u7684\u95ee\u9898\uff0c\u5c31\u80fd\u8dd1\u8d77\u6765\u4e86\u3002<\/p>\n<h3>\u5c55\u793a<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/255\/103\/306\/1640311912209778.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe6\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe6\" \/><\/p>\n<p>\u624b\u673a\u8c03\u8bd5\u65f6\u53d1\u73b0\u4e00\u4e2a\u8b66\u544a,EXT_blend_minmax\u6269\u5c55\u4e0d\u652f\u6301,\u770b\u4ee3\u7801\u662f\u5728threejs\u91cc\u9762\u62a5\u7684\u9519\u8bef\u3002\u4ed4\u7ec6\u67e5\u627e\u4e00\u756a<\/p>\n<p>MDN\u5730\u5740\uff1ahttps:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/EXT_blend_minmax<\/p>\n<p>\u53d1\u73b0\u8fd9\u5c31\u662f\u4e24\u4e2a\u5e38\u91cf\uff0c\u800c\u4e14\u5728webgl2\u4e2d\u662f\u9ed8\u8ba4\u652f\u6301\u4e86\uff0c<\/p>\n<pre>interface&nbsp;EXT_blend_minmax&nbsp;{\n&nbsp;&nbsp;const&nbsp;GLenum&nbsp;MIN_EXT&nbsp;=&nbsp;0x8007;\n&nbsp;&nbsp;const&nbsp;GLenum&nbsp;MAX_EXT&nbsp;=&nbsp;0x8008;\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u53ef\u4ee5\u5728\u4ee3\u7801\u91cc\u76f4\u63a5\u6539\u4e3a\u5bf9\u5e94\u7684\u503c\uff0c\u8b66\u544a\u60f3\u53bb\u6389\u7684\u8bdd\u572812551\u884c\u5de6\u53f3<\/p>\n<h2><strong>2. \u4f7f\u7528TextureLoader<\/strong><\/h2>\n<h3><strong>\u89e3\u51b3\u62a5\u9519<\/strong><\/h3>\n<h4><strong>\u95ee\u98981 createElementNS<\/strong><\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/421\/918\/364\/1640311917335406.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe7\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe7\" \/><\/p>\n<p>\u4ed4\u7ec6\u770b\u4e00\u4e0b\u903b\u8f91: TextureLoader -&gt; ImageLoader -&gt;createElementNS<\/p>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6ca1\u6709createElementNS\uff0c\u627e\u4e86\u4e00\u5708\u53d1\u73b0\u6709\u4e2a\u66ff\u4ee3\u65b9\u6cd5\uff0c\u5c31\u662fcanvas\u7684createImage\uff0c\u4f46\u662fcanvas\u53bb\u54ea\u62ff\uff0c\u6ca1\u6709\u65b9\u6cd5\u80fd\u76f4\u63a5\u521b\u5efa\uff0c\u4e3a\u4e86\u65b9\u4fbf\uff0c\u76f4\u63a5\u5728new TextureLoader\u7684\u65f6\u5019\u4f20\u8fdb\u53bb\uff0c\u6ce8\u610f\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u6709\u610f\u4e49\u7684\uff0c\u4f20\u7a7a\u5373\u53ef<\/p>\n<pre>const&nbsp;texture&nbsp;=&nbsp;new&nbsp;THREE.TextureLoader(undefined,&nbsp;canvas)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3><strong>\u5c55\u793a<\/strong><\/h3>\n<p>\u89e3\u51b3\uff0c\u53ef\u4ee5\u4f7f\u7528Texture\u4e86<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/318\/395\/479\/1640311922627093.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe8\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe8\" \/><\/p>\n<h2><strong>3. \u4f7f\u7528OrbitControls<\/strong><\/h2>\n<h3><strong>\u89e3\u51b3\u62a5\u9519<\/strong><\/h3>\n<h4><strong>\u95ee\u98981 addEventListener<\/strong><\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/765\/644\/254\/1640311928762613.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe9\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe9\" \/><\/p>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6ca1\u6709addEventListener\uff0c\u4f46\u662f\u53ef\u4ee5\u5728canvas\u4e0a\u7ed1\u5b9a\u4e8b\u4ef6,\u4ed4\u7ec6\u770bpoint event\u548c\u5c0f\u7a0b\u5e8f\u5bf9\u5e94\u7684\u4e8b\u4ef6<\/p>\n<pre>contextmenu&nbsp;\/\/&nbsp;\u9f20\u6807\u53f3\u952e\nwheel&nbsp;\/\/&nbsp;\u6eda\u8f6e\u6eda\u52a8\nkeydown&nbsp;\/\/&nbsp;\u952e\u76d8\u4e8b\u4ef6\n\/\/&nbsp;\u9700\u8981\u8fdb\u884c\u9002\u914d\u7684\npointerdown&nbsp;&nbsp;-&amp;gt;&nbsp;&nbsp;touchstart\npointermove&nbsp;&nbsp;-&amp;gt;&nbsp;&nbsp;touchmove\npointerup&nbsp;&nbsp;&nbsp;&nbsp;-&amp;gt;&nbsp;&nbsp;touchend<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4><strong>\u95ee\u98982 \u4e8b\u4ef6\u89e6\u53d1\u540e\u600e\u4e48\u901a\u77e5OrbitControls<\/strong><\/h4>\n<p>\u4e8b\u4ef6\u6709\u4e86\uff0c\u600e\u4e48\u901a\u77e5\u5462\uff1f\u4e24\u4e2a\u65b9\u6cd5\u6ca1\u6709\u4efb\u4f55\u8054\u7cfb\uff0c\u53ea\u80fd\u7528eventbus\u4e86\uff0ceventbus\u53ef\u4ee5\u81ea\u5df1\u5199\u4e2a\u7b80\u5355\u7684 &nbsp;\u3002<br \/>index.js\uff08\u89e6\u53d1\uff09<\/p>\n<pre>&nbsp;&nbsp;onTouchStart(e)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;EventBus.dispatchEvent(e)\n&nbsp;&nbsp;},\n&nbsp;&nbsp;onTouchMove(e)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;EventBus.dispatchEvent(e)\n&nbsp;&nbsp;},\n&nbsp;&nbsp;onTouchEnd(e)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;EventBus.dispatchEvent(e)\n&nbsp;&nbsp;},<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>OrbitControls.js \uff08\u76d1\u542c\uff09<\/p>\n<pre>EventBus.addEventListener(&nbsp;'touchstart',&nbsp;onPointerDown&nbsp;);\nEventBus.addEventListener(&nbsp;'touchend',&nbsp;onPointerUp&nbsp;);\nEventBus.addEventListener(&nbsp;'touchmove',&nbsp;onPointerMove);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4><strong>\u95ee\u98983 \u89e6\u6478\u4e8b\u4ef6\u89e6\u53d1\u7684\u53c2\u6570\u95ee\u9898\uff0c\u5c0f\u7a0b\u5e8f\u4e8b\u4ef6\u89e6\u53d1\u62ff\u5230\u7684\u53c2\u6570\u548ch5\u62ff\u5230\u7684\u6570\u636e\u683c\u5f0f\u4e0d\u4e00\u81f4\uff0c\u9700\u8981\u8c03\u6574\u3002<\/strong><\/h4>\n<p>\u627e\u4e86\u534a\u5929\uff0c\u53d1\u73b0\u5fae\u4fe1\u5c0f\u6e38\u620f\u8fd9\u8fb9\u6709\u4e00\u4e9b\u9002\u914d\u597d\u7684\u4e1c\u897f\uff0c<\/p>\n<p>\u8fd8\u6709\u8fd9\u4e2a\u6587\u7ae0\u91cc\u8001\u54e5\u81ea\u5df1\u5199\u7684\u5e93\u5e94\u8be5\u662f\u6309\u7167\u4e0a\u9762\u5fae\u4fe1\u5c0f\u6e38\u620f\u7684\u9002\u914d\u5e93\u6539\u7684<\/p>\n<p>\u6211\u662f\u76f4\u63a5\u7528TouchEvent\uff0c\u770b\u5982\u4f55\u6539\u6210pointEvent<\/p>\n<h4><strong>\u95ee\u98984 \u65e0\u6cd5\u65cb\u8f6c<\/strong><\/h4>\n<p>\u770b\u6253\u5370\uff0c\u5e94\u8be5\u662f\u67d0\u4e9b\u53c2\u6570\u6709\u95ee\u9898\uff0c\u5bfc\u81f4scope.object.position\u8ba1\u7b97\u4e3aNaN\uff0c<\/p>\n<p>\u6392\u67e5\u8fc7\u7a0b\uff1a<\/p>\n<p>position -&gt; offset -&gt; spherical -&gt; sphericalDelta -&gt; clientHeight<\/p>\n<p>clientHeight\u548cclientWidth\u9700\u8981\u8d4b\u503c<\/p>\n<pre>&nbsp;&nbsp;canvas.clientHeight&nbsp;=&nbsp;canvas.height\n&nbsp;&nbsp;canvas.clientWidth&nbsp;=&nbsp;canvas.width;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4><strong>\u95ee\u98984 \u65e0\u6cd5\u7f29\u653e<\/strong><\/h4>\n<p>\u770b\u6253\u5370\uff0c\u8fd8\u662fscope.object.position\u8ba1\u7b97\u4e3aNaN<\/p>\n<p>\u6392\u67e5\u8fc7\u7a0b\uff1a<\/p>\n<p>position -&gt; offset -&gt; spherical.radius -&gt; scale -&gt; pointers<\/p>\n<p>\u53d1\u73b0pointerId\u5c5e\u6027\u7f3a\u5c11\uff0c\u5c0f\u7a0b\u5e8f\u4e8b\u4ef6\u6709\u8fd4\u56deidentifier\uff0c\u5c31\u662fpointerId<\/p>\n<p>\u603b\u5171\u4fee\u6539\u7684\u5c5e\u6027\uff1a<\/p>\n<pre>1.timeStamp\n2.&nbsp;pointerType&nbsp;\u53d6touch\n3.&nbsp;\u591a\u70b9\u89e6\u6478\u65f6\u70b9\u51fb\u53d6touches\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\n4.&nbsp;pointerId&nbsp;&nbsp;identifier&nbsp;\u591a\u70b9\u89e6\u6478\u65f6\u6807\u8bc6\u662f\u67d0\u4e2a\u70b9\u51fb\n5.&nbsp;clientHeight<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2><strong>4 \u4f7f\u7528OBJLoader<\/strong><\/h2>\n<h3><strong>\u89e3\u51b3\u62a5\u9519<\/strong><\/h3>\n<h4><strong>\u95ee\u98981 Request\u548cfetch\u4e3aundefined<\/strong><\/h4>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u53ea\u6709wx.request,\u521a\u597d\u4e0a\u9762\u6211\u4eec\u53d1\u73b0\u6709\u4e2aXMLHttpRequest.js\u7684\u9002\u914d\u6587\u4ef6\uff0c\u53ef\u4ee5\u7528\uff0c\u5c1d\u8bd5\u540e\u53d1\u73b0\u6ca1\u6cd5\u76f4\u63a5\u7528\uff0c\u9700\u8981\u7f16\u8bd1\u6210es5\u3002 \u6211\u4eec\u7b2c\u4e00\u6b65\u5c31\u62c9\u4e86\u6574\u4e2athreejs\u9879\u76ee\u7684\u4ee3\u7801\uff0c\u91cc\u9762\u6709\u53ef\u4ee5\u91cd\u65b0\u7f16\u8bd1\u7684\u547d\u4ee4\uff0c\u6211\u4eec\u53ef\u4ee5\u628aXMLHttpRequest\u590d\u5236\u8fc7\u53bb\uff0c\u4fee\u6539\u4f7f\u7528\uff0c\u518d\u8fdb\u884c\u7f16\u8bd1\uff0c \u4e3b\u8981\u4fee\u6539\u7684\u65b9\u6cd5:<\/p>\n<pre>const&nbsp;request&nbsp;=&nbsp;new&nbsp;XMLHttpRequest();\nrequest.open('GET',&nbsp;url);\nrequest.onreadystatechange&nbsp;=&nbsp;function&nbsp;()&nbsp;{}\nrequest.onerror()\nrequest.send()<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4><strong>\u95ee\u98982 \u6a21\u578b\u9ed8\u8ba4\u663e\u793a\u592a\u5c0f\u4e86\uff0c<\/strong><\/h4>\n<p>\u4ee5\u4e3a\u662f\u8fd8\u6ca1\u9002\u914d\u597d\uff0c\u52a0\u8f7d\u6709\u95ee\u9898\uff0c\u770b\u4e86\u8001\u534a\u5929\u624d\u53d1\u73b0\u5df2\u7ecf\u663e\u793a\u4e86\uff0c\u5c31\u662f\u592a\u5c0f\u4e86\uff0c \u89e3\u51b3\u65b9\u6cd5\uff1a\u653e\u5927<\/p>\n<pre>roup.scale.set(30,30,30)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4><strong>\u95ee\u98983 \u6a21\u578b\u663e\u793a\u5f88\u6697\uff0c\u9700\u8981\u628a\u706f\u5149\u5f3a\u5ea6\u8c03\u5230\u5f88\u9ad8\u624d\u80fd\u770b\u6e05<\/strong><\/h4>\n<p>\u770b\u793a\u4f8b\u662f\u8fd9\u884c\u4ee3\u7801\u6ca1\u52a0<\/p>\n<pre>renderer.outputEncoding&nbsp;=&nbsp;THREE.sRGBEncoding;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7a0d\u5fae\u4e86\u89e3\u4e86\u4e00\u4e0b\u989c\u8272\u7a7a\u95f4\u7684\u6982\u5ff5:<br \/>\u7ebf\u6027\u7a7a\u95f4: \u673a\u5668\u5bf9\u4eae\u5ea6\u7684\u611f\u53d7<br \/>\u975e\u7ebf\u6027(Gamma): \u4eba\u5bf9\u4eae\u5ea6\u7684\u611f\u53d7<\/p>\n<p>\u6d41\u7a0b: &nbsp;sRGB(\u5bfc\u5165\u7684\u56fe\u7247) -&gt; linear(\u5904\u7406\u65f6) -&gt; sRGB(\u8f93\u51fa\u5c55\u793a)<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/316\/218\/475\/1640311937191717.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe10\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe10\" \/><\/p>\n<p>\u4e0a\u56fe\u4e2d\uff0c\u4e0b\u9762\u7684\u5b9e\u7ebf\u662f\u5b9e\u9645\u663e\u793a\u5668\u7684\u4eae\u5ea6\u548c\u989c\u8272\u7684\u7cfb\u6570\u56fe\uff0c\u5982\u679c\u6ca1\u6709\u8bef\u5dee\uff0c\u662f\u4e0d\u9700\u8981gamma\u6821\u6b63\u7684\uff0c \u4f46\u5b9e\u9645\u4e0a\u7ebf\u6027\u7a7a\u95f4\u91cc\u8ba1\u7b97\u51fa\u6765\u7684\u5149\u7167\u7684\u4e2d\u95f4\u4eae\u5ea6\u90e8\u5206\u4f1a\u88ab\u538b\u6697\uff0c\u6240\u4ee5\u9700\u8981\u7ecf\u8fc7Gamma\u6821\u6b63\uff0c\u8c03\u9ad8\u539f\u6709\u7684\u503c\u8fdb\u884c\u663e\u793a\u3002<\/p>\n<blockquote><p>\n  \u53c2\u8003\u6587\u7ae0https:\/\/www.cnblogs.com\/guanzz\/p\/7416821.htmlhttps:\/\/cloud.tencent.com\/developer\/article\/1543647\n<\/p><\/blockquote>\n<h3><strong>\u5c55\u793a<\/strong><\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/205\/272\/746\/1640311941770249.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe11\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe11\" \/><\/p>\n<h2><strong>5 \u771f\u673a\u8c03\u8bd5<\/strong><\/h2>\n<p>\u771f\u673a\u8c03\u8bd52.0\u652f\u6301canvas<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/575\/830\/162\/1640311948659792.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe12\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe12\" \/><\/p>\n<h3><strong>\u89e3\u51b3\u95ee\u9898<\/strong><\/h3>\n<h4><strong>\u95ee\u98981 \u6a21\u578b\u592a\u5927<\/strong><\/h4>\n<p>\u53ea\u80fd\u653e\u5230\u7ebf\u4e0a\uff0c\u653e\u5230GitHub\u4e0a\uff0c\u53ef\u4ee5\u8bbf\u95eeraw.githubusercontent.com\u8bf7\u6c42\u5230\u8d44\u6e90<\/p>\n<h4><strong>\u95ee\u98982 githubusercontent\u8bbf\u95ee\u4e0d\u7a33\u5b9a\uff0c\u7ecf\u5e38\u6302<\/strong><\/h4>\n<p>\u653e\u5230\u7801\u4e91\u4e0a\uff0c\u7801\u4e91\u540c\u6837\u6709raw\u5730\u5740\u53ef\u4ee5\u8bbf\u95ee\u5230\u8d44\u6e90<\/p>\n<h4><strong>\u95ee\u98983 \u7801\u4e91\u5927\u4e8e1m\u7684\u8d44\u6e90\u9700\u8981\u767b\u5f55<\/strong><\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/881\/841\/732\/1640311953432975.png\" class=\"aligncenter\" title=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe13\" alt=\"\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u63d2\u56fe13\" \/><\/p>\n<p>\u6700\u540e\u9009\u62e9\u4f7f\u7528\u67d0\u4e91\uff0c\u6709\u514d\u8d39\u7a7a\u95f4\u53ef\u4ee5\u7528\u3002\u5c31\u662f\u5982\u679c\u6ca1\u6709\u81ea\u5df1\u57df\u540d\u7684\u8bdd\uff0c\u6d4b\u8bd5\u57df\u540d\u53ea\u6709\u4e00\u4e2a\u6708\u7684\u6709\u6548\u671f\uff0c\u521a\u597d\u4e4b\u524d\u7533\u8bf7\u4e86\u4e2a\u57df\u540d\uff0c\u7ed1\u5b9a\uff0c\u4fee\u6539cname, \u628a\u6a21\u578b\u4f20\u5230\u4e0a\u53bb\uff0c\u53ef\u4ee5\u8bbf\u95ee\uff0c\u7533\u8bf7\u514d\u8d39\u7684\u8bc1\u4e66\uff0chttps\u53ef\u4ee5\u8bbf\u95ee\uff0c\u641e\u5b9a<\/p>\n<h2><strong>\u603b\u7ed3<\/strong><\/h2>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u9002\u914dthreejs\u7684\u6ce8\u610f\u70b9\uff1a<\/p>\n<ul>\n<li>\n<p>\u4e8b\u4ef6\u7cfb\u7edf\uff0c\u4e8b\u4ef6\u89e6\u53d1\u548c\u4e8b\u4ef6\u53c2\u6570<\/p>\n<\/li>\n<li>\n<p>\u8bf7\u6c42\uff0c<\/p>\n<\/li>\n<li>\n<p>doucment\u4e0a\u7684\u5c5e\u6027\u9002\u914d<\/p>\n<\/li>\n<li>\n<p>canvas\u4e0a\u7684\u5c5e\u6027\u9002\u914d<\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u67e5\u627e\u76f8\u5173\u95ee\u9898\u65f6\u53d1\u73b0\u4e86\u4e0b\u9762\u8fd9\u4f4d\u5927\u4f6c\uff0cthreejs\u914d\u5957\u7684\u57fa\u672c\u90fd\u9002\u914d\u4e86, \u8fd8\u6709demo\u5c55\u793a\uff0c\u63a8\u8350\u770b\u4e00\u4e0bhttps:\/\/github.com\/deepkolos\/three-platformize<\/p>\n<p>\u3010\u76f8\u5173\u5b66\u4e60\u63a8\u8350\uff1a\u3011<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6d45\u6790\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u7a0b\u5e8f\u4e2d\u8981\u600e\u4e48\u7528threejs\uff1f\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u548c\u5927\u5bb6\u4e00\u8d77\u804a\u804a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u4f7f\u7528threejs\u7684\u65b9\u6cd5\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\uff01 \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u672c\u8eab\u63d0\u4f9b\u4e86\u9002\u914d\u7248\uff0c\u4f46\u662f\u7248\u672c\u592a\u65e7\u4e86, \u800c\u4e14\u9002\u914d\u7684\u4e0d\u5168\uff0c\u5c1d\u8bd5\u81ea\u5df1\u624b\u52a8\u9002\u914d\u4e00\u4e0b\u3002 \u8fd9\u662f\u5b98\u65b9\u9002\u914dthreejs\u7684github\u94fe\u63a5https:\/\/github.com\/wechat-miniprogram\/threejs-miniprogram \u6548\u679c\u5c55\u793a \u9002\u914d\u540e\u7684\u5c0f\u7a0b\u5e8f\u4ee3\u7801\u7247\u6bb5https:\/\/developers.weixin.qq.com\/s\/y5tDPImr7xvs 1. \u7b80\u5355\u4f7f\u7528 GitHub\u5730\u5740: https:\/\/github.com\/mrdoob\/three.js\uff0c\u5c06\u6574\u4e2a\u9879\u76ee\u62c9\u4e0b\u6765\uff0c\u540e\u9762\u9700\u8981\u4fee\u6539\u5176\u4e2d\u7684\u4ee3\u7801\u3002build\u76ee\u5f55\u4e0b\u5df2\u6709\u4e09\u4e2a\u7f16\u8bd1\u597d\u7684\u6587\u4ef6\uff0c\u7531\u4e8e\u5927\u5c0f\u8d85\u8fc7500k,\u4f1a\u8df3\u8fc7es6\u8f6ces5,\u4e0d\u80fd\u4f7f\u7528three.module.js,\u4e3a\u4e86\u8c03\u8bd5\u65b9\u4fbf\u770b\u62a5\u9519\u7684\u4f4d\u7f6e,\u5c06\u672a\u538b\u7f29\u7684three.js\u653e\u5230\u9879\u76ee\u4e2d\u3002\u5c1d\u8bd5\u5f15\u7528\u3002 import&nbsp;*&nbsp;as&nbsp;THREE&nbsp;from&nbsp;&#8216;..\/libs\/three.js&#8217; \u767b\u5f55\u540e\u590d\u5236 \u62a5\u9519\uff01\uff01\uff01 \u7ecf\u8fc7\u6d4b\u8bd5\uff0c\u662f\u57fa\u7840\u5e93\u6700\u65b0\u51e0\u4e2a\u7248\u672c\u7684bug, \u7ed9\u5fae\u4fe1\u5b98\u65b9\u53cd\u9988\u4e86\uff0c\u53cd\u9988\u5730\u5740\uff08https:\/\/developers.weixin.qq.com\/community\/develop\/doc\/0002ca77aa420880162d1b08d5b800\uff09\uff0c\u5b98\u65b9\u4eba\u5458\u89e3\u51b3\u95ee\u9898\u5f88\u5feb\uff0c \u5176\u5b9e\uff0c\u4e0d\u89e3\u51b3\u4e5f\u4e0d\u5f71\u54cd\uff0c\u8c03\u4f4e\u7248\u672c\u5e93\u7248\u672c\u52302.19.6\u6216\u4f7f\u7528require\u5bfc\u5165\u4e5f\u53ef\u4ee5\u89e3\u51b3 \u89e3\u51b3\u62a5\u9519 \u95ee\u98981 \u7531\u4e8e\u53c2\u8003\u7684\u4ee3\u7801\u592a\u65e7\u4e86\uff0c\u62a5\u4e86\u4e00\u4e2aCubeGeometry\u7684\u9519\u8bef \u67e5\u627e\u53d1\u73b0\u8fd9\u4e2aCubeGeometry\u65e9\u6539\u540d\u4e86 \u66f4\u65b0\u65e5\u5fd7\uff1ahttps:\/\/github.com\/mrdoob\/three.js\/wiki\/Migration-Guide \u95ee\u98982 addEventListener\u62a5\u9519 \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6ca1\u6709addEventListener\uff0c\u4f1a\u81ea\u52a8\u7ba1\u7406canvas\u7684\u91cd\u8f7d\uff0c\u6ce8\u91ca\u6389three.js\u4e2d\u4e0b\u9762\u7684\u4ee3\u7801 _canvas.addEventListener(&#8216;webglcontextlost&#8217;,&nbsp;onContextLost,&nbsp;false); _canvas.addEventListener(&#8216;webglcontextrestored&#8217;,&nbsp;onContextRestore,&nbsp;false); \u767b\u5f55\u540e\u590d\u5236 \u95ee\u98983 canvas type\u6709\u95ee\u9898 \u4ed4\u7ec6\u67e5\u770b\u4ee3\u7801\u53d1\u73b0\u662f_canvas.getContext\u8fd9\u91cc\u62a5\u9519\u4e86\uff0c\u7c7b\u578b\u6539\u4e3awebgl\u3002 const&nbsp;context&nbsp;=&nbsp;_canvas.getContext(&#8216;webgl&#8217;,&nbsp;contextAttributes); \u767b\u5f55\u540e\u590d\u5236 \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684canvas\u6709\u4e24\u79cd\u4f7f\u7528\u65b9\u5f0f\uff0cwebgl\u548c2d\uff0c2d\u4e0d\u4ee3\u8868\u662fwebgl2, const&nbsp;contextNames&nbsp;=&nbsp;[&#8216;webgl2&#8217;,&nbsp;&#8216;webgl&#8217;,&nbsp;&#8216;experimental-webgl&#8217;]; \u767b\u5f55\u540e\u590d\u5236 \u800c\u4e14contextNames\u91cc\u6ca1\u67092d\uff0c\u4ee3\u7801\u91cc\u53ea\u6709\u56fe\u7247\u76f8\u5173\u7684\u65b9\u6cd5\u7528\u5230\u4e862d\u3002 \u89e3\u51b3\u5b8c\u4e0a\u9762\u7684\u95ee\u9898\uff0c\u5c31\u80fd\u8dd1\u8d77\u6765\u4e86\u3002 \u5c55\u793a \u624b\u673a\u8c03\u8bd5\u65f6\u53d1\u73b0\u4e00\u4e2a\u8b66\u544a,EXT_blend_minmax\u6269\u5c55\u4e0d\u652f\u6301,\u770b\u4ee3\u7801\u662f\u5728threejs\u91cc\u9762\u62a5\u7684\u9519\u8bef\u3002\u4ed4\u7ec6\u67e5\u627e\u4e00\u756a MDN\u5730\u5740\uff1ahttps:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/EXT_blend_minmax \u53d1\u73b0\u8fd9\u5c31\u662f\u4e24\u4e2a\u5e38\u91cf\uff0c\u800c\u4e14\u5728webgl2\u4e2d\u662f\u9ed8\u8ba4\u652f\u6301\u4e86\uff0c interface&nbsp;EXT_blend_minmax&nbsp;{ &nbsp;&nbsp;const&nbsp;GLenum&nbsp;MIN_EXT&nbsp;=&nbsp;0x8007; &nbsp;&nbsp;const&nbsp;GLenum&nbsp;MAX_EXT&nbsp;=&nbsp;0x8008; }; \u767b\u5f55\u540e\u590d\u5236 \u53ef\u4ee5\u5728\u4ee3\u7801\u91cc\u76f4\u63a5\u6539\u4e3a\u5bf9\u5e94\u7684\u503c\uff0c\u8b66\u544a\u60f3\u53bb\u6389\u7684\u8bdd\u572812551\u884c\u5de6\u53f3 2. \u4f7f\u7528TextureLoader \u89e3\u51b3\u62a5\u9519 \u95ee\u98981 createElementNS \u4ed4\u7ec6\u770b\u4e00\u4e0b\u903b\u8f91: TextureLoader [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-34170","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=34170"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34170\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}