Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
69da8d2e
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,发现更多精彩内容 >>
提交
69da8d2e
编写于
10月 03, 2011
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'Knectar/dev' into dev
上级
705f6967
5ef31d7f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
139 addition
and
0 deletion
+139
-0
src/extras/geometries/OctahedronGeometry.js
src/extras/geometries/OctahedronGeometry.js
+138
-0
utils/build.py
utils/build.py
+1
-0
未找到文件。
src/extras/geometries/OctahedronGeometry.js
0 → 100644
浏览文件 @
69da8d2e
/**
* Octahedrons have 8 sides. This octahedron supports subdivision.
*
* Vertices have 'smooth' normals,
* to make a sharp edge choose a material that uses face normals instead.
*
* @author daniel.deady@knectar.com
* @param radius
* @param detail Final number of triangles = 4^detail * 8
*/
THREE
.
OctahedronGeometry
=
function
(
radius
,
detail
)
{
THREE
.
Geometry
.
call
(
this
);
detail
=
isFinite
(
detail
)
?
detail
:
3
;
// allow a zero value
var
that
=
this
;
// ugly scope hack
prepare
(
new
THREE
.
Vector3
(
+
1
,
0
,
0
)
);
// right
prepare
(
new
THREE
.
Vector3
(
-
1
,
0
,
0
)
);
// left
prepare
(
new
THREE
.
Vector3
(
0
,
+
1
,
0
)
);
// up
prepare
(
new
THREE
.
Vector3
(
0
,
-
1
,
0
)
);
// down
prepare
(
new
THREE
.
Vector3
(
0
,
0
,
+
1
)
);
// front
prepare
(
new
THREE
.
Vector3
(
0
,
0
,
-
1
)
);
// back
var
midpoints
=
[],
p
=
this
.
vertices
;
// careful to output faces counter-clockwise, that is required for meshes
make
(
p
[
0
],
p
[
2
],
p
[
4
],
detail
);
make
(
p
[
0
],
p
[
4
],
p
[
3
],
detail
);
make
(
p
[
0
],
p
[
3
],
p
[
5
],
detail
);
make
(
p
[
0
],
p
[
5
],
p
[
2
],
detail
);
make
(
p
[
1
],
p
[
2
],
p
[
5
],
detail
);
make
(
p
[
1
],
p
[
5
],
p
[
3
],
detail
);
make
(
p
[
1
],
p
[
3
],
p
[
4
],
detail
);
make
(
p
[
1
],
p
[
4
],
p
[
2
],
detail
);
/**
* Project vector onto sphere's surface
*/
function
prepare
(
vector
)
{
var
normal
=
vector
.
clone
().
normalize
();
var
vertex
=
new
THREE
.
Vertex
(
normal
.
clone
().
multiplyScalar
(
radius
)
);
vertex
.
index
=
that
.
vertices
.
push
(
vertex
)
-
1
;
// Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
var
u
=
azimuth
(
vector
)
/
2
/
Math
.
PI
+
0.5
;
var
v
=
inclination
(
vector
)
/
Math
.
PI
+
0.5
;
vertex
.
uv
=
new
THREE
.
UV
(
u
,
v
);
return
vertex
;
}
/**
* Approximate a curved face with recursively sub-divided triangles.
*/
function
make
(
v1
,
v2
,
v3
,
detail
)
{
if
(
detail
<
1
)
{
var
face
=
new
THREE
.
Face3
(
v1
.
index
,
v2
.
index
,
v3
.
index
,
[
v1
.
position
,
v2
.
position
,
v3
.
position
]
);
face
.
centroid
.
addSelf
(
v1
.
position
).
addSelf
(
v2
.
position
).
addSelf
(
v3
.
position
).
divideScalar
(
3
);
face
.
normal
=
face
.
centroid
.
clone
().
normalize
();
that
.
faces
.
push
(
face
);
var
azi
=
azimuth
(
face
.
centroid
);
that
.
faceVertexUvs
[
0
].
push
(
[
correctUV
(
v1
.
uv
,
v1
.
position
,
azi
),
correctUV
(
v2
.
uv
,
v2
.
position
,
azi
),
correctUV
(
v3
.
uv
,
v3
.
position
,
azi
)
]
);
}
else
{
detail
-=
1
;
// split triangle into 4 smaller triangles
make
(
v1
,
midpoint
(
v1
,
v2
),
midpoint
(
v1
,
v3
),
detail
);
// top quadrant
make
(
midpoint
(
v1
,
v2
),
v2
,
midpoint
(
v2
,
v3
),
detail
);
// left quadrant
make
(
midpoint
(
v1
,
v3
),
midpoint
(
v2
,
v3
),
v3
,
detail
);
// right quadrant
make
(
midpoint
(
v1
,
v2
),
midpoint
(
v2
,
v3
),
midpoint
(
v1
,
v3
),
detail
);
// center quadrant
}
}
function
midpoint
(
v1
,
v2
)
{
if
(
!
midpoints
[
v1
.
index
]
)
midpoints
[
v1
.
index
]
=
[];
if
(
!
midpoints
[
v2
.
index
]
)
midpoints
[
v2
.
index
]
=
[];
var
mid
=
midpoints
[
v1
.
index
][
v2
.
index
];
if
(
mid
===
undefined
)
{
// generate mean point and project to surface with prepare()
midpoints
[
v1
.
index
][
v2
.
index
]
=
midpoints
[
v2
.
index
][
v1
.
index
]
=
mid
=
prepare
(
new
THREE
.
Vector3
().
add
(
v1
.
position
,
v2
.
position
).
divideScalar
(
2
)
);
}
return
mid
;
}
/**
* Angle around the Y axis, counter-clockwise when looking from above.
*/
function
azimuth
(
vector
)
{
return
Math
.
atan2
(
vector
.
z
,
-
vector
.
x
);
}
/**
* Angle above the XZ plane.
*/
function
inclination
(
vector
)
{
return
Math
.
atan2
(
-
vector
.
y
,
Math
.
sqrt
(
(
vector
.
x
*
vector
.
x
)
+
(
vector
.
z
*
vector
.
z
)
)
);
}
/**
* Texture fixing helper. Spheres have some odd behaviours.
*/
function
correctUV
(
uv
,
vector
,
azimuth
)
{
if
(
(
azimuth
<
0
)
&&
(
uv
.
u
===
1
)
)
uv
=
new
THREE
.
UV
(
uv
.
u
-
1
,
uv
.
v
);
if
(
(
vector
.
x
===
0
)
&&
(
vector
.
z
===
0
)
)
uv
=
new
THREE
.
UV
(
azimuth
/
2
/
Math
.
PI
+
0.5
,
uv
.
v
);
return
uv
;
}
this
.
boundingSphere
=
{
radius
:
radius
};
};
THREE
.
OctahedronGeometry
.
prototype
=
new
THREE
.
Geometry
();
THREE
.
OctahedronGeometry
.
prototype
.
constructor
=
THREE
.
OctahedronGeometry
;
utils/build.py
浏览文件 @
69da8d2e
...
...
@@ -104,6 +104,7 @@ EXTRAS_FILES = [
'extras/geometries/ExtrudeGeometry.js'
,
'extras/geometries/IcosahedronGeometry.js'
,
'extras/geometries/LatheGeometry.js'
,
'extras/geometries/OctahedronGeometry.js'
,
'extras/geometries/PlaneGeometry.js'
,
'extras/geometries/SphereGeometry.js'
,
'extras/geometries/TextGeometry.js'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录