Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
eea1cd9c
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,发现更多精彩内容 >>
提交
eea1cd9c
编写于
3月 16, 2012
作者:
Z
zz85
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding TubeGeometry.js
上级
cc6c1b57
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
149 addition
and
0 deletion
+149
-0
src/extras/geometries/TubeGeometry.js
src/extras/geometries/TubeGeometry.js
+148
-0
utils/build.py
utils/build.py
+1
-0
未找到文件。
src/extras/geometries/TubeGeometry.js
0 → 100644
浏览文件 @
eea1cd9c
/**
* @author WestLangley / https://github.com/WestLangley
* @author zz85 / https://github.com/zz85
* @author miningold / https://github.com/miningold
* modified from the TorusKnotGeometry by @oosmoxiecode
*
* Creates a tube which extrudes along a 3d spline
*/
THREE
.
TubeGeometry
=
function
(
radius
,
segments
,
segmentsRadius
,
path
)
{
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
.
path
=
path
;
var
tang
=
new
THREE
.
Vector3
();
var
binormal
=
new
THREE
.
Vector3
();
var
normal
=
new
THREE
.
Vector3
();
var
pos
=
new
THREE
.
Vector3
();
var
epsilon
=
0.001
;
var
u
,
v
;
var
p1
,
p2
;
var
cx
,
cy
;
var
oldB
;
for
(
var
i
=
0
;
i
<
this
.
segments
;
++
i
)
{
this
.
grid
[
i
]
=
new
Array
(
this
.
segmentsRadius
);
u
=
i
/
this
.
segments
;
var
pos
=
this
.
path
.
getPointAt
(
u
);
tang
=
this
.
path
.
getTangentAt
(
u
);
if
(
oldB
===
undefined
)
{
//arbitrary vector
//oldB = new THREE.Vector3(Math.random(), Math.random(), Math.random()).normalize();
//oldB = new THREE.Vector3( 0, -1, 0 ); // test to see what happens to a known binormal vector
// 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
)
{
smallest
=
tx
;
x
=
1
;
y
=
0
;
z
=
0
;
}
if
(
ty
<=
smallest
)
{
smallest
=
ty
;
x
=
0
;
y
=
1
;
z
=
0
;
}
if
(
tz
<=
smallest
)
{
x
=
0
;
y
=
0
;
z
=
1
;
}
oldB
=
new
THREE
.
Vector3
(
x
,
y
,
z
);
}
normal
.
cross
(
oldB
,
tang
).
normalize
();
binormal
.
cross
(
tang
,
normal
).
normalize
();
oldB
=
binormal
;
addArrow
(
parent
,
pos
,
normal
,
radius
*
2
,
0xffff00
);
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
);
var
pos2
=
new
THREE
.
Vector3
().
copy
(
pos
);
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
);
}
}
for
(
var
i
=
0
;
i
<
this
.
segments
-
1
;
++
i
)
{
for
(
var
j
=
0
;
j
<
this
.
segmentsRadius
;
++
j
)
{
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
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
.
computeCentroids
();
this
.
computeFaceNormals
();
this
.
computeVertexNormals
();
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
);
}
};
THREE
.
TubeGeometry
.
prototype
=
new
THREE
.
Geometry
();
THREE
.
TubeGeometry
.
prototype
.
constructor
=
THREE
.
TubeGeometry
;
\ No newline at end of file
utils/build.py
浏览文件 @
eea1cd9c
...
...
@@ -116,6 +116,7 @@ EXTRAS_FILES = [
'extras/geometries/TextGeometry.js'
,
'extras/geometries/TorusGeometry.js'
,
'extras/geometries/TorusKnotGeometry.js'
,
'extras/geometries/TubeGeometry.js'
,
'extras/geometries/PolyhedronGeometry.js'
,
'extras/geometries/IcosahedronGeometry.js'
,
'extras/geometries/OctahedronGeometry.js'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录