Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
7c27e473
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,发现更多精彩内容 >>
提交
7c27e473
编写于
3月 15, 2019
作者:
M
Mugen87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Mesh: Added support for morph targets with BufferGeometry in raycast().
上级
82974f2a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
69 addition
and
9 deletion
+69
-9
examples/webgl_morphtargets.html
examples/webgl_morphtargets.html
+28
-4
src/objects/Mesh.js
src/objects/Mesh.js
+41
-5
未找到文件。
examples/webgl_morphtargets.html
浏览文件 @
7c27e473
...
...
@@ -51,9 +51,9 @@
var
container
;
var
camera
,
scene
,
renderer
;
var
camera
,
scene
,
renderer
,
raycaster
;
var
mesh
;
var
mesh
,
mouse
=
new
THREE
.
Vector2
()
;
init
();
animate
();
...
...
@@ -69,7 +69,8 @@
scene
.
background
=
new
THREE
.
Color
(
0x222222
);
scene
.
fog
=
new
THREE
.
Fog
(
0x000000
,
1
,
15000
);
var
light
=
new
THREE
.
PointLight
(
0xff2200
);
var
light
=
new
THREE
.
PointLight
(
0xffffff
);
light
.
position
.
z
=
500
;
camera
.
add
(
light
);
scene
.
add
(
camera
);
...
...
@@ -77,7 +78,7 @@
scene
.
add
(
light
);
var
geometry
=
new
THREE
.
BoxGeometry
(
100
,
100
,
100
);
var
material
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0xff
ffff
,
morphTargets
:
true
}
);
var
material
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0xff
0000
,
morphTargets
:
true
}
);
// construct 8 blend shapes
...
...
@@ -169,6 +170,8 @@
//
raycaster
=
new
THREE
.
Raycaster
();
renderer
=
new
THREE
.
WebGLRenderer
();
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
...
...
@@ -184,6 +187,27 @@
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
document
.
addEventListener
(
'
click
'
,
onClick
,
false
);
}
function
onClick
(
event
)
{
event
.
preventDefault
();
mouse
.
x
=
(
event
.
clientX
/
window
.
innerWidth
)
*
2
-
1
;
mouse
.
y
=
-
(
event
.
clientY
/
window
.
innerHeight
)
*
2
+
1
;
raycaster
.
setFromCamera
(
mouse
,
camera
);
var
intersects
=
raycaster
.
intersectObject
(
mesh
);
if
(
intersects
.
length
>
0
)
{
mesh
.
material
.
color
.
set
(
Math
.
random
()
*
0xffffff
);
}
}
function
onWindowResize
()
{
...
...
src/objects/Mesh.js
浏览文件 @
7c27e473
...
...
@@ -126,6 +126,10 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
var
tempB
=
new
Vector3
();
var
tempC
=
new
Vector3
();
var
morphA
=
new
Vector3
();
var
morphB
=
new
Vector3
();
var
morphC
=
new
Vector3
();
var
uvA
=
new
Vector2
();
var
uvB
=
new
Vector2
();
var
uvC
=
new
Vector2
();
...
...
@@ -164,12 +168,43 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
}
function
checkBufferGeometryIntersection
(
object
,
material
,
raycaster
,
ray
,
position
,
uv
,
a
,
b
,
c
)
{
function
checkBufferGeometryIntersection
(
object
,
material
,
raycaster
,
ray
,
position
,
morphPosition
,
uv
,
a
,
b
,
c
)
{
vA
.
fromBufferAttribute
(
position
,
a
);
vB
.
fromBufferAttribute
(
position
,
b
);
vC
.
fromBufferAttribute
(
position
,
c
);
var
morphInfluences
=
object
.
morphTargetInfluences
;
if
(
material
.
morphTargets
&&
morphPosition
&&
morphInfluences
)
{
morphA
.
set
(
0
,
0
,
0
);
morphB
.
set
(
0
,
0
,
0
);
morphC
.
set
(
0
,
0
,
0
);
for
(
var
i
=
0
,
il
=
morphPosition
.
length
;
i
<
il
;
i
++
)
{
var
influence
=
morphInfluences
[
i
];
var
morphAttribute
=
morphPosition
[
i
];
if
(
influence
===
0
)
continue
;
tempA
.
fromBufferAttribute
(
morphAttribute
,
a
);
tempB
.
fromBufferAttribute
(
morphAttribute
,
b
);
tempC
.
fromBufferAttribute
(
morphAttribute
,
c
);
morphA
.
addScaledVector
(
tempA
.
sub
(
vA
),
influence
);
morphB
.
addScaledVector
(
tempB
.
sub
(
vB
),
influence
);
morphC
.
addScaledVector
(
tempC
.
sub
(
vC
),
influence
);
}
vA
.
add
(
morphA
);
vB
.
add
(
morphB
);
vC
.
add
(
morphC
);
}
var
intersection
=
checkIntersection
(
object
,
material
,
raycaster
,
ray
,
vA
,
vB
,
vC
,
intersectionPoint
);
if
(
intersection
)
{
...
...
@@ -232,6 +267,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
var
a
,
b
,
c
;
var
index
=
geometry
.
index
;
var
position
=
geometry
.
attributes
.
position
;
var
morphPosition
=
geometry
.
morphAttributes
.
position
;
var
uv
=
geometry
.
attributes
.
uv
;
var
groups
=
geometry
.
groups
;
var
drawRange
=
geometry
.
drawRange
;
...
...
@@ -259,7 +295,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
b
=
index
.
getX
(
j
+
1
);
c
=
index
.
getX
(
j
+
2
);
intersection
=
checkBufferGeometryIntersection
(
this
,
groupMaterial
,
raycaster
,
ray
,
position
,
uv
,
a
,
b
,
c
);
intersection
=
checkBufferGeometryIntersection
(
this
,
groupMaterial
,
raycaster
,
ray
,
position
,
morphPosition
,
uv
,
a
,
b
,
c
);
if
(
intersection
)
{
...
...
@@ -284,7 +320,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
b
=
index
.
getX
(
i
+
1
);
c
=
index
.
getX
(
i
+
2
);
intersection
=
checkBufferGeometryIntersection
(
this
,
material
,
raycaster
,
ray
,
position
,
uv
,
a
,
b
,
c
);
intersection
=
checkBufferGeometryIntersection
(
this
,
material
,
raycaster
,
ray
,
position
,
morphPosition
,
uv
,
a
,
b
,
c
);
if
(
intersection
)
{
...
...
@@ -317,7 +353,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
b
=
j
+
1
;
c
=
j
+
2
;
intersection
=
checkBufferGeometryIntersection
(
this
,
groupMaterial
,
raycaster
,
ray
,
position
,
uv
,
a
,
b
,
c
);
intersection
=
checkBufferGeometryIntersection
(
this
,
groupMaterial
,
raycaster
,
ray
,
position
,
morphPosition
,
uv
,
a
,
b
,
c
);
if
(
intersection
)
{
...
...
@@ -342,7 +378,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
b
=
i
+
1
;
c
=
i
+
2
;
intersection
=
checkBufferGeometryIntersection
(
this
,
material
,
raycaster
,
ray
,
position
,
uv
,
a
,
b
,
c
);
intersection
=
checkBufferGeometryIntersection
(
this
,
material
,
raycaster
,
ray
,
position
,
morphPosition
,
uv
,
a
,
b
,
c
);
if
(
intersection
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录