Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
2375024e
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,发现更多精彩内容 >>
提交
2375024e
编写于
3月 16, 2012
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleaned up TubeGeometry.
上级
87f6fde2
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
626 addition
and
604 deletion
+626
-604
build/Three.js
build/Three.js
+405
-401
build/custom/ThreeExtras.js
build/custom/ThreeExtras.js
+159
-155
src/extras/geometries/TubeGeometry.js
src/extras/geometries/TubeGeometry.js
+62
-48
未找到文件。
build/Three.js
浏览文件 @
2375024e
此差异已折叠。
点击以展开。
build/custom/ThreeExtras.js
浏览文件 @
2375024e
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
src/extras/geometries/TubeGeometry.js
浏览文件 @
2375024e
...
...
@@ -2,31 +2,29 @@
* @author WestLangley / https://github.com/WestLangley
* @author zz85 / https://github.com/zz85
* @author miningold / https://github.com/miningold
* modified from the TorusKnotGeometry by @oosmoxiecode
*
* Modified from the TorusKnotGeometry by @oosmoxiecode
*
* Creates a tube which extrudes along a 3d spline
*/
THREE
.
TubeGeometry
=
function
(
radius
,
segments
,
segmentsRadius
,
path
,
debug
)
{
THREE
.
TubeGeometry
=
function
(
radius
,
segments
,
segmentsRadius
,
path
,
debug
)
{
THREE
.
Geometry
.
call
(
this
);
THREE
.
Geometry
.
call
(
this
);
var
scope
=
this
;
this
.
radius
=
radius
||
40
;
this
.
segments
=
segments
||
64
;
this
.
segmentsRadius
=
segmentsRadius
||
8
;
this
.
grid
=
new
Array
(
this
.
segments
);
this
.
grid
=
new
Array
(
this
.
segments
);
this
.
path
=
path
;
if
(
debug
)
this
.
debug
=
new
THREE
.
Object3D
();
if
(
debug
)
this
.
debug
=
new
THREE
.
Object3D
();
var
tang
=
new
THREE
.
Vector3
();
var
binormal
=
new
THREE
.
Vector3
();
var
normal
=
new
THREE
.
Vector3
();
var
pos
=
new
THREE
.
Vector3
();
var
epsilon
=
0.001
;
...
...
@@ -38,16 +36,17 @@ THREE.TubeGeometry = function(radius, segments, segmentsRadius, path, debug) {
var
oldB
;
for
(
var
i
=
0
;
i
<
this
.
segments
;
++
i
)
{
for
(
var
i
=
0
;
i
<
this
.
segments
;
++
i
)
{
this
.
grid
[
i
]
=
new
Array
(
this
.
segmentsRadius
);
this
.
grid
[
i
]
=
new
Array
(
this
.
segmentsRadius
);
u
=
i
/
this
.
segments
;
var
pos
=
this
.
path
.
getPointAt
(
u
);
tang
=
this
.
path
.
getTangentAt
(
u
);
pos
=
this
.
path
.
getPointAt
(
u
);
tang
=
this
.
path
.
getTangentAt
(
u
);
if
(
oldB
===
undefined
)
{
if
(
oldB
===
undefined
)
{
//arbitrary vector method 1
//oldB = new THREE.Vector3(Math.random(), Math.random(), Math.random()).normalize();
...
...
@@ -71,83 +70,94 @@ THREE.TubeGeometry = function(radius, segments, segmentsRadius, path, debug) {
// Find the smallest componenet of the tangent vector (x, y, or z) and set the binormal
// equal to the unit vector in that direction ((1, 0, 0), (0, 1, 0), or (0, 0, 1))
var
smallest
=
Number
.
MAX_VALUE
;
var
x
,
y
,
z
;
var
tx
=
Math
.
abs
(
tang
.
x
);
var
ty
=
Math
.
abs
(
tang
.
y
);
var
tz
=
Math
.
abs
(
tang
.
z
);
if
(
tx
<=
smallest
)
{
var
tx
=
Math
.
abs
(
tang
.
x
);
var
ty
=
Math
.
abs
(
tang
.
y
);
var
tz
=
Math
.
abs
(
tang
.
z
);
if
(
tx
<=
smallest
)
{
smallest
=
tx
;
x
=
1
;
y
=
0
;
z
=
0
;
}
if
(
ty
<=
smallest
)
{
if
(
ty
<=
smallest
)
{
smallest
=
ty
;
x
=
0
;
y
=
1
;
z
=
0
;
}
if
(
tz
<=
smallest
)
{
if
(
tz
<=
smallest
)
{
x
=
0
;
y
=
0
;
z
=
1
;
}
oldB
=
new
THREE
.
Vector3
(
x
,
y
,
z
);
oldB
=
new
THREE
.
Vector3
(
x
,
y
,
z
);
}
normal
.
cross
(
oldB
,
tang
).
normalize
();
binormal
.
cross
(
tang
,
normal
).
normalize
();
normal
.
cross
(
oldB
,
tang
).
normalize
();
binormal
.
cross
(
tang
,
normal
).
normalize
();
oldB
=
binormal
;
if
(
this
.
debug
)
{
this
.
debug
.
add
(
new
THREE
.
ArrowHelper
(
normal
,
pos
,
radius
*
2
,
0xff0000
)
);
if
(
this
.
debug
)
{
this
.
debug
.
add
(
new
THREE
.
ArrowHelper
(
normal
,
pos
,
radius
*
2
,
0xff0000
));
}
for
(
var
j
=
0
;
j
<
this
.
segmentsRadius
;
++
j
)
{
for
(
var
j
=
0
;
j
<
this
.
segmentsRadius
;
++
j
)
{
v
=
j
/
this
.
segmentsRadius
*
2
*
Math
.
PI
;
cx
=
-
this
.
radius
*
Math
.
cos
(
v
);
// TODO: Hack: Negating it so it faces outside.
cy
=
this
.
radius
*
Math
.
sin
(
v
);
cx
=
-
this
.
radius
*
Math
.
cos
(
v
);
// TODO: Hack: Negating it so it faces outside.
cy
=
this
.
radius
*
Math
.
sin
(
v
);
var
pos2
=
new
THREE
.
Vector3
().
copy
(
pos
);
var
pos2
=
pos
.
clone
(
);
pos2
.
x
+=
cx
*
normal
.
x
+
cy
*
binormal
.
x
;
pos2
.
y
+=
cx
*
normal
.
y
+
cy
*
binormal
.
y
;
pos2
.
z
+=
cx
*
normal
.
z
+
cy
*
binormal
.
z
;
this
.
grid
[
i
][
j
]
=
vert
(
pos2
.
x
,
pos2
.
y
,
pos2
.
z
);
this
.
grid
[
i
][
j
]
=
vert
(
pos2
.
x
,
pos2
.
y
,
pos2
.
z
);
}
}
for
(
var
i
=
0
;
i
<
this
.
segments
;
++
i
)
{
// segments -1 for non-closed loops, segment - 0 for closed ?
for
(
var
i
=
0
;
i
<
this
.
segments
;
++
i
)
{
// segments -1 for non-closed loops, segment - 0 for closed ?
for
(
var
j
=
0
;
j
<
this
.
segmentsRadius
;
++
j
)
{
for
(
var
j
=
0
;
j
<
this
.
segmentsRadius
;
++
j
)
{
var
ip
=
(
i
+
1
)
%
this
.
segments
;
var
jp
=
(
j
+
1
)
%
this
.
segmentsRadius
;
var
ip
=
(
i
+
1
)
%
this
.
segments
;
var
jp
=
(
j
+
1
)
%
this
.
segmentsRadius
;
var
a
=
this
.
grid
[
i
][
j
];
var
b
=
this
.
grid
[
ip
][
j
];
var
c
=
this
.
grid
[
ip
][
jp
];
var
d
=
this
.
grid
[
i
][
jp
];
var
a
=
this
.
grid
[
i
][
j
];
var
b
=
this
.
grid
[
ip
][
j
];
var
c
=
this
.
grid
[
ip
][
jp
];
var
d
=
this
.
grid
[
i
][
jp
];
var
uva
=
new
THREE
.
UV
(
i
/
this
.
segments
,
j
/
this
.
segmentsRadius
);
var
uvb
=
new
THREE
.
UV
(
(
i
+
1
)
/
this
.
segments
,
j
/
this
.
segmentsRadius
);
var
uvc
=
new
THREE
.
UV
(
(
i
+
1
)
/
this
.
segments
,
(
j
+
1
)
/
this
.
segmentsRadius
);
var
uvd
=
new
THREE
.
UV
(
i
/
this
.
segments
,
(
j
+
1
)
/
this
.
segmentsRadius
);
var
uva
=
new
THREE
.
UV
(
i
/
this
.
segments
,
j
/
this
.
segmentsRadius
);
var
uvb
=
new
THREE
.
UV
(
(
i
+
1
)
/
this
.
segments
,
j
/
this
.
segmentsRadius
);
var
uvc
=
new
THREE
.
UV
(
(
i
+
1
)
/
this
.
segments
,
(
j
+
1
)
/
this
.
segmentsRadius
);
var
uvd
=
new
THREE
.
UV
(
i
/
this
.
segments
,
(
j
+
1
)
/
this
.
segmentsRadius
);
this
.
faces
.
push
(
new
THREE
.
Face4
(
a
,
b
,
c
,
d
)
);
this
.
faceVertexUvs
[
0
].
push
([
uva
,
uvb
,
uvc
,
uvd
]
);
this
.
faces
.
push
(
new
THREE
.
Face4
(
a
,
b
,
c
,
d
)
);
this
.
faceVertexUvs
[
0
].
push
(
[
uva
,
uvb
,
uvc
,
uvd
]
);
}
}
...
...
@@ -156,12 +166,16 @@ THREE.TubeGeometry = function(radius, segments, segmentsRadius, path, debug) {
this
.
computeFaceNormals
();
this
.
computeVertexNormals
();
function
vert
(
x
,
y
,
z
)
{
return
scope
.
vertices
.
push
(
new
THREE
.
Vertex
(
new
THREE
.
Vector3
(
x
,
y
,
z
)))
-
1
;
function
vert
(
x
,
y
,
z
)
{
return
scope
.
vertices
.
push
(
new
THREE
.
Vertex
(
new
THREE
.
Vector3
(
x
,
y
,
z
)
)
)
-
1
;
}
function
getPathPos
(
u
,
path
)
{
return
path
.
getPoint
(
u
);
function
getPathPos
(
u
,
path
)
{
return
path
.
getPoint
(
u
);
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录