Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
254e09b7
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,发现更多精彩内容 >>
提交
254e09b7
编写于
3月 30, 2017
作者:
M
Mr.doob
提交者:
GitHub
3月 30, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11074 from Mugen87/parametric
ParametricGeometry: Optimize code
上级
ee765064
0f75dd85
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
27 deletion
+59
-27
examples/js/ParametricGeometries.js
examples/js/ParametricGeometries.js
+38
-20
src/geometries/ParametricGeometry.js
src/geometries/ParametricGeometry.js
+21
-7
未找到文件。
examples/js/ParametricGeometries.js
浏览文件 @
254e09b7
...
...
@@ -7,7 +7,9 @@
THREE
.
ParametricGeometries
=
{
klein
:
function
(
v
,
u
)
{
klein
:
function
(
v
,
u
,
optionalTarget
)
{
var
result
=
optionalTarget
||
new
THREE
.
Vector3
();
u
*=
Math
.
PI
;
v
*=
2
*
Math
.
PI
;
...
...
@@ -28,25 +30,29 @@ THREE.ParametricGeometries = {
y
=
-
2
*
(
1
-
Math
.
cos
(
u
)
/
2
)
*
Math
.
sin
(
v
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
return
result
.
set
(
x
,
y
,
z
);
},
plane
:
function
(
width
,
height
)
{
return
function
(
u
,
v
)
{
return
function
(
u
,
v
,
optionalTarget
)
{
var
result
=
optionalTarget
||
new
THREE
.
Vector3
();
var
x
=
u
*
width
;
var
y
=
0
;
var
z
=
v
*
height
;
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
return
result
.
set
(
x
,
y
,
z
);
};
},
mobius
:
function
(
u
,
t
)
{
mobius
:
function
(
u
,
t
,
optionalTarget
)
{
var
result
=
optionalTarget
||
new
THREE
.
Vector3
();
// flat mobius strip
// http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
...
...
@@ -56,28 +62,36 @@ THREE.ParametricGeometries = {
var
x
,
y
,
z
;
var
a
=
2
;
x
=
Math
.
cos
(
v
)
*
(
a
+
u
*
Math
.
cos
(
v
/
2
)
);
y
=
Math
.
sin
(
v
)
*
(
a
+
u
*
Math
.
cos
(
v
/
2
)
);
z
=
u
*
Math
.
sin
(
v
/
2
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
return
result
.
set
(
x
,
y
,
z
);
},
mobius3d
:
function
(
u
,
t
)
{
mobius3d
:
function
(
u
,
t
,
optionalTarget
)
{
var
result
=
optionalTarget
||
new
THREE
.
Vector3
();
// volumetric mobius strip
u
*=
Math
.
PI
;
t
*=
2
*
Math
.
PI
;
u
=
u
*
2
;
var
phi
=
u
/
2
;
var
major
=
2.25
,
a
=
0.125
,
b
=
0.65
;
var
x
,
y
,
z
;
x
=
a
*
Math
.
cos
(
t
)
*
Math
.
cos
(
phi
)
-
b
*
Math
.
sin
(
t
)
*
Math
.
sin
(
phi
);
z
=
a
*
Math
.
cos
(
t
)
*
Math
.
sin
(
phi
)
+
b
*
Math
.
sin
(
t
)
*
Math
.
cos
(
phi
);
y
=
(
major
+
x
)
*
Math
.
sin
(
u
);
x
=
(
major
+
x
)
*
Math
.
cos
(
u
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
return
result
.
set
(
x
,
y
,
z
);
}
...
...
@@ -108,7 +122,7 @@ THREE.ParametricGeometries.TubeGeometry = function( path, segments, radius, segm
x
,
y
,
z
,
tx
,
ty
,
tz
,
u
,
v
,
cx
,
cy
,
pos
,
pos2
=
new
THREE
.
Vector3
(),
cx
,
cy
,
pos
,
i
,
j
,
ip
,
jp
,
a
,
b
,
c
,
d
,
uva
,
uvb
,
uvc
,
uvd
;
var
frames
=
path
.
computeFrenetFrames
(
segments
,
closed
),
...
...
@@ -123,7 +137,9 @@ THREE.ParametricGeometries.TubeGeometry = function( path, segments, radius, segm
var
ParametricTube
=
function
(
u
,
v
)
{
var
ParametricTube
=
function
(
u
,
v
,
optionalTarget
)
{
var
result
=
optionalTarget
||
new
THREE
.
Vector3
();
v
*=
2
*
Math
.
PI
;
...
...
@@ -147,12 +163,11 @@ THREE.ParametricGeometries.TubeGeometry = function( path, segments, radius, segm
cx
=
-
scope
.
radius
*
Math
.
cos
(
v
);
// TODO: Hack: Negating it so it faces outside.
cy
=
scope
.
radius
*
Math
.
sin
(
v
);
pos2
.
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
;
pos
.
x
+=
cx
*
normal
.
x
+
cy
*
binormal
.
x
;
pos
.
y
+=
cx
*
normal
.
y
+
cy
*
binormal
.
y
;
pos
.
z
+=
cx
*
normal
.
z
+
cy
*
binormal
.
z
;
return
pos2
.
clone
(
);
return
result
.
copy
(
pos
);
};
...
...
@@ -222,7 +237,9 @@ THREE.ParametricGeometries.TorusKnotGeometry.prototype.constructor = THREE.Param
*********************************************/
THREE
.
ParametricGeometries
.
SphereGeometry
=
function
(
size
,
u
,
v
)
{
function
sphere
(
u
,
v
)
{
function
sphere
(
u
,
v
,
optionalTarget
)
{
var
result
=
optionalTarget
||
new
THREE
.
Vector3
();
u
*=
Math
.
PI
;
v
*=
2
*
Math
.
PI
;
...
...
@@ -231,8 +248,7 @@ THREE.ParametricGeometries.SphereGeometry = function( size, u, v ) {
var
y
=
size
*
Math
.
sin
(
u
)
*
Math
.
sin
(
v
);
var
z
=
size
*
Math
.
cos
(
u
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
return
result
.
set
(
x
,
y
,
z
);
}
...
...
@@ -252,13 +268,15 @@ THREE.ParametricGeometries.SphereGeometry.prototype.constructor = THREE.Parametr
THREE
.
ParametricGeometries
.
PlaneGeometry
=
function
(
width
,
depth
,
segmentsWidth
,
segmentsDepth
)
{
function
plane
(
u
,
v
)
{
function
plane
(
u
,
v
,
optionalTarget
)
{
var
result
=
optionalTarget
||
new
THREE
.
Vector3
();
var
x
=
u
*
width
;
var
y
=
0
;
var
z
=
v
*
depth
;
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
return
result
.
set
(
x
,
y
,
z
);
}
...
...
src/geometries/ParametricGeometry.js
浏览文件 @
254e09b7
...
...
@@ -58,7 +58,11 @@ function ParametricBufferGeometry( func, slices, stacks ) {
var
uvs
=
[];
var
EPS
=
0.00001
;
var
pu
=
new
Vector3
(),
pv
=
new
Vector3
(),
normal
=
new
Vector3
();
var
normal
=
new
Vector3
();
var
p0
=
new
Vector3
(),
p1
=
new
Vector3
();
var
pu
=
new
Vector3
(),
pv
=
new
Vector3
();
var
i
,
j
;
...
...
@@ -74,28 +78,36 @@ function ParametricBufferGeometry( func, slices, stacks ) {
var
u
=
j
/
slices
;
var
p
=
func
(
u
,
v
);
vertices
.
push
(
p
.
x
,
p
.
y
,
p
.
z
);
// vertex
p0
=
func
(
u
,
v
,
p0
);
vertices
.
push
(
p0
.
x
,
p0
.
y
,
p0
.
z
);
// normal
// approximate tangent vectors via finite differences
if
(
u
-
EPS
>=
0
)
{
pu
.
subVectors
(
p
,
func
(
u
-
EPS
,
v
)
);
p1
=
func
(
u
-
EPS
,
v
,
p1
);
pu
.
subVectors
(
p0
,
p1
);
}
else
{
pu
.
subVectors
(
func
(
u
+
EPS
,
v
),
p
);
p1
=
func
(
u
+
EPS
,
v
,
p1
);
pu
.
subVectors
(
p1
,
p0
);
}
if
(
v
-
EPS
>=
0
)
{
pv
.
subVectors
(
p
,
func
(
u
,
v
-
EPS
)
);
p1
=
func
(
u
,
v
-
EPS
,
p1
);
pv
.
subVectors
(
p0
,
p1
);
}
else
{
pv
.
subVectors
(
func
(
u
,
v
+
EPS
),
p
);
p1
=
func
(
u
,
v
+
EPS
,
p1
);
pv
.
subVectors
(
p1
,
p0
);
}
...
...
@@ -104,6 +116,8 @@ function ParametricBufferGeometry( func, slices, stacks ) {
normal
.
crossVectors
(
pu
,
pv
).
normalize
();
normals
.
push
(
normal
.
x
,
normal
.
y
,
normal
.
z
);
// uv
uvs
.
push
(
u
,
v
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录