Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
07089eff
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
07089eff
编写于
12月 24, 2016
作者:
L
Lewy Blue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added BufferGeometry section
上级
de541600
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
113 addition
and
31 deletion
+113
-31
docs/manual/introduction/How-to-update-things.html
docs/manual/introduction/How-to-update-things.html
+113
-31
未找到文件。
docs/manual/introduction/How-to-update-things.html
浏览文件 @
07089eff
...
...
@@ -34,24 +34,106 @@ object.updateMatrix();
<h2>
Geometries
</h2>
<div>
<p>
You can only update the content of buffers, you cannot resize buffers (this is very costly,
basically equivalent to creating new geometry).
</p>
<p>
You can emulate resizing by pre-allocating a larger buffer and then keeping unneeded vertices
collapsed / hidden.
</p>
<p>
The following flag control updating of various geometry attributes. Set flags only
for attributes that you need to update, updates are costly. Once buffers
change, these flags reset automatically back to false. You need to keep setting them to
true if you wanna keep updating buffers. Note that this applies only to [page:Geometry]
and not to [page:BufferGeometry].
</p>
<code>
<h3>
[page:BufferGeometry]
</h3>
<div>
<p>
BufferGeometries store information (such as vertex positions, face indices, normals, colors,
UVs, and any custom attributes) in [page:BufferAttribute buffers] - that is,
[link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays typed arrays].
This makes them generally faster than standard Geometries, at the cost of being somewhat harder to
work with.
</p>
<p>
With regards to updating BufferGeometries, the most important thing to understand is that you
you cannot resize buffers (this is very costly, basically the equivalent to creating new a geometry).
You can however update the content of buffers.
</p>
<p>
This means that if you know an attribute of you BufferGeometry will grow, say the number of vertices,
you must pre-allocate a buffer large enough to hold any new vertices that may be created. Of
course, this also means that there will be a maximum size for your BufferGeometry - there is
no way to create a BufferGeometry that can efficiently be extended indefinitely.
</p>
<p>
We'll use the example of a line that gets extended at render time. We'll allocate space
in the buffer for 500 vertices but draw only two at first, using [page:BufferGeometry.drawRange].
</p>
<code>
var MAX_POINTS = 500;
// geometry
var geometry = new THREE.BufferGeometry();
// attributes
var positions = new Float32Array( MAX_POINTS * 3 ); // 3 vertices per point
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
// draw range
drawCount = 2; // draw the first 2 points, only
geometry.setDrawRange( 0, drawCount );
// material
var material = new THREE.LineBasicMaterial( { color: 0xff0000, linewidth: 2 } );
// line
line = new THREE.Line( geometry, material );
scene.add( line );
</code>
<p>
Next we'll randomly add points to the line using a pattern like:
</p>
<code>
var positions = line.geometry.attributes.position.array;
var x = y = z = index = 0;
for ( var i = 0, l = MAX_POINTS; i
<
l
;
i
++
)
{
positions
[
index
++
] =
x;
positions
[
index
++
] =
y;
positions
[
index
++
] =
z;
x
+=
(
Math.random
()
-
0.5
)
*
30;
y
+=
(
Math.random
()
-
0.5
)
*
30;
z
+=
(
Math.random
()
-
0.5
)
*
30;
}
</
code
>
<p>
If you want to change the
<em>
number of points
</em>
rendered after the first render, do this:
</p>
<code>
line.geometry.setDrawRange( 0, newValue );
</code>
<p>
If you want to change the position data values after the first render, you need to
set the needsUpdate flag like so:
</p>
<code>
line.geometry.attributes.position.needsUpdate = true; // required after the first render
</code>
<p>
[link:http://jsfiddle.net/w67tzfhx/ Here is a fiddle] showing an animated line which you can adapt to your use case.
</p>
<h4>
Examples:
</h4>
[example:webgl_custom_attributes WebGL / custom / attributes]
<br
/>
[example:webgl_buffergeometry_custom_attributes_particles WebGL / buffergeometry / custom / attributes / particles]
</div>
<h3>
[page:Geometry]
</h3>
<div>
<p>
The following flag control updating of various geometry attributes. Set flags only
for attributes that you need to update, updates are costly. Once buffers
change, these flags reset automatically back to false. You need to keep setting them to
true if you wanna keep updating buffers. Note that this applies only to [page:Geometry]
and not to [page:BufferGeometry].
</p>
<code>
var geometry = new THREE.Geometry();
geometry.verticesNeedUpdate = true;
geometry.elementsNeedUpdate = true;
...
...
@@ -60,22 +142,22 @@ geometry.uvsNeedUpdate = true;
geometry.normalsNeedUpdate = true;
geometry.colorsNeedUpdate = true;
geometry.tangentsNeedUpdate = true;
</code>
</code>
<p>
In versions prior to [link:https://github.com/mrdoob/three.js/releases/tag/r66 r66] meshes
additionally need the
<em>
dynamic
</em>
flag enabled (to keep internal typed arrays):
</p>
<p>
In versions prior to [link:https://github.com/mrdoob/three.js/releases/tag/r66 r66] meshes
additionally need the
<em>
dynamic
</em>
flag enabled (to keep internal typed arrays):
</p>
<code>
//removed after r66
geometry.dynamic = true;
</code>
<code>
//removed after r66
geometry.dynamic = true;
</code>
<h4>
Example:
</h4>
[example:webgl_geometry_dynamic WebGL / geometry / dynamic]
<br
/>
</div>
<h3>
Examples:
</h3>
[example:webgl_geometry_dynamic WebGL / geometry / dynamic]
<br
/>
[example:webgl_custom_attributes WebGL / custom / attributes]
<br
/>
[example:webgl_custom_attributes_particles WebGL / custom / attributes / particles]
</div>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录