Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
57fbfb77
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,发现更多精彩内容 >>
提交
57fbfb77
编写于
11月 20, 2019
作者:
W
webglzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remake InstanceMesh.raycast
上级
75fb3aa8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
53 addition
and
202 deletion
+53
-202
examples/files.js
examples/files.js
+0
-1
examples/webgl_instancing_morphtargets_raycast.html
examples/webgl_instancing_morphtargets_raycast.html
+0
-195
src/objects/InstancedMesh.js
src/objects/InstancedMesh.js
+53
-6
未找到文件。
examples/files.js
浏览文件 @
57fbfb77
...
...
@@ -49,7 +49,6 @@ var files = {
"
webgl_helpers
"
,
"
webgl_instancing_suzanne
"
,
"
webgl_instancing_raycast
"
,
"
webgl_instancing_morphtargets_raycast
"
,
"
webgl_interactive_buffergeometry
"
,
"
webgl_interactive_cubes
"
,
"
webgl_interactive_cubes_gpu
"
,
...
...
examples/webgl_instancing_morphtargets_raycast.html
已删除
100644 → 0
浏览文件 @
75fb3aa8
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl - instancing - morph targets - raycast
</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=
"http://threejs.org"
target=
"_blank"
rel=
"noopener"
>
three.js
</a>
- WebGL instancing morphTarget raycast
example
</div>
<script
type=
"module"
>
import
*
as
THREE
from
'
../build/three.module.js
'
;
import
Stats
from
'
./jsm/libs/stats.module.js
'
;
import
{
OrbitControls
}
from
'
./jsm/controls/OrbitControls.js
'
;
var
container
;
var
camera
,
scene
,
renderer
,
raycaster
,
controls
,
stats
;
var
mesh
,
mouse
=
new
THREE
.
Vector2
();
var
object
=
new
THREE
.
Object3D
();
var
amount
=
parseInt
(
window
.
location
.
search
.
substr
(
1
)
)
||
10
;
var
count
=
Math
.
pow
(
amount
,
3
);
var
rotationTheta
=
0.1
;
var
rotationMatrix
=
new
THREE
.
Matrix4
().
makeRotationY
(
rotationTheta
);
var
instanceMatrix
=
new
THREE
.
Matrix4
();
var
matrix
=
new
THREE
.
Matrix4
();
init
();
animate
();
function
init
()
{
container
=
document
.
getElementById
(
'
container
'
);
scene
=
new
THREE
.
Scene
();
scene
.
background
=
new
THREE
.
Color
(
0x000000
);
camera
=
new
THREE
.
PerspectiveCamera
(
45
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
2000
);
camera
.
position
.
set
(
25
,
25
,
25
);
camera
.
lookAt
(
new
THREE
.
Vector3
(
0
,
0
,
0
)
);
scene
.
add
(
camera
);
var
light
=
new
THREE
.
AmbientLight
(
0xffffff
);
scene
.
add
(
light
);
var
geometry
=
new
THREE
.
BoxGeometry
(
0.5
,
0.5
,
0.5
);
var
material
=
new
THREE
.
MeshNormalMaterial
(
{
morphTargets
:
true
}
);
// construct 8 blend shapes
for
(
var
i
=
0
;
i
<
8
;
i
++
)
{
var
vertices
=
[];
for
(
var
v
=
0
;
v
<
geometry
.
vertices
.
length
;
v
++
)
{
vertices
.
push
(
geometry
.
vertices
[
v
].
clone
()
);
if
(
v
===
i
)
{
vertices
[
vertices
.
length
-
1
].
x
*=
2
;
vertices
[
vertices
.
length
-
1
].
y
*=
2
;
vertices
[
vertices
.
length
-
1
].
z
*=
2
;
}
}
geometry
.
morphTargets
.
push
(
{
name
:
"
target
"
+
i
,
vertices
:
vertices
}
);
}
geometry
=
new
THREE
.
BufferGeometry
().
fromGeometry
(
geometry
);
mesh
=
new
THREE
.
InstancedMesh
(
geometry
,
material
,
count
);
mesh
.
position
.
set
(
0
,
0
,
0
);
var
i
=
0
;
var
offset
=
amount
/
2
;
for
(
var
x
=
0
;
x
<
amount
;
x
++
)
{
for
(
var
y
=
0
;
y
<
amount
;
y
++
)
{
for
(
var
z
=
0
;
z
<
amount
;
z
++
)
{
object
.
position
.
set
(
(
offset
-
x
)
*
2
,
(
offset
-
y
)
*
2
,
(
offset
-
z
)
*
2
);
object
.
updateMatrix
();
mesh
.
setMatrixAt
(
i
++
,
object
.
matrix
);
}
}
}
scene
.
add
(
mesh
);
raycaster
=
new
THREE
.
Raycaster
();
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
);
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
container
.
appendChild
(
renderer
.
domElement
);
controls
=
new
OrbitControls
(
camera
,
renderer
.
domElement
);
stats
=
new
Stats
();
document
.
body
.
appendChild
(
stats
.
dom
);
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
document
.
addEventListener
(
'
mousemove
'
,
onMouseMove
,
false
);
}
function
onMouseMove
(
event
)
{
event
.
preventDefault
();
mouse
.
x
=
(
event
.
clientX
/
window
.
innerWidth
)
*
2
-
1
;
mouse
.
y
=
-
(
event
.
clientY
/
window
.
innerHeight
)
*
2
+
1
;
}
function
onWindowResize
()
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
}
function
animate
()
{
requestAnimationFrame
(
animate
);
render
();
}
function
updateMorphTargetInfluences
()
{
for
(
var
i
=
0
;
i
<
mesh
.
morphTargetInfluences
.
length
;
i
++
)
{
mesh
.
morphTargetInfluences
[
i
]
=
Math
.
sin
(
Date
.
now
()
*
0.001
)
+
0.5
;
}
}
function
render
()
{
updateMorphTargetInfluences
();
raycaster
.
setFromCamera
(
mouse
,
camera
);
var
intersects
=
raycaster
.
intersectObject
(
mesh
);
if
(
intersects
.
length
>
0
)
{
mesh
.
getMatrixAt
(
intersects
[
0
].
instanceId
,
instanceMatrix
);
matrix
.
multiplyMatrices
(
instanceMatrix
,
rotationMatrix
);
mesh
.
setMatrixAt
(
intersects
[
0
].
instanceId
,
matrix
);
mesh
.
instanceMatrix
.
needsUpdate
=
true
;
}
renderer
.
render
(
scene
,
camera
);
stats
.
update
();
}
</script>
</body>
</html>
src/objects/InstancedMesh.js
浏览文件 @
57fbfb77
...
...
@@ -5,6 +5,13 @@ import { BufferAttribute } from '../core/BufferAttribute.js';
import
{
Mesh
}
from
'
./Mesh.js
'
;
import
{
Matrix4
}
from
'
../math/Matrix4.js
'
;
var
_instanceLocalMatrix
=
new
Matrix4
();
var
_instanceWorldMatrix
=
new
Matrix4
();
var
_instanceIntersects
=
[];
var
_agentMesh
=
new
Mesh
();
function
InstancedMesh
(
geometry
,
material
,
count
)
{
Mesh
.
call
(
this
,
geometry
,
material
);
...
...
@@ -23,11 +30,51 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
getMatrixAt
:
function
(
index
,
matrix
)
{
var
matrix
=
matrix
||
new
Matrix4
();
matrix
.
fromArray
(
this
.
instanceMatrix
.
array
,
index
*
16
);
return
matrix
;
},
raycast
:
function
(
raycaster
,
intersects
)
{
var
matrixWorld
=
this
.
matrixWorld
;
var
raycastTimes
=
this
.
count
;
_agentMesh
.
geometry
=
this
.
geometry
;
_agentMesh
.
material
=
this
.
material
;
if
(
_agentMesh
.
material
===
undefined
)
return
;
for
(
var
instanceId
=
0
;
instanceId
<
raycastTimes
;
instanceId
++
)
{
//Calculate the world matrix for each instance
this
.
getMatrixAt
(
instanceId
,
_instanceLocalMatrix
);
_instanceWorldMatrix
.
multiplyMatrices
(
matrixWorld
,
_instanceLocalMatrix
);
//The agent mesh represents this single instance
_agentMesh
.
matrix
=
_instanceWorldMatrix
;
_agentMesh
.
matrixWorld
.
copy
(
_instanceWorldMatrix
);
_agentMesh
.
raycast
(
raycaster
,
_instanceIntersects
);
//Process the result of raycast
if
(
_instanceIntersects
.
length
>
0
)
{
_instanceIntersects
[
0
].
instanceId
=
instanceId
;
_instanceIntersects
[
0
].
object
=
this
;
intersects
.
push
(
_instanceIntersects
[
0
]
);
_instanceIntersects
=
[];
}
}
},
...
...
@@ -37,9 +84,9 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
},
//
updateMorphTargets: function () {
//
//
}
updateMorphTargets
:
function
()
{
}
}
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录