Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
326b83d6
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 搜索 >>
提交
326b83d6
编写于
12月 22, 2020
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up.
上级
919707fd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
0 addition
and
596 deletion
+0
-596
examples/js/math/Capsule.js
examples/js/math/Capsule.js
+0
-137
examples/js/math/Octree.js
examples/js/math/Octree.js
+0
-457
utils/modularize.js
utils/modularize.js
+0
-2
未找到文件。
examples/js/math/Capsule.js
已删除
100644 → 0
浏览文件 @
919707fd
THREE
.
Capsule
=
(
function
()
{
var
_v1
=
new
THREE
.
Vector3
();
var
_v2
=
new
THREE
.
Vector3
();
var
_v3
=
new
THREE
.
Vector3
();
var
EPS
=
1
e
-
10
;
function
Capsule
(
start
,
end
,
radius
)
{
this
.
start
=
start
==
undefined
?
new
THREE
.
Vector3
(
0
,
0
,
0
)
:
start
;
this
.
end
=
end
==
undefined
?
new
THREE
.
Vector3
(
0
,
1
,
0
)
:
end
;
this
.
radius
=
radius
==
undefined
?
1
:
radius
;
}
Object
.
assign
(
Capsule
.
prototype
,
{
clone
:
function
()
{
return
new
Capsule
(
this
.
start
.
clone
(),
this
.
end
.
clone
(),
this
.
radius
);
},
set
:
function
(
start
,
end
,
radius
)
{
this
.
start
.
copy
(
start
);
this
.
end
.
copy
(
end
);
this
.
radius
=
radius
;
},
copy
:
function
(
capsule
)
{
this
.
start
.
copy
(
capsule
.
start
);
this
.
end
.
copy
(
capsule
.
end
);
this
.
radius
=
capsule
.
radius
;
},
getCenter
:
function
(
target
)
{
return
target
.
copy
(
this
.
end
).
add
(
this
.
start
).
multiplyScalar
(
0.5
);
},
translate
:
function
(
v
)
{
this
.
start
.
add
(
v
);
this
.
end
.
add
(
v
);
},
checkAABBAxis
:
function
(
p1x
,
p1y
,
p2x
,
p2y
,
minx
,
maxx
,
miny
,
maxy
,
radius
)
{
return
(
(
minx
-
p1x
<
radius
||
minx
-
p2x
<
radius
)
&&
(
p1x
-
maxx
<
radius
||
p2x
-
maxx
<
radius
)
&&
(
miny
-
p1y
<
radius
||
miny
-
p2y
<
radius
)
&&
(
p1y
-
maxy
<
radius
||
p2y
-
maxy
<
radius
)
);
},
intersectsBox
:
function
(
box
)
{
return
(
this
.
checkAABBAxis
(
this
.
start
.
x
,
this
.
start
.
y
,
this
.
end
.
x
,
this
.
end
.
y
,
box
.
min
.
x
,
box
.
max
.
x
,
box
.
min
.
y
,
box
.
max
.
y
,
this
.
radius
)
&&
this
.
checkAABBAxis
(
this
.
start
.
x
,
this
.
start
.
z
,
this
.
end
.
x
,
this
.
end
.
z
,
box
.
min
.
x
,
box
.
max
.
x
,
box
.
min
.
z
,
box
.
max
.
z
,
this
.
radius
)
&&
this
.
checkAABBAxis
(
this
.
start
.
y
,
this
.
start
.
z
,
this
.
end
.
y
,
this
.
end
.
z
,
box
.
min
.
y
,
box
.
max
.
y
,
box
.
min
.
z
,
box
.
max
.
z
,
this
.
radius
)
);
},
lineLineMinimumPoints
:
function
(
line1
,
line2
)
{
var
r
=
_v1
.
copy
(
line1
.
end
).
sub
(
line1
.
start
);
var
s
=
_v2
.
copy
(
line2
.
end
).
sub
(
line2
.
start
);
var
w
=
_v3
.
copy
(
line2
.
start
).
sub
(
line1
.
start
);
var
a
=
r
.
dot
(
s
),
b
=
r
.
dot
(
r
),
c
=
s
.
dot
(
s
),
d
=
s
.
dot
(
w
),
e
=
r
.
dot
(
w
);
var
t1
,
t2
,
divisor
=
b
*
c
-
a
*
a
;
if
(
Math
.
abs
(
divisor
)
<
EPS
)
{
var
d1
=
-
d
/
c
;
var
d2
=
(
a
-
d
)
/
c
;
if
(
Math
.
abs
(
d1
-
0.5
)
<
Math
.
abs
(
d2
-
0.5
)
)
{
t1
=
0
;
t2
=
d1
;
}
else
{
t1
=
1
;
t2
=
d2
;
}
}
else
{
t1
=
(
d
*
a
+
e
*
c
)
/
divisor
;
t2
=
(
t1
*
a
-
d
)
/
c
;
}
t2
=
Math
.
max
(
0
,
Math
.
min
(
1
,
t2
)
);
t1
=
Math
.
max
(
0
,
Math
.
min
(
1
,
t1
)
);
var
point1
=
r
.
multiplyScalar
(
t1
).
add
(
line1
.
start
);
var
point2
=
s
.
multiplyScalar
(
t2
).
add
(
line2
.
start
);
return
[
point1
,
point2
];
}
}
);
return
Capsule
;
}
)();
examples/js/math/Octree.js
已删除
100644 → 0
浏览文件 @
919707fd
THREE
.
Octree
=
(
function
()
{
var
_v1
=
new
THREE
.
Vector3
();
var
_v2
=
new
THREE
.
Vector3
();
var
_plane
=
new
THREE
.
Plane
();
var
_line1
=
new
THREE
.
Line3
();
var
_line2
=
new
THREE
.
Line3
();
var
_sphere
=
new
THREE
.
Sphere
();
var
_capsule
=
new
THREE
.
Capsule
();
function
Octree
(
box
)
{
this
.
triangles
=
[];
this
.
box
=
box
;
this
.
subTrees
=
[];
}
Object
.
assign
(
Octree
.
prototype
,
{
addTriangle
:
function
(
triangle
)
{
if
(
!
this
.
bounds
)
this
.
bounds
=
new
THREE
.
Box3
();
this
.
bounds
.
min
.
x
=
Math
.
min
(
this
.
bounds
.
min
.
x
,
triangle
.
a
.
x
,
triangle
.
b
.
x
,
triangle
.
c
.
x
);
this
.
bounds
.
min
.
y
=
Math
.
min
(
this
.
bounds
.
min
.
y
,
triangle
.
a
.
y
,
triangle
.
b
.
y
,
triangle
.
c
.
y
);
this
.
bounds
.
min
.
z
=
Math
.
min
(
this
.
bounds
.
min
.
z
,
triangle
.
a
.
z
,
triangle
.
b
.
z
,
triangle
.
c
.
z
);
this
.
bounds
.
max
.
x
=
Math
.
max
(
this
.
bounds
.
max
.
x
,
triangle
.
a
.
x
,
triangle
.
b
.
x
,
triangle
.
c
.
x
);
this
.
bounds
.
max
.
y
=
Math
.
max
(
this
.
bounds
.
max
.
y
,
triangle
.
a
.
y
,
triangle
.
b
.
y
,
triangle
.
c
.
y
);
this
.
bounds
.
max
.
z
=
Math
.
max
(
this
.
bounds
.
max
.
z
,
triangle
.
a
.
z
,
triangle
.
b
.
z
,
triangle
.
c
.
z
);
this
.
triangles
.
push
(
triangle
);
return
this
;
},
calcBox
:
function
()
{
this
.
box
=
this
.
bounds
.
clone
();
// offset small ammount to account for regular grid
this
.
box
.
min
.
x
-=
0.01
;
this
.
box
.
min
.
y
-=
0.01
;
this
.
box
.
min
.
z
-=
0.01
;
return
this
;
},
split
:
function
(
level
)
{
if
(
!
this
.
box
)
return
;
var
subTrees
=
[],
halfsize
=
_v2
.
copy
(
this
.
box
.
max
).
sub
(
this
.
box
.
min
).
multiplyScalar
(
0.5
),
box
,
v
,
triangle
;
for
(
var
x
=
0
;
x
<
2
;
x
++
)
{
for
(
var
y
=
0
;
y
<
2
;
y
++
)
{
for
(
var
z
=
0
;
z
<
2
;
z
++
)
{
box
=
new
THREE
.
Box3
();
v
=
_v1
.
set
(
x
,
y
,
z
);
box
.
min
.
copy
(
this
.
box
.
min
).
add
(
v
.
multiply
(
halfsize
)
);
box
.
max
.
copy
(
box
.
min
).
add
(
halfsize
);
subTrees
.
push
(
new
Octree
(
box
)
);
}
}
}
while
(
triangle
=
this
.
triangles
.
pop
()
)
{
for
(
var
i
=
0
;
i
<
subTrees
.
length
;
i
++
)
{
if
(
subTrees
[
i
].
box
.
intersectsTriangle
(
triangle
)
)
{
subTrees
[
i
].
triangles
.
push
(
triangle
);
}
}
}
for
(
var
i
=
0
;
i
<
subTrees
.
length
;
i
++
)
{
var
len
=
subTrees
[
i
].
triangles
.
length
;
if
(
len
>
8
&&
level
<
16
)
{
subTrees
[
i
].
split
(
level
+
1
);
}
if
(
len
!=
0
)
{
this
.
subTrees
.
push
(
subTrees
[
i
]
);
}
}
return
this
;
},
build
:
function
()
{
this
.
calcBox
();
this
.
split
(
0
);
return
this
;
},
getRayTriangles
:
function
(
ray
,
triangles
)
{
for
(
var
i
=
0
;
i
<
this
.
subTrees
.
length
;
i
++
)
{
var
subTree
=
this
.
subTrees
[
i
];
if
(
!
ray
.
intersectsBox
(
subTree
.
box
)
)
continue
;
if
(
subTree
.
triangles
.
length
>
0
)
{
for
(
var
j
=
0
;
j
<
subTree
.
triangles
.
length
;
j
++
)
{
if
(
triangles
.
indexOf
(
subTree
.
triangles
[
j
]
)
===
-
1
)
triangles
.
push
(
subTree
.
triangles
[
j
]
);
}
}
else
{
subTree
.
getRayTriangles
(
ray
,
triangles
);
}
}
return
triangles
;
},
triangleCapsuleIntersect
:
function
(
capsule
,
triangle
)
{
var
point1
,
point2
,
line1
,
line2
;
triangle
.
getPlane
(
_plane
);
var
d1
=
_plane
.
distanceToPoint
(
capsule
.
start
)
-
capsule
.
radius
;
var
d2
=
_plane
.
distanceToPoint
(
capsule
.
end
)
-
capsule
.
radius
;
if
(
(
d1
>
0
&&
d2
>
0
)
||
(
d1
<
-
capsule
.
radius
&&
d2
<
-
capsule
.
radius
)
)
{
return
false
;
}
var
delta
=
Math
.
abs
(
d1
/
(
Math
.
abs
(
d1
)
+
Math
.
abs
(
d2
)
)
);
var
intersectPoint
=
_v1
.
copy
(
capsule
.
start
).
lerp
(
capsule
.
end
,
delta
);
if
(
triangle
.
containsPoint
(
intersectPoint
)
)
{
return
{
normal
:
_plane
.
normal
.
clone
(),
point
:
intersectPoint
.
clone
(),
depth
:
Math
.
abs
(
Math
.
min
(
d1
,
d2
)
)
};
}
var
r2
=
capsule
.
radius
*
capsule
.
radius
;
line1
=
_line1
.
set
(
capsule
.
start
,
capsule
.
end
);
var
lines
=
[
[
triangle
.
a
,
triangle
.
b
],
[
triangle
.
b
,
triangle
.
c
],
[
triangle
.
c
,
triangle
.
a
]
];
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
line2
=
_line2
.
set
(
lines
[
i
][
0
],
lines
[
i
][
1
]
);
[
point1
,
point2
]
=
capsule
.
lineLineMinimumPoints
(
line1
,
line2
);
if
(
point1
.
distanceToSquared
(
point2
)
<
r2
)
{
return
{
normal
:
point1
.
clone
().
sub
(
point2
).
normalize
(),
point
:
point2
.
clone
(),
depth
:
capsule
.
radius
-
point1
.
distanceTo
(
point2
)
};
}
}
return
false
;
},
triangleSphereIntersect
:
function
(
sphere
,
triangle
)
{
triangle
.
getPlane
(
_plane
);
if
(
!
sphere
.
intersectsPlane
(
_plane
)
)
return
false
;
var
depth
=
Math
.
abs
(
_plane
.
distanceToSphere
(
sphere
)
);
var
r2
=
sphere
.
radius
*
sphere
.
radius
-
depth
*
depth
;
var
plainPoint
=
_plane
.
projectPoint
(
sphere
.
center
,
_v1
);
if
(
triangle
.
containsPoint
(
sphere
.
center
)
)
{
return
{
normal
:
_plane
.
normal
.
clone
(),
point
:
plainPoint
.
clone
(),
depth
:
Math
.
abs
(
_plane
.
distanceToSphere
(
sphere
)
)
};
}
var
lines
=
[
[
triangle
.
a
,
triangle
.
b
],
[
triangle
.
b
,
triangle
.
c
],
[
triangle
.
c
,
triangle
.
a
]
];
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
_line1
.
set
(
lines
[
i
][
0
],
lines
[
i
][
1
]
);
_line1
.
closestPointToPoint
(
plainPoint
,
true
,
_v2
);
var
d
=
_v2
.
distanceToSquared
(
sphere
.
center
);
if
(
d
<
r2
)
{
return
{
normal
:
sphere
.
center
.
clone
().
sub
(
_v2
).
normalize
(),
point
:
_v2
.
clone
(),
depth
:
sphere
.
radius
-
Math
.
sqrt
(
d
)
};
}
}
return
false
;
},
getSphereTriangles
:
function
(
sphere
,
triangles
)
{
for
(
var
i
=
0
;
i
<
this
.
subTrees
.
length
;
i
++
)
{
var
subTree
=
this
.
subTrees
[
i
];
if
(
!
sphere
.
intersectsBox
(
subTree
.
box
)
)
continue
;
if
(
subTree
.
triangles
.
length
>
0
)
{
for
(
var
j
=
0
;
j
<
subTree
.
triangles
.
length
;
j
++
)
{
if
(
triangles
.
indexOf
(
subTree
.
triangles
[
j
]
)
===
-
1
)
triangles
.
push
(
subTree
.
triangles
[
j
]
);
}
}
else
{
subTree
.
getSphereTriangles
(
sphere
,
triangles
);
}
}
},
getCapsuleTriangles
:
function
(
capsule
,
triangles
)
{
for
(
var
i
=
0
;
i
<
this
.
subTrees
.
length
;
i
++
)
{
var
subTree
=
this
.
subTrees
[
i
];
if
(
!
capsule
.
intersectsBox
(
subTree
.
box
)
)
continue
;
if
(
subTree
.
triangles
.
length
>
0
)
{
for
(
var
j
=
0
;
j
<
subTree
.
triangles
.
length
;
j
++
)
{
if
(
triangles
.
indexOf
(
subTree
.
triangles
[
j
]
)
===
-
1
)
triangles
.
push
(
subTree
.
triangles
[
j
]
);
}
}
else
{
subTree
.
getCapsuleTriangles
(
capsule
,
triangles
);
}
}
},
sphereIntersect
(
sphere
)
{
_sphere
.
copy
(
sphere
);
var
triangles
=
[],
result
,
hit
=
false
;
this
.
getSphereTriangles
(
sphere
,
triangles
);
for
(
var
i
=
0
;
i
<
triangles
.
length
;
i
++
)
{
if
(
result
=
this
.
triangleSphereIntersect
(
_sphere
,
triangles
[
i
]
)
)
{
hit
=
true
;
_sphere
.
center
.
add
(
result
.
normal
.
multiplyScalar
(
result
.
depth
)
);
}
}
if
(
hit
)
{
var
collisionVector
=
_sphere
.
center
.
clone
().
sub
(
sphere
.
center
);
var
depth
=
collisionVector
.
length
();
return
{
normal
:
collisionVector
.
normalize
(),
depth
:
depth
};
}
return
false
;
},
capsuleIntersect
:
function
(
capsule
)
{
_capsule
.
copy
(
capsule
);
var
triangles
=
[],
result
,
hit
=
false
;
this
.
getCapsuleTriangles
(
_capsule
,
triangles
);
for
(
var
i
=
0
;
i
<
triangles
.
length
;
i
++
)
{
if
(
result
=
this
.
triangleCapsuleIntersect
(
_capsule
,
triangles
[
i
]
)
)
{
hit
=
true
;
_capsule
.
translate
(
result
.
normal
.
multiplyScalar
(
result
.
depth
)
);
}
}
if
(
hit
)
{
var
collisionVector
=
_capsule
.
getCenter
(
new
THREE
.
Vector3
()
).
sub
(
capsule
.
getCenter
(
_v1
)
);
var
depth
=
collisionVector
.
length
();
return
{
normal
:
collisionVector
.
normalize
(),
depth
:
depth
};
}
return
false
;
},
rayIntersect
:
function
(
ray
)
{
if
(
ray
.
direction
.
length
()
===
0
)
return
;
var
triangles
=
[],
triangle
,
position
,
distance
=
1
e100
,
result
;
this
.
getRayTriangles
(
ray
,
triangles
);
for
(
var
i
=
0
;
i
<
triangles
.
length
;
i
++
)
{
result
=
ray
.
intersectTriangle
(
triangles
[
i
].
a
,
triangles
[
i
].
b
,
triangles
[
i
].
c
,
true
,
_v1
);
if
(
result
)
{
var
newdistance
=
result
.
sub
(
ray
.
origin
).
length
();
if
(
distance
>
newdistance
)
{
position
=
result
.
clone
().
add
(
ray
.
origin
);
distance
=
newdistance
;
triangle
=
triangles
[
i
];
}
}
}
return
distance
<
1
e100
?
{
distance
:
distance
,
triangle
:
triangle
,
position
:
position
}
:
false
;
},
fromGraphNode
:
function
(
group
)
{
group
.
traverse
(
(
obj
)
=>
{
if
(
obj
.
type
===
'
Mesh
'
)
{
obj
.
updateMatrix
();
obj
.
updateWorldMatrix
();
var
geometry
,
isTemp
=
false
;
if
(
obj
.
geometry
.
index
)
{
isTemp
=
true
;
geometry
=
obj
.
geometry
.
clone
().
toNonIndexed
();
}
else
{
geometry
=
obj
.
geometry
;
}
var
positions
=
geometry
.
attributes
.
position
.
array
;
var
transform
=
obj
.
matrixWorld
;
for
(
var
i
=
0
;
i
<
positions
.
length
;
i
+=
9
)
{
var
v1
=
new
THREE
.
Vector3
(
positions
[
i
],
positions
[
i
+
1
],
positions
[
i
+
2
]
);
var
v2
=
new
THREE
.
Vector3
(
positions
[
i
+
3
],
positions
[
i
+
4
],
positions
[
i
+
5
]
);
var
v3
=
new
THREE
.
Vector3
(
positions
[
i
+
6
],
positions
[
i
+
7
],
positions
[
i
+
8
]
);
v1
.
applyMatrix4
(
transform
);
v2
.
applyMatrix4
(
transform
);
v3
.
applyMatrix4
(
transform
);
this
.
addTriangle
(
new
THREE
.
Triangle
(
v1
,
v2
,
v3
)
);
}
if
(
isTemp
)
{
geometry
.
dispose
();
}
}
}
);
this
.
build
();
return
this
;
}
}
);
return
Octree
;
}
)();
utils/modularize.js
浏览文件 @
326b83d6
...
...
@@ -105,8 +105,6 @@ var files = [
{
path
:
'
math/ImprovedNoise.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
math/Lut.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
math/SimplexNoise.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
math/Capsule.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
math/Octree.js
'
,
dependencies
:
[
{
name
:
'
Capsule
'
,
path
:
'
math/Capsule.js
'
}
],
ignoreList
:
[]
},
{
path
:
'
misc/ConvexObjectBreaker.js
'
,
dependencies
:
[
{
name
:
'
ConvexBufferGeometry
'
,
path
:
'
geometries/ConvexGeometry.js
'
}
],
ignoreList
:
[
'
Matrix4
'
]
},
{
path
:
'
misc/GPUComputationRenderer.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录