Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
45802697
T
three.js
项目概览
Ablesons
/
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,体验更适合开发者的 AI 搜索 >>
提交
45802697
编写于
4月 03, 2020
作者:
M
Mugen87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Examples: Add integer attributes demo.
上级
7918de9c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
172 addition
and
0 deletion
+172
-0
examples/files.js
examples/files.js
+1
-0
examples/webgl2_buffergeometry_attributes_integer.html
examples/webgl2_buffergeometry_attributes_integer.html
+171
-0
未找到文件。
examples/files.js
浏览文件 @
45802697
...
...
@@ -310,6 +310,7 @@ var files = {
"
webgl_worker_offscreencanvas
"
],
"
webgl2
"
:
[
"
webgl2_buffergeometry_attributes_integer
"
,
"
webgl2_materials_texture2darray
"
,
"
webgl2_materials_texture3d
"
,
"
webgl2_multisampled_renderbuffers
"
,
...
...
examples/webgl2_buffergeometry_attributes_integer.html
0 → 100644
浏览文件 @
45802697
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js WebGL 2 - buffergeometry - integer attributes
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<link
type=
"text/css"
rel=
"stylesheet"
href=
"main.css"
>
</head>
<body>
<div
id=
"container"
></div>
<div
id=
"info"
><a
href=
"https://threejs.org"
target=
"_blank"
rel=
"noopener"
>
three.js
</a>
WebGL 2 - buffergeometry - integer attributes
</div>
<script
id=
"vertexShader"
type=
"x-shader/x-vertex"
>
#
version
300
es
in
int
textureIndex
;
flat
out
int
vIndex
;
// "flat" indicates that the value will not be interpolated (required for integer attributes)
out
vec2
vUv
;
void
main
()
{
vIndex
=
textureIndex
;
vUv
=
uv
;
gl_Position
=
projectionMatrix
*
modelViewMatrix
*
vec4
(
position
,
1.0
);
}
</script>
<script
id=
"fragmentShader"
type=
"x-shader/x-fragment"
>
#
version
300
es
flat
in
int
vIndex
;
in
vec2
vUv
;
uniform
sampler2D
uTextures
[
3
];
out
vec4
outColor
;
void
main
()
{
if
(
vIndex
==
0
)
outColor
=
texture
(
uTextures
[
0
],
vUv
);
else
if
(
vIndex
==
1
)
outColor
=
texture
(
uTextures
[
1
],
vUv
);
else
if
(
vIndex
==
2
)
outColor
=
texture
(
uTextures
[
2
],
vUv
);
}
</script>
<script
type=
"module"
>
import
*
as
THREE
from
'
../build/three.module.js
'
;
var
camera
,
scene
,
renderer
,
mesh
;
init
();
animate
();
function
init
()
{
camera
=
new
THREE
.
PerspectiveCamera
(
27
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
3500
);
camera
.
position
.
z
=
2500
;
scene
=
new
THREE
.
Scene
();
scene
.
background
=
new
THREE
.
Color
(
0x050505
);
scene
.
fog
=
new
THREE
.
Fog
(
0x050505
,
2000
,
3500
);
// geometry
var
triangles
=
10000
;
var
geometry
=
new
THREE
.
BufferGeometry
();
var
positions
=
[];
var
uvs
=
[];
var
textureIndices
=
[];
var
n
=
800
,
n2
=
n
/
2
;
// triangles spread in the cube
var
d
=
50
,
d2
=
d
/
2
;
// individual triangle size
for
(
var
i
=
0
;
i
<
triangles
;
i
++
)
{
// positions
var
x
=
Math
.
random
()
*
n
-
n2
;
var
y
=
Math
.
random
()
*
n
-
n2
;
var
z
=
Math
.
random
()
*
n
-
n2
;
var
ax
=
x
+
Math
.
random
()
*
d
-
d2
;
var
ay
=
y
+
Math
.
random
()
*
d
-
d2
;
var
az
=
z
+
Math
.
random
()
*
d
-
d2
;
var
bx
=
x
+
Math
.
random
()
*
d
-
d2
;
var
by
=
y
+
Math
.
random
()
*
d
-
d2
;
var
bz
=
z
+
Math
.
random
()
*
d
-
d2
;
var
cx
=
x
+
Math
.
random
()
*
d
-
d2
;
var
cy
=
y
+
Math
.
random
()
*
d
-
d2
;
var
cz
=
z
+
Math
.
random
()
*
d
-
d2
;
positions
.
push
(
ax
,
ay
,
az
);
positions
.
push
(
bx
,
by
,
bz
);
positions
.
push
(
cx
,
cy
,
cz
);
// uvs
uvs
.
push
(
0
,
0
);
uvs
.
push
(
0.5
,
1
);
uvs
.
push
(
1
,
0
);
// texture indices
var
t
=
i
%
3
;
textureIndices
.
push
(
t
,
t
,
t
);
}
geometry
.
setAttribute
(
'
position
'
,
new
THREE
.
Float32BufferAttribute
(
positions
,
3
)
);
geometry
.
setAttribute
(
'
uv
'
,
new
THREE
.
Float32BufferAttribute
(
uvs
,
2
)
);
geometry
.
setAttribute
(
'
textureIndex
'
,
new
THREE
.
Int32BufferAttribute
(
textureIndices
,
1
)
);
geometry
.
computeBoundingSphere
();
// material
var
loader
=
new
THREE
.
TextureLoader
();
var
map1
=
loader
.
load
(
'
textures/crate.gif
'
);
var
map2
=
loader
.
load
(
'
textures/floors/FloorsCheckerboard_S_Diffuse.jpg
'
);
var
map3
=
loader
.
load
(
'
textures/terrain/grasslight-big.jpg
'
);
var
material
=
new
THREE
.
ShaderMaterial
(
{
uniforms
:
{
uTextures
:
{
value
:
[
map1
,
map2
,
map3
]
}
},
vertexShader
:
document
.
getElementById
(
'
vertexShader
'
).
textContent
,
fragmentShader
:
document
.
getElementById
(
'
fragmentShader
'
).
textContent
,
side
:
THREE
.
DoubleSide
}
);
// mesh
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
scene
.
add
(
mesh
);
// renderer
var
canvas
=
document
.
createElement
(
'
canvas
'
);
var
context
=
canvas
.
getContext
(
'
webgl2
'
,
{
alpha
:
false
}
);
renderer
=
new
THREE
.
WebGLRenderer
(
{
canvas
:
canvas
,
context
:
context
}
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
document
.
body
.
appendChild
(
renderer
.
domElement
);
}
function
animate
()
{
requestAnimationFrame
(
animate
);
var
time
=
Date
.
now
()
*
0.001
;
mesh
.
rotation
.
x
=
time
*
0.25
;
mesh
.
rotation
.
y
=
time
*
0.5
;
renderer
.
render
(
scene
,
camera
);
}
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录