Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
f1e4f59a
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,发现更多精彩内容 >>
提交
f1e4f59a
编写于
7月 09, 2011
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into dev
上级
82a0bcfc
8544110f
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
334 addition
and
255 deletion
+334
-255
build/Three.js
build/Three.js
+49
-48
build/custom/ThreeCanvas.js
build/custom/ThreeCanvas.js
+1
-1
build/custom/ThreeDOM.js
build/custom/ThreeDOM.js
+1
-1
build/custom/ThreeExtras.js
build/custom/ThreeExtras.js
+59
-58
build/custom/ThreeSVG.js
build/custom/ThreeSVG.js
+1
-1
build/custom/ThreeWebGL.js
build/custom/ThreeWebGL.js
+18
-18
src/extras/ShaderUtils.js
src/extras/ShaderUtils.js
+5
-0
src/extras/io/Loader.js
src/extras/io/Loader.js
+21
-4
src/extras/io/SceneLoader.js
src/extras/io/SceneLoader.js
+15
-4
src/renderers/WebGLShaders.js
src/renderers/WebGLShaders.js
+23
-6
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/export_threejs.py
...der/2.58/scripts/addons/io_mesh_threejs/export_threejs.py
+32
-5
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/import_threejs.py
...der/2.58/scripts/addons/io_mesh_threejs/import_threejs.py
+109
-109
未找到文件。
build/Three.js
浏览文件 @
f1e4f59a
此差异已折叠。
点击以展开。
build/custom/ThreeCanvas.js
浏览文件 @
f1e4f59a
...
...
@@ -53,7 +53,7 @@ THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;thi
d
;
this
.
z
=
a
.
z
*
d
;
this
.
w
=
Math
.
cos
(
c
);
return
this
},
calculateW
:
function
(){
this
.
w
=-
Math
.
sqrt
(
Math
.
abs
(
1
-
this
.
x
*
this
.
x
-
this
.
y
*
this
.
y
-
this
.
z
*
this
.
z
));
return
this
},
inverse
:
function
(){
this
.
x
*=-
1
;
this
.
y
*=-
1
;
this
.
z
*=-
1
;
return
this
},
length
:
function
(){
return
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
+
this
.
w
*
this
.
w
)},
normalize
:
function
(){
var
a
=
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
+
this
.
w
*
this
.
w
);
a
==
0
?
this
.
w
=
this
.
z
=
this
.
y
=
this
.
x
=
0
:(
a
=
1
/
a
,
this
.
x
*=
a
,
this
.
y
*=
a
,
this
.
z
*=
a
,
this
.
w
*=
a
);
return
this
},
multiplySelf
:
function
(
a
){
var
b
=
this
.
x
,
c
=
this
.
y
,
d
=
this
.
z
,
f
=
this
.
w
,
g
=
a
.
x
,
e
=
a
.
y
,
h
=
a
.
z
,
a
=
a
.
w
;
this
.
x
=
b
*
a
+
f
*
g
+
c
*
h
-
d
*
e
;
this
.
y
=
c
*
a
+
f
*
e
+
d
*
g
-
b
*
h
;
this
.
z
=
d
*
a
+
f
*
h
+
b
*
e
-
c
*
g
;
this
.
w
=
f
*
a
-
b
*
g
-
c
*
e
-
d
*
h
;
return
this
},
multiply
:
function
(
a
,
b
){
this
.
x
=
a
.
x
*
b
.
w
+
a
.
y
*
b
.
z
-
a
.
z
*
b
.
y
+
a
.
w
*
b
.
x
;
this
.
y
=-
a
.
x
*
b
.
z
+
a
.
y
*
b
.
w
+
a
.
z
*
b
.
x
+
a
.
w
*
b
.
y
;
this
.
z
=
a
.
x
*
b
.
y
-
a
.
y
*
b
.
x
+
a
.
z
*
b
.
w
+
a
.
w
*
b
.
z
;
this
.
w
=-
a
.
x
*
b
.
x
-
a
.
y
*
b
.
y
-
a
.
z
*
b
.
z
+
a
.
w
*
b
.
w
;
return
this
},
multiplyVector3
:
function
(
a
,
b
){
b
||
(
b
=
a
);
var
c
=
a
.
x
,
d
=
a
.
y
,
f
=
a
.
z
,
g
=
this
.
x
,
e
=
this
.
y
,
h
=
this
.
z
,
i
=
this
.
w
,
l
=
i
*
c
+
e
*
f
-
h
*
d
,
m
=
i
*
d
+
h
*
c
-
g
*
f
,
j
=
i
*
f
+
g
*
d
-
e
*
c
,
c
=-
g
*
c
-
e
*
d
-
h
*
f
;
b
.
x
=
l
*
i
+
c
*-
g
+
m
*-
h
-
j
*-
e
;
b
.
y
=
m
*
i
+
c
*-
e
+
j
*-
g
-
l
*-
h
;
b
.
z
=
j
*
i
+
c
*-
h
+
l
*-
e
-
m
*-
g
;
return
b
}};
THREE
.
Quaternion
.
slerp
=
function
(
a
,
b
,
c
,
d
){
var
f
=
a
.
w
*
b
.
w
+
a
.
x
*
b
.
x
+
a
.
y
*
b
.
y
+
a
.
z
*
b
.
z
;
if
(
Math
.
abs
(
f
)
>=
1
)
return
c
.
w
=
a
.
w
,
c
.
x
=
a
.
x
,
c
.
y
=
a
.
y
,
c
.
z
=
a
.
z
,
c
;
var
g
=
Math
.
acos
(
f
),
e
=
Math
.
sqrt
(
1
-
f
*
f
);
if
(
Math
.
abs
(
e
)
<
0.001
)
return
c
.
w
=
0.5
*
(
a
.
w
+
b
.
w
),
c
.
x
=
0.5
*
(
a
.
x
+
b
.
x
),
c
.
y
=
0.5
*
(
a
.
y
+
b
.
y
),
c
.
z
=
0.5
*
(
a
.
z
+
b
.
z
),
c
;
f
=
Math
.
sin
((
1
-
d
)
*
g
)
/
e
;
d
=
Math
.
sin
(
d
*
g
)
/
e
;
c
.
w
=
a
.
w
*
f
+
b
.
w
*
d
;
c
.
x
=
a
.
x
*
f
+
b
.
x
*
d
;
c
.
y
=
a
.
y
*
f
+
b
.
y
*
d
;
c
.
z
=
a
.
z
*
f
+
b
.
z
*
d
;
return
c
};
THREE
.
Vertex
=
function
(
a
){
this
.
position
=
a
||
new
THREE
.
Vector3
};
THREE
.
Quaternion
.
slerp
=
function
(
a
,
b
,
c
,
d
){
var
f
=
a
.
w
*
b
.
w
+
a
.
x
*
b
.
x
+
a
.
y
*
b
.
y
+
a
.
z
*
b
.
z
;
if
(
Math
.
abs
(
f
)
>=
1
)
return
c
.
w
=
a
.
w
,
c
.
x
=
a
.
x
,
c
.
y
=
a
.
y
,
c
.
z
=
a
.
z
,
c
;
var
g
=
Math
.
acos
(
f
),
e
=
Math
.
sqrt
(
1
-
f
*
f
);
if
(
Math
.
abs
(
e
)
<
0.001
0
)
return
c
.
w
=
0.5
*
(
a
.
w
+
b
.
w
),
c
.
x
=
0.5
*
(
a
.
x
+
b
.
x
),
c
.
y
=
0.5
*
(
a
.
y
+
b
.
y
),
c
.
z
=
0.5
*
(
a
.
z
+
b
.
z
),
c
;
f
=
Math
.
sin
((
1
-
d
)
*
g
)
/
e
;
d
=
Math
.
sin
(
d
*
g
)
/
e
;
c
.
w
=
a
.
w
*
f
+
b
.
w
*
d
;
c
.
x
=
a
.
x
*
f
+
b
.
x
*
d
;
c
.
y
=
a
.
y
*
f
+
b
.
y
*
d
;
c
.
z
=
a
.
z
*
f
+
b
.
z
*
d
;
return
c
};
THREE
.
Vertex
=
function
(
a
){
this
.
position
=
a
||
new
THREE
.
Vector3
};
THREE
.
Face3
=
function
(
a
,
b
,
c
,
d
,
f
,
g
){
this
.
a
=
a
;
this
.
b
=
b
;
this
.
c
=
c
;
this
.
normal
=
d
instanceof
THREE
.
Vector3
?
d
:
new
THREE
.
Vector3
;
this
.
vertexNormals
=
d
instanceof
Array
?
d
:[];
this
.
color
=
f
instanceof
THREE
.
Color
?
f
:
new
THREE
.
Color
;
this
.
vertexColors
=
f
instanceof
Array
?
f
:[];
this
.
vertexTangents
=
[];
this
.
materials
=
g
instanceof
Array
?
g
:[
g
];
this
.
centroid
=
new
THREE
.
Vector3
};
THREE
.
Face4
=
function
(
a
,
b
,
c
,
d
,
f
,
g
,
e
){
this
.
a
=
a
;
this
.
b
=
b
;
this
.
c
=
c
;
this
.
d
=
d
;
this
.
normal
=
f
instanceof
THREE
.
Vector3
?
f
:
new
THREE
.
Vector3
;
this
.
vertexNormals
=
f
instanceof
Array
?
f
:[];
this
.
color
=
g
instanceof
THREE
.
Color
?
g
:
new
THREE
.
Color
;
this
.
vertexColors
=
g
instanceof
Array
?
g
:[];
this
.
vertexTangents
=
[];
this
.
materials
=
e
instanceof
Array
?
e
:[
e
];
this
.
centroid
=
new
THREE
.
Vector3
};
THREE
.
UV
=
function
(
a
,
b
){
this
.
set
(
a
||
0
,
b
||
0
)};
THREE
.
UV
.
prototype
=
{
set
:
function
(
a
,
b
){
this
.
u
=
a
;
this
.
v
=
b
;
return
this
},
copy
:
function
(
a
){
this
.
set
(
a
.
u
,
a
.
v
);
return
this
}};
THREE
.
Geometry
=
function
(){
this
.
id
=
"
Geometry
"
+
THREE
.
GeometryIdCounter
++
;
this
.
vertices
=
[];
this
.
colors
=
[];
this
.
faces
=
[];
this
.
edges
=
[];
this
.
faceUvs
=
[[]];
this
.
faceVertexUvs
=
[[]];
this
.
morphTargets
=
[];
this
.
morphColors
=
[];
this
.
skinWeights
=
[];
this
.
skinIndices
=
[];
this
.
boundingSphere
=
this
.
boundingBox
=
null
;
this
.
hasTangents
=!
1
};
...
...
build/custom/ThreeDOM.js
浏览文件 @
f1e4f59a
...
...
@@ -53,7 +53,7 @@ THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;thi
d
;
this
.
z
=
a
.
z
*
d
;
this
.
w
=
Math
.
cos
(
c
);
return
this
},
calculateW
:
function
(){
this
.
w
=-
Math
.
sqrt
(
Math
.
abs
(
1
-
this
.
x
*
this
.
x
-
this
.
y
*
this
.
y
-
this
.
z
*
this
.
z
));
return
this
},
inverse
:
function
(){
this
.
x
*=-
1
;
this
.
y
*=-
1
;
this
.
z
*=-
1
;
return
this
},
length
:
function
(){
return
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
+
this
.
w
*
this
.
w
)},
normalize
:
function
(){
var
a
=
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
+
this
.
w
*
this
.
w
);
a
==
0
?
this
.
w
=
this
.
z
=
this
.
y
=
this
.
x
=
0
:(
a
=
1
/
a
,
this
.
x
*=
a
,
this
.
y
*=
a
,
this
.
z
*=
a
,
this
.
w
*=
a
);
return
this
},
multiplySelf
:
function
(
a
){
var
b
=
this
.
x
,
c
=
this
.
y
,
d
=
this
.
z
,
e
=
this
.
w
,
g
=
a
.
x
,
f
=
a
.
y
,
h
=
a
.
z
,
a
=
a
.
w
;
this
.
x
=
b
*
a
+
e
*
g
+
c
*
h
-
d
*
f
;
this
.
y
=
c
*
a
+
e
*
f
+
d
*
g
-
b
*
h
;
this
.
z
=
d
*
a
+
e
*
h
+
b
*
f
-
c
*
g
;
this
.
w
=
e
*
a
-
b
*
g
-
c
*
f
-
d
*
h
;
return
this
},
multiply
:
function
(
a
,
b
){
this
.
x
=
a
.
x
*
b
.
w
+
a
.
y
*
b
.
z
-
a
.
z
*
b
.
y
+
a
.
w
*
b
.
x
;
this
.
y
=-
a
.
x
*
b
.
z
+
a
.
y
*
b
.
w
+
a
.
z
*
b
.
x
+
a
.
w
*
b
.
y
;
this
.
z
=
a
.
x
*
b
.
y
-
a
.
y
*
b
.
x
+
a
.
z
*
b
.
w
+
a
.
w
*
b
.
z
;
this
.
w
=-
a
.
x
*
b
.
x
-
a
.
y
*
b
.
y
-
a
.
z
*
b
.
z
+
a
.
w
*
b
.
w
;
return
this
},
multiplyVector3
:
function
(
a
,
b
){
b
||
(
b
=
a
);
var
c
=
a
.
x
,
d
=
a
.
y
,
e
=
a
.
z
,
g
=
this
.
x
,
f
=
this
.
y
,
h
=
this
.
z
,
j
=
this
.
w
,
i
=
j
*
c
+
f
*
e
-
h
*
d
,
k
=
j
*
d
+
h
*
c
-
g
*
e
,
l
=
j
*
e
+
g
*
d
-
f
*
c
,
c
=-
g
*
c
-
f
*
d
-
h
*
e
;
b
.
x
=
i
*
j
+
c
*-
g
+
k
*-
h
-
l
*-
f
;
b
.
y
=
k
*
j
+
c
*-
f
+
l
*-
g
-
i
*-
h
;
b
.
z
=
l
*
j
+
c
*-
h
+
i
*-
f
-
k
*-
g
;
return
b
}};
THREE
.
Quaternion
.
slerp
=
function
(
a
,
b
,
c
,
d
){
var
e
=
a
.
w
*
b
.
w
+
a
.
x
*
b
.
x
+
a
.
y
*
b
.
y
+
a
.
z
*
b
.
z
;
if
(
Math
.
abs
(
e
)
>=
1
)
return
c
.
w
=
a
.
w
,
c
.
x
=
a
.
x
,
c
.
y
=
a
.
y
,
c
.
z
=
a
.
z
,
c
;
var
g
=
Math
.
acos
(
e
),
f
=
Math
.
sqrt
(
1
-
e
*
e
);
if
(
Math
.
abs
(
f
)
<
0.001
)
return
c
.
w
=
0.5
*
(
a
.
w
+
b
.
w
),
c
.
x
=
0.5
*
(
a
.
x
+
b
.
x
),
c
.
y
=
0.5
*
(
a
.
y
+
b
.
y
),
c
.
z
=
0.5
*
(
a
.
z
+
b
.
z
),
c
;
e
=
Math
.
sin
((
1
-
d
)
*
g
)
/
f
;
d
=
Math
.
sin
(
d
*
g
)
/
f
;
c
.
w
=
a
.
w
*
e
+
b
.
w
*
d
;
c
.
x
=
a
.
x
*
e
+
b
.
x
*
d
;
c
.
y
=
a
.
y
*
e
+
b
.
y
*
d
;
c
.
z
=
a
.
z
*
e
+
b
.
z
*
d
;
return
c
};
THREE
.
Vertex
=
function
(
a
){
this
.
position
=
a
||
new
THREE
.
Vector3
};
THREE
.
Quaternion
.
slerp
=
function
(
a
,
b
,
c
,
d
){
var
e
=
a
.
w
*
b
.
w
+
a
.
x
*
b
.
x
+
a
.
y
*
b
.
y
+
a
.
z
*
b
.
z
;
if
(
Math
.
abs
(
e
)
>=
1
)
return
c
.
w
=
a
.
w
,
c
.
x
=
a
.
x
,
c
.
y
=
a
.
y
,
c
.
z
=
a
.
z
,
c
;
var
g
=
Math
.
acos
(
e
),
f
=
Math
.
sqrt
(
1
-
e
*
e
);
if
(
Math
.
abs
(
f
)
<
0.001
0
)
return
c
.
w
=
0.5
*
(
a
.
w
+
b
.
w
),
c
.
x
=
0.5
*
(
a
.
x
+
b
.
x
),
c
.
y
=
0.5
*
(
a
.
y
+
b
.
y
),
c
.
z
=
0.5
*
(
a
.
z
+
b
.
z
),
c
;
e
=
Math
.
sin
((
1
-
d
)
*
g
)
/
f
;
d
=
Math
.
sin
(
d
*
g
)
/
f
;
c
.
w
=
a
.
w
*
e
+
b
.
w
*
d
;
c
.
x
=
a
.
x
*
e
+
b
.
x
*
d
;
c
.
y
=
a
.
y
*
e
+
b
.
y
*
d
;
c
.
z
=
a
.
z
*
e
+
b
.
z
*
d
;
return
c
};
THREE
.
Vertex
=
function
(
a
){
this
.
position
=
a
||
new
THREE
.
Vector3
};
THREE
.
Face3
=
function
(
a
,
b
,
c
,
d
,
e
,
g
){
this
.
a
=
a
;
this
.
b
=
b
;
this
.
c
=
c
;
this
.
normal
=
d
instanceof
THREE
.
Vector3
?
d
:
new
THREE
.
Vector3
;
this
.
vertexNormals
=
d
instanceof
Array
?
d
:[];
this
.
color
=
e
instanceof
THREE
.
Color
?
e
:
new
THREE
.
Color
;
this
.
vertexColors
=
e
instanceof
Array
?
e
:[];
this
.
vertexTangents
=
[];
this
.
materials
=
g
instanceof
Array
?
g
:[
g
];
this
.
centroid
=
new
THREE
.
Vector3
};
THREE
.
Face4
=
function
(
a
,
b
,
c
,
d
,
e
,
g
,
f
){
this
.
a
=
a
;
this
.
b
=
b
;
this
.
c
=
c
;
this
.
d
=
d
;
this
.
normal
=
e
instanceof
THREE
.
Vector3
?
e
:
new
THREE
.
Vector3
;
this
.
vertexNormals
=
e
instanceof
Array
?
e
:[];
this
.
color
=
g
instanceof
THREE
.
Color
?
g
:
new
THREE
.
Color
;
this
.
vertexColors
=
g
instanceof
Array
?
g
:[];
this
.
vertexTangents
=
[];
this
.
materials
=
f
instanceof
Array
?
f
:[
f
];
this
.
centroid
=
new
THREE
.
Vector3
};
THREE
.
UV
=
function
(
a
,
b
){
this
.
set
(
a
||
0
,
b
||
0
)};
THREE
.
UV
.
prototype
=
{
set
:
function
(
a
,
b
){
this
.
u
=
a
;
this
.
v
=
b
;
return
this
},
copy
:
function
(
a
){
this
.
set
(
a
.
u
,
a
.
v
);
return
this
}};
THREE
.
Camera
=
function
(
a
,
b
,
c
,
d
,
e
){
THREE
.
Object3D
.
call
(
this
);
this
.
fov
=
a
||
50
;
this
.
aspect
=
b
||
1
;
this
.
near
=
c
||
0.1
;
this
.
far
=
d
||
2
E3
;
this
.
target
=
e
||
new
THREE
.
Object3D
;
this
.
useTarget
=!
0
;
this
.
matrixWorldInverse
=
new
THREE
.
Matrix4
;
this
.
projectionMatrix
=
null
;
this
.
updateProjectionMatrix
()};
THREE
.
Camera
.
prototype
=
new
THREE
.
Object3D
;
THREE
.
Camera
.
prototype
.
constructor
=
THREE
.
Camera
;
...
...
build/custom/ThreeExtras.js
浏览文件 @
f1e4f59a
此差异已折叠。
点击以展开。
build/custom/ThreeSVG.js
浏览文件 @
f1e4f59a
...
...
@@ -53,7 +53,7 @@ THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;thi
d
;
this
.
z
=
a
.
z
*
d
;
this
.
w
=
Math
.
cos
(
c
);
return
this
},
calculateW
:
function
(){
this
.
w
=-
Math
.
sqrt
(
Math
.
abs
(
1
-
this
.
x
*
this
.
x
-
this
.
y
*
this
.
y
-
this
.
z
*
this
.
z
));
return
this
},
inverse
:
function
(){
this
.
x
*=-
1
;
this
.
y
*=-
1
;
this
.
z
*=-
1
;
return
this
},
length
:
function
(){
return
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
+
this
.
w
*
this
.
w
)},
normalize
:
function
(){
var
a
=
Math
.
sqrt
(
this
.
x
*
this
.
x
+
this
.
y
*
this
.
y
+
this
.
z
*
this
.
z
+
this
.
w
*
this
.
w
);
a
==
0
?
this
.
w
=
this
.
z
=
this
.
y
=
this
.
x
=
0
:(
a
=
1
/
a
,
this
.
x
*=
a
,
this
.
y
*=
a
,
this
.
z
*=
a
,
this
.
w
*=
a
);
return
this
},
multiplySelf
:
function
(
a
){
var
b
=
this
.
x
,
c
=
this
.
y
,
d
=
this
.
z
,
e
=
this
.
w
,
g
=
a
.
x
,
f
=
a
.
y
,
h
=
a
.
z
,
a
=
a
.
w
;
this
.
x
=
b
*
a
+
e
*
g
+
c
*
h
-
d
*
f
;
this
.
y
=
c
*
a
+
e
*
f
+
d
*
g
-
b
*
h
;
this
.
z
=
d
*
a
+
e
*
h
+
b
*
f
-
c
*
g
;
this
.
w
=
e
*
a
-
b
*
g
-
c
*
f
-
d
*
h
;
return
this
},
multiply
:
function
(
a
,
b
){
this
.
x
=
a
.
x
*
b
.
w
+
a
.
y
*
b
.
z
-
a
.
z
*
b
.
y
+
a
.
w
*
b
.
x
;
this
.
y
=-
a
.
x
*
b
.
z
+
a
.
y
*
b
.
w
+
a
.
z
*
b
.
x
+
a
.
w
*
b
.
y
;
this
.
z
=
a
.
x
*
b
.
y
-
a
.
y
*
b
.
x
+
a
.
z
*
b
.
w
+
a
.
w
*
b
.
z
;
this
.
w
=-
a
.
x
*
b
.
x
-
a
.
y
*
b
.
y
-
a
.
z
*
b
.
z
+
a
.
w
*
b
.
w
;
return
this
},
multiplyVector3
:
function
(
a
,
b
){
b
||
(
b
=
a
);
var
c
=
a
.
x
,
d
=
a
.
y
,
e
=
a
.
z
,
g
=
this
.
x
,
f
=
this
.
y
,
h
=
this
.
z
,
k
=
this
.
w
,
l
=
k
*
c
+
f
*
e
-
h
*
d
,
i
=
k
*
d
+
h
*
c
-
g
*
e
,
j
=
k
*
e
+
g
*
d
-
f
*
c
,
c
=-
g
*
c
-
f
*
d
-
h
*
e
;
b
.
x
=
l
*
k
+
c
*-
g
+
i
*-
h
-
j
*-
f
;
b
.
y
=
i
*
k
+
c
*-
f
+
j
*-
g
-
l
*-
h
;
b
.
z
=
j
*
k
+
c
*-
h
+
l
*-
f
-
i
*-
g
;
return
b
}};
THREE
.
Quaternion
.
slerp
=
function
(
a
,
b
,
c
,
d
){
var
e
=
a
.
w
*
b
.
w
+
a
.
x
*
b
.
x
+
a
.
y
*
b
.
y
+
a
.
z
*
b
.
z
;
if
(
Math
.
abs
(
e
)
>=
1
)
return
c
.
w
=
a
.
w
,
c
.
x
=
a
.
x
,
c
.
y
=
a
.
y
,
c
.
z
=
a
.
z
,
c
;
var
g
=
Math
.
acos
(
e
),
f
=
Math
.
sqrt
(
1
-
e
*
e
);
if
(
Math
.
abs
(
f
)
<
0.001
)
return
c
.
w
=
0.5
*
(
a
.
w
+
b
.
w
),
c
.
x
=
0.5
*
(
a
.
x
+
b
.
x
),
c
.
y
=
0.5
*
(
a
.
y
+
b
.
y
),
c
.
z
=
0.5
*
(
a
.
z
+
b
.
z
),
c
;
e
=
Math
.
sin
((
1
-
d
)
*
g
)
/
f
;
d
=
Math
.
sin
(
d
*
g
)
/
f
;
c
.
w
=
a
.
w
*
e
+
b
.
w
*
d
;
c
.
x
=
a
.
x
*
e
+
b
.
x
*
d
;
c
.
y
=
a
.
y
*
e
+
b
.
y
*
d
;
c
.
z
=
a
.
z
*
e
+
b
.
z
*
d
;
return
c
};
THREE
.
Vertex
=
function
(
a
){
this
.
position
=
a
||
new
THREE
.
Vector3
};
THREE
.
Quaternion
.
slerp
=
function
(
a
,
b
,
c
,
d
){
var
e
=
a
.
w
*
b
.
w
+
a
.
x
*
b
.
x
+
a
.
y
*
b
.
y
+
a
.
z
*
b
.
z
;
if
(
Math
.
abs
(
e
)
>=
1
)
return
c
.
w
=
a
.
w
,
c
.
x
=
a
.
x
,
c
.
y
=
a
.
y
,
c
.
z
=
a
.
z
,
c
;
var
g
=
Math
.
acos
(
e
),
f
=
Math
.
sqrt
(
1
-
e
*
e
);
if
(
Math
.
abs
(
f
)
<
0.001
0
)
return
c
.
w
=
0.5
*
(
a
.
w
+
b
.
w
),
c
.
x
=
0.5
*
(
a
.
x
+
b
.
x
),
c
.
y
=
0.5
*
(
a
.
y
+
b
.
y
),
c
.
z
=
0.5
*
(
a
.
z
+
b
.
z
),
c
;
e
=
Math
.
sin
((
1
-
d
)
*
g
)
/
f
;
d
=
Math
.
sin
(
d
*
g
)
/
f
;
c
.
w
=
a
.
w
*
e
+
b
.
w
*
d
;
c
.
x
=
a
.
x
*
e
+
b
.
x
*
d
;
c
.
y
=
a
.
y
*
e
+
b
.
y
*
d
;
c
.
z
=
a
.
z
*
e
+
b
.
z
*
d
;
return
c
};
THREE
.
Vertex
=
function
(
a
){
this
.
position
=
a
||
new
THREE
.
Vector3
};
THREE
.
Face3
=
function
(
a
,
b
,
c
,
d
,
e
,
g
){
this
.
a
=
a
;
this
.
b
=
b
;
this
.
c
=
c
;
this
.
normal
=
d
instanceof
THREE
.
Vector3
?
d
:
new
THREE
.
Vector3
;
this
.
vertexNormals
=
d
instanceof
Array
?
d
:[];
this
.
color
=
e
instanceof
THREE
.
Color
?
e
:
new
THREE
.
Color
;
this
.
vertexColors
=
e
instanceof
Array
?
e
:[];
this
.
vertexTangents
=
[];
this
.
materials
=
g
instanceof
Array
?
g
:[
g
];
this
.
centroid
=
new
THREE
.
Vector3
};
THREE
.
Face4
=
function
(
a
,
b
,
c
,
d
,
e
,
g
,
f
){
this
.
a
=
a
;
this
.
b
=
b
;
this
.
c
=
c
;
this
.
d
=
d
;
this
.
normal
=
e
instanceof
THREE
.
Vector3
?
e
:
new
THREE
.
Vector3
;
this
.
vertexNormals
=
e
instanceof
Array
?
e
:[];
this
.
color
=
g
instanceof
THREE
.
Color
?
g
:
new
THREE
.
Color
;
this
.
vertexColors
=
g
instanceof
Array
?
g
:[];
this
.
vertexTangents
=
[];
this
.
materials
=
f
instanceof
Array
?
f
:[
f
];
this
.
centroid
=
new
THREE
.
Vector3
};
THREE
.
UV
=
function
(
a
,
b
){
this
.
set
(
a
||
0
,
b
||
0
)};
THREE
.
UV
.
prototype
=
{
set
:
function
(
a
,
b
){
this
.
u
=
a
;
this
.
v
=
b
;
return
this
},
copy
:
function
(
a
){
this
.
set
(
a
.
u
,
a
.
v
);
return
this
}};
THREE
.
Geometry
=
function
(){
this
.
id
=
"
Geometry
"
+
THREE
.
GeometryIdCounter
++
;
this
.
vertices
=
[];
this
.
colors
=
[];
this
.
faces
=
[];
this
.
edges
=
[];
this
.
faceUvs
=
[[]];
this
.
faceVertexUvs
=
[[]];
this
.
morphTargets
=
[];
this
.
morphColors
=
[];
this
.
skinWeights
=
[];
this
.
skinIndices
=
[];
this
.
boundingSphere
=
this
.
boundingBox
=
null
;
this
.
hasTangents
=!
1
};
...
...
build/custom/ThreeWebGL.js
浏览文件 @
f1e4f59a
此差异已折叠。
点击以展开。
src/extras/ShaderUtils.js
浏览文件 @
f1e4f59a
...
...
@@ -95,6 +95,7 @@ THREE.ShaderUtils = {
uniforms
:
THREE
.
UniformsUtils
.
merge
(
[
THREE
.
UniformsLib
[
"
fog
"
],
THREE
.
UniformsLib
[
"
lights
"
],
{
...
...
@@ -162,6 +163,8 @@ THREE.ShaderUtils = {
"
varying vec3 vViewPosition;
"
,
THREE
.
ShaderChunk
[
"
fog_pars_fragment
"
],
"
void main() {
"
,
"
gl_FragColor = vec4( 1.0 );
"
,
...
...
@@ -255,6 +258,8 @@ THREE.ShaderUtils = {
"
gl_FragColor = gl_FragColor * totalLight;
"
,
THREE
.
ShaderChunk
[
"
fog_fragment
"
],
"
}
"
].
join
(
"
\n
"
),
...
...
src/extras/io/Loader.js
浏览文件 @
f1e4f59a
...
...
@@ -293,6 +293,12 @@ THREE.Loader.prototype = {
}
if
(
m
.
mapSpecular
&&
texture_path
)
{
create_texture
(
mpars
,
"
specularMap
"
,
m
.
mapSpecular
,
m
.
mapSpecularRepeat
,
m
.
mapSpecularOffset
,
m
.
mapSpecularWrap
);
}
// special case for normal mapped material
if
(
m
.
mapNormal
)
{
...
...
@@ -320,10 +326,21 @@ THREE.Loader.prototype = {
}
// for the moment don't handle specular, AO and displacement textures
if
(
mpars
.
specularMap
)
{
uniforms
[
"
tSpecular
"
].
texture
=
mpars
.
specularMap
;
uniforms
[
"
enableSpecular
"
].
value
=
true
;
}
if
(
mpars
.
lightMap
)
{
uniforms
[
"
tAO
"
].
texture
=
mpars
.
lightMap
;
uniforms
[
"
enableAO
"
].
value
=
true
;
}
uniforms
[
"
enableAO
"
].
value
=
false
;
uniforms
[
"
enableSpecular
"
].
value
=
false
;
// for the moment don't handle displacement texture
uniforms
[
"
uDiffuseColor
"
].
value
.
setHex
(
diffuse
);
uniforms
[
"
uSpecularColor
"
].
value
.
setHex
(
specular
);
...
...
@@ -337,7 +354,7 @@ THREE.Loader.prototype = {
}
var
parameters
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShader
,
uniforms
:
uniforms
,
lights
:
true
};
var
parameters
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShader
,
uniforms
:
uniforms
,
lights
:
true
,
fog
:
true
};
material
=
new
THREE
.
MeshShaderMaterial
(
parameters
);
...
...
src/extras/io/SceneLoader.js
浏览文件 @
f1e4f59a
...
...
@@ -535,7 +535,7 @@ THREE.SceneLoader.prototype = {
if
(
modelJson
)
{
jsonLoader
.
createModel
(
modelJson
,
create_callback_embed
(
dg
),
texture_path
);
}
}
...
...
@@ -713,8 +713,19 @@ THREE.SceneLoader.prototype = {
}
uniforms
[
"
enableAO
"
].
value
=
false
;
uniforms
[
"
enableSpecular
"
].
value
=
false
;
if
(
m
.
parameters
.
lightMap
)
{
uniforms
[
"
tAO
"
].
texture
=
m
.
parameters
.
lightMap
;
uniforms
[
"
enableAO
"
].
value
=
true
;
}
if
(
m
.
parameters
.
specularMap
)
{
uniforms
[
"
tSpecular
"
].
texture
=
result
.
textures
[
m
.
parameters
.
specularMap
];
uniforms
[
"
enableSpecular
"
].
value
=
true
;
}
uniforms
[
"
uDiffuseColor
"
].
value
.
setHex
(
diffuse
);
uniforms
[
"
uSpecularColor
"
].
value
.
setHex
(
specular
);
...
...
@@ -728,7 +739,7 @@ THREE.SceneLoader.prototype = {
}
var
parameters
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShader
,
uniforms
:
uniforms
,
lights
:
true
};
var
parameters
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShader
,
uniforms
:
uniforms
,
lights
:
true
,
fog
:
true
};
material
=
new
THREE
.
MeshShaderMaterial
(
parameters
);
...
...
src/renderers/WebGLShaders.js
浏览文件 @
f1e4f59a
...
...
@@ -588,12 +588,16 @@ THREE.UniformsLib = {
"
refractionRatio
"
:
{
type
:
"
f
"
,
value
:
0.98
},
"
combine
"
:
{
type
:
"
i
"
,
value
:
0
},
"
morphTargetInfluences
"
:
{
type
:
"
f
"
,
value
:
0
}
},
fog
:
{
"
fogDensity
"
:
{
type
:
"
f
"
,
value
:
0.00025
},
"
fogNear
"
:
{
type
:
"
f
"
,
value
:
1
},
"
fogFar
"
:
{
type
:
"
f
"
,
value
:
2000
},
"
fogColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0xffffff
)
},
"
morphTargetInfluences
"
:
{
type
:
"
f
"
,
value
:
0
}
"
fogColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0xffffff
)
}
},
...
...
@@ -664,7 +668,7 @@ THREE.ShaderLib = {
"
vVisibility = ( visibility.r / 9.0 ) *
"
,
"
( 1.0 - visibility.g / 9.0 ) *
"
,
"
( visibility.b / 9.0 ) *
"
,
"
( visibility.b / 9.0 ) *
"
,
"
( 1.0 - visibility.a / 9.0 );
"
,
"
pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;
"
,
...
...
@@ -1016,7 +1020,12 @@ THREE.ShaderLib = {
'
basic
'
:
{
uniforms
:
THREE
.
UniformsLib
[
"
common
"
],
uniforms
:
THREE
.
UniformsUtils
.
merge
(
[
THREE
.
UniformsLib
[
"
common
"
],
THREE
.
UniformsLib
[
"
fog
"
]
]
),
fragmentShader
:
[
...
...
@@ -1072,7 +1081,13 @@ THREE.ShaderLib = {
'
lambert
'
:
{
uniforms
:
THREE
.
UniformsUtils
.
merge
(
[
THREE
.
UniformsLib
[
"
common
"
],
THREE
.
UniformsLib
[
"
lights
"
]
]
),
uniforms
:
THREE
.
UniformsUtils
.
merge
(
[
THREE
.
UniformsLib
[
"
common
"
],
THREE
.
UniformsLib
[
"
fog
"
],
THREE
.
UniformsLib
[
"
lights
"
]
]
),
fragmentShader
:
[
...
...
@@ -1141,7 +1156,9 @@ THREE.ShaderLib = {
uniforms
:
THREE
.
UniformsUtils
.
merge
(
[
THREE
.
UniformsLib
[
"
common
"
],
THREE
.
UniformsLib
[
"
fog
"
],
THREE
.
UniformsLib
[
"
lights
"
],
{
"
ambient
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0x050505
)
},
"
specular
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0x111111
)
},
...
...
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/export_threejs.py
浏览文件 @
f1e4f59a
...
...
@@ -761,6 +761,7 @@ def extract_materials(mesh, scene, option_colors, option_copy_textures, filepath
handle_texture
(
'diffuse'
,
textures
,
material
,
filepath
,
option_copy_textures
)
handle_texture
(
'light'
,
textures
,
material
,
filepath
,
option_copy_textures
)
handle_texture
(
'normal'
,
textures
,
material
,
filepath
,
option_copy_textures
)
handle_texture
(
'specular'
,
textures
,
material
,
filepath
,
option_copy_textures
)
material
[
"vertexColors"
]
=
m
.
THREE_useVertexColors
and
option_colors
...
...
@@ -771,7 +772,10 @@ def extract_materials(mesh, scene, option_colors, option_copy_textures, filepath
#else:
# material['shading'] = "Lambert"
material
[
'shading'
]
=
m
.
THREE_materialType
if
textures
[
'normal'
]:
material
[
'shading'
]
=
"Phong"
else
:
material
[
'shading'
]
=
m
.
THREE_materialType
return
materials
...
...
@@ -1324,6 +1328,7 @@ def extract_material_data(m, option_colors):
material
[
'mapDiffuse'
]
=
""
material
[
'mapLight'
]
=
""
material
[
'mapSpecular'
]
=
""
material
[
'mapNormal'
]
=
""
material
[
'mapNormalFactor'
]
=
1.0
...
...
@@ -1335,6 +1340,9 @@ def extract_material_data(m, option_colors):
if
textures
[
'light'
]:
material
[
'mapLight'
]
=
textures
[
'light'
][
'texture'
].
image
.
name
if
textures
[
'specular'
]:
material
[
'mapSpecular'
]
=
textures
[
'specular'
][
'texture'
].
image
.
name
if
textures
[
'normal'
]:
material
[
'mapNormal'
]
=
textures
[
'normal'
][
'texture'
].
image
.
name
if
textures
[
'normal'
][
'slot'
].
use_map_normal
:
...
...
@@ -1348,7 +1356,8 @@ def guess_material_textures(material):
textures
=
{
'diffuse'
:
None
,
'light'
:
None
,
'normal'
:
None
'normal'
:
None
,
'specular'
:
None
}
# just take first textures of each, for the moment three.js materials can't handle more
...
...
@@ -1363,6 +1372,9 @@ def guess_material_textures(material):
if
texture
.
use_normal_map
:
textures
[
'normal'
]
=
{
"texture"
:
texture
,
"slot"
:
slot
}
elif
slot
.
use_map_specular
or
slot
.
use_map_hardness
:
textures
[
'specular'
]
=
{
"texture"
:
texture
,
"slot"
:
slot
}
else
:
if
not
textures
[
'diffuse'
]:
textures
[
'diffuse'
]
=
{
"texture"
:
texture
,
"slot"
:
slot
}
...
...
@@ -1370,19 +1382,30 @@ def guess_material_textures(material):
else
:
textures
[
'light'
]
=
{
"texture"
:
texture
,
"slot"
:
slot
}
if
textures
[
'diffuse'
]
and
textures
[
'normal'
]
and
textures
[
'light'
]:
if
textures
[
'diffuse'
]
and
textures
[
'normal'
]
and
textures
[
'light'
]
and
textures
[
'specular'
]
:
break
return
textures
def
generate_material_string
(
material
):
material_id
=
material
[
"name"
]
# default to Lambert
shading
=
material
.
get
(
"shading"
,
"Lambert"
)
# normal mapped materials must use Phong
# to get all required parameters for normal shader
if
material
[
'mapNormal'
]:
shading
=
"Phong"
type_map
=
{
"Lambert"
:
"MeshLambertMaterial"
,
"Phong"
:
"MeshPhongMaterial"
}
material_id
=
material
[
"name"
]
shading
=
material
.
get
(
"shading"
,
"Lambert"
)
material_type
=
type_map
.
get
(
shading
,
"MeshBasicMaterial"
)
parameters
=
'"color": %d'
%
rgb2int
(
material
[
"colorDiffuse"
])
...
...
@@ -1395,6 +1418,7 @@ def generate_material_string(material):
colorMap
=
material
[
'mapDiffuse'
]
lightMap
=
material
[
'mapLight'
]
specularMap
=
material
[
'mapSpecular'
]
normalMap
=
material
[
'mapNormal'
]
normalMapFactor
=
material
[
'mapNormalFactor'
]
...
...
@@ -1402,8 +1426,11 @@ def generate_material_string(material):
parameters
+=
', "map": %s'
%
generate_string
(
colorMap
)
if
lightMap
:
parameters
+=
', "lightMap": %s'
%
generate_string
(
lightMap
)
if
specularMap
:
parameters
+=
', "specularMap": %s'
%
generate_string
(
specularMap
)
if
normalMap
:
parameters
+=
', "normalMap": %s'
%
generate_string
(
normalMap
)
if
normalMapFactor
!=
1.0
:
parameters
+=
', "normalMapFactor": %f'
%
normalMapFactor
...
...
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/import_threejs.py
浏览文件 @
f1e4f59a
...
...
@@ -27,7 +27,7 @@ import json
import
bpy
import
mathutils
from
mathutils.geometry
import
tesselate_polygon
from
io_utils
import
load_image
,
unpack_list
,
unpack_face_list
from
bpy_extras.image_utils
import
load_image
# #####################################################
# Generators
...
...
@@ -40,43 +40,43 @@ def setColor(c, t):
def
create_texture
(
filename
,
modelpath
):
name
=
filename
texture
=
bpy
.
data
.
textures
.
new
(
name
,
type
=
'IMAGE'
)
image
=
load_image
(
filename
,
modelpath
)
has_data
=
False
if
image
:
texture
.
image
=
image
has_data
=
image
.
has_data
return
texture
def
create_materials
(
data
,
modelpath
):
materials
=
[]
materials_data
=
data
.
get
(
"materials"
,
[])
for
i
,
m
in
enumerate
(
materials_data
):
name
=
m
.
get
(
"DbgName"
,
"material_%d"
%
i
)
colorAmbient
=
m
.
get
(
"colorAmbient"
,
None
)
colorDiffuse
=
m
.
get
(
"colorDiffuse"
,
None
)
colorSpecular
=
m
.
get
(
"colorSpecular"
,
None
)
alpha
=
m
.
get
(
"transparency"
,
1.0
)
specular_hardness
=
m
.
get
(
"specularCoef"
,
0
)
mapDiffuse
=
m
.
get
(
"mapDiffuse"
,
None
)
mapLightmap
=
m
.
get
(
"mapLightmap"
,
None
)
vertexColorsType
=
m
.
get
(
"vertexColors"
,
False
)
useVertexColors
=
False
if
vertexColorsType
:
useVertexColors
=
True
material
=
bpy
.
data
.
materials
.
new
(
name
)
material
.
THREE_useVertexColors
=
useVertexColors
if
colorDiffuse
:
setColor
(
material
.
diffuse_color
,
colorDiffuse
)
material
.
diffuse_intensity
=
1.0
...
...
@@ -84,14 +84,14 @@ def create_materials(data, modelpath):
if
colorSpecular
:
setColor
(
material
.
specular_color
,
colorSpecular
)
material
.
specular_intensity
=
1.0
if
alpha
<
1.0
:
material
.
alpha
=
alpha
material
.
use_transparency
=
True
if
specular_hardness
:
material
.
specular_hardness
=
specular_hardness
if
mapDiffuse
:
texture
=
create_texture
(
mapDiffuse
,
modelpath
)
mtex
=
material
.
texture_slots
.
add
()
...
...
@@ -99,13 +99,13 @@ def create_materials(data, modelpath):
mtex
.
texture_coords
=
'UV'
mtex
.
use
=
True
mtex
.
use_map_color_diffuse
=
True
material
.
active_texture
=
texture
materials
.
append
(
material
)
return
materials
def
create_mesh_object
(
name
,
vertices
,
materials
,
face_data
,
flipYZ
,
recalculate_normals
):
faces
=
face_data
[
"faces"
]
...
...
@@ -114,23 +114,23 @@ def create_mesh_object(name, vertices, materials, face_data, flipYZ, recalculate
vertexUVs
=
face_data
[
"vertexUVs"
]
faceMaterials
=
face_data
[
"materials"
]
faceColors
=
face_data
[
"faceColors"
]
edges
=
[]
# Create a new mesh
me
=
bpy
.
data
.
meshes
.
new
(
name
)
me
.
from_pydata
(
vertices
,
edges
,
faces
)
# Handle normals
if
not
recalculate_normals
:
me
.
update
(
calc_edges
=
True
)
if
face_data
[
"hasVertexNormals"
]:
print
(
"setting vertex normals"
)
for
fi
in
range
(
len
(
faces
)):
if
vertexNormals
[
fi
]:
...
...
@@ -139,24 +139,24 @@ def create_mesh_object(name, vertices, materials, face_data, flipYZ, recalculate
# if me.update() is called after setting vertex normals
# setting face.use_smooth overrides these normals
# - this fixes weird shading artefacts (seems to come from sharing
# - this fixes weird shading artefacts (seems to come from sharing
# of vertices between faces, didn't find a way how to set vertex normals
# per face use of vertex as opposed to per vertex),
# per face use of vertex as opposed to per vertex),
# - probably this just overrides all custom vertex normals
# - to preserve vertex normals from the original data
# call me.update() before setting them
me
.
faces
[
fi
].
use_smooth
=
True
if
not
recalculate_normals
:
for
j
in
range
(
len
(
vertexNormals
[
fi
])):
vertexNormal
=
vertexNormals
[
fi
][
j
]
x
=
vertexNormal
[
0
]
y
=
vertexNormal
[
1
]
z
=
vertexNormal
[
2
]
if
flipYZ
:
tmp
=
y
y
=
-
z
...
...
@@ -169,45 +169,45 @@ def create_mesh_object(name, vertices, materials, face_data, flipYZ, recalculate
#z = -z
vi
=
me
.
faces
[
fi
].
vertices
[
j
]
me
.
vertices
[
vi
].
normal
.
x
=
x
me
.
vertices
[
vi
].
normal
.
y
=
y
me
.
vertices
[
vi
].
normal
.
z
=
z
if
recalculate_normals
:
me
.
update
(
calc_edges
=
True
)
# Handle colors
if
face_data
[
"hasVertexColors"
]:
print
(
"setting vertex colors"
)
me
.
vertex_colors
.
new
(
"vertex_color_layer_0"
)
for
fi
in
range
(
len
(
faces
)):
if
vertexColors
[
fi
]:
face_colors
=
me
.
vertex_colors
[
0
].
data
[
fi
]
face_colors
=
face_colors
.
color1
,
face_colors
.
color2
,
face_colors
.
color3
,
face_colors
.
color4
for
vi
in
range
(
len
(
vertexColors
[
fi
])):
r
=
vertexColors
[
fi
][
vi
][
0
]
g
=
vertexColors
[
fi
][
vi
][
1
]
b
=
vertexColors
[
fi
][
vi
][
2
]
face_colors
[
vi
].
r
=
r
face_colors
[
vi
].
g
=
g
face_colors
[
vi
].
b
=
b
elif
face_data
[
"hasFaceColors"
]:
print
(
"setting vertex colors from face colors"
)
me
.
vertex_colors
.
new
(
"vertex_color_layer_0"
)
for
fi
in
range
(
len
(
faces
)):
if
faceColors
[
fi
]:
...
...
@@ -218,19 +218,19 @@ def create_mesh_object(name, vertices, materials, face_data, flipYZ, recalculate
face_colors
=
me
.
vertex_colors
[
0
].
data
[
fi
]
face_colors
=
face_colors
.
color1
,
face_colors
.
color2
,
face_colors
.
color3
,
face_colors
.
color4
for
vi
in
range
(
len
(
faces
[
fi
])):
face_colors
[
vi
].
r
=
r
face_colors
[
vi
].
g
=
g
face_colors
[
vi
].
b
=
b
# Handle uvs
if
face_data
[
"hasVertexUVs"
]:
print
(
"setting vertex uvs"
)
for
li
,
layer
in
enumerate
(
vertexUVs
):
me
.
uv_textures
.
new
(
"uv_layer_%d"
%
li
)
...
...
@@ -238,47 +238,47 @@ def create_mesh_object(name, vertices, materials, face_data, flipYZ, recalculate
for
fi
in
range
(
len
(
faces
)):
if
layer
[
fi
]:
uv_face
=
me
.
uv_textures
[
li
].
data
[
fi
]
face_uvs
=
uv_face
.
uv1
,
uv_face
.
uv2
,
uv_face
.
uv3
,
uv_face
.
uv4
for
vi
in
range
(
len
(
layer
[
fi
])):
u
=
layer
[
fi
][
vi
][
0
]
v
=
layer
[
fi
][
vi
][
1
]
face_uvs
[
vi
].
x
=
u
face_uvs
[
vi
].
y
=
1.0
-
v
active_texture
=
materials
[
faceMaterials
[
fi
]].
active_texture
if
active_texture
:
uv_face
.
use_image
=
True
uv_face
.
image
=
active_texture
.
image
# Handle materials # 1
if
face_data
[
"hasMaterials"
]:
print
(
"setting materials (mesh)"
)
for
m
in
materials
:
me
.
materials
.
append
(
m
)
print
(
"setting materials (faces)"
)
print
(
"setting materials (faces)"
)
for
fi
in
range
(
len
(
faces
)):
if
faceMaterials
[
fi
]
>=
0
:
me
.
faces
[
fi
].
material_index
=
faceMaterials
[
fi
]
# Create a new object
ob
=
bpy
.
data
.
objects
.
new
(
name
,
me
)
ob
=
bpy
.
data
.
objects
.
new
(
name
,
me
)
ob
.
data
=
me
# link the mesh data to the object
...
...
@@ -286,14 +286,14 @@ def create_mesh_object(name, vertices, materials, face_data, flipYZ, recalculate
scene
.
objects
.
link
(
ob
)
# link the object into the scene
ob
.
location
=
scene
.
cursor_location
# position object at 3d-cursor
# #####################################################
# Faces
# #####################################################
def
extract_faces
(
data
):
result
=
{
"faces"
:
[],
"materials"
:
[],
...
...
@@ -303,14 +303,14 @@ def extract_faces(data):
"vertexNormals"
:
[],
"faceColors"
:
[],
"vertexColors"
:
[],
"hasVertexNormals"
:
False
,
"hasVertexUVs"
:
False
,
"hasVertexColors"
:
False
,
"hasFaceColors"
:
False
,
"hasMaterials"
:
False
}
faces
=
data
.
get
(
"faces"
,
[])
normals
=
data
.
get
(
"normals"
,
[])
colors
=
data
.
get
(
"colors"
,
[])
...
...
@@ -351,23 +351,23 @@ def extract_faces(data):
result
[
"hasVertexColors"
]
=
result
[
"hasVertexColors"
]
or
hasFaceVertexColor
result
[
"hasFaceColors"
]
=
result
[
"hasFaceColors"
]
or
hasFaceColor
result
[
"hasMaterials"
]
=
result
[
"hasMaterials"
]
or
hasMaterial
# vertices
if
isQuad
:
a
=
faces
[
offset
]
offset
+=
1
b
=
faces
[
offset
]
offset
+=
1
c
=
faces
[
offset
]
offset
+=
1
d
=
faces
[
offset
]
offset
+=
1
face
=
[
a
,
b
,
c
,
d
]
nVertices
=
4
...
...
@@ -376,26 +376,26 @@ def extract_faces(data):
a
=
faces
[
offset
]
offset
+=
1
b
=
faces
[
offset
]
offset
+=
1
c
=
faces
[
offset
]
offset
+=
1
face
=
[
a
,
b
,
c
]
nVertices
=
3
result
[
"faces"
].
append
(
face
)
# material
if
hasMaterial
:
materialIndex
=
faces
[
offset
]
offset
+=
1
else
:
materialIndex
=
-
1
...
...
@@ -407,9 +407,9 @@ def extract_faces(data):
for
i
in
range
(
nUvLayers
):
faceUv
=
None
if
hasFaceUv
:
uvLayer
=
data
[
"uvs"
][
i
]
uvIndex
=
faces
[
offset
]
...
...
@@ -419,7 +419,7 @@ def extract_faces(data):
v
=
uvLayer
[
uvIndex
*
2
+
1
]
faceUv
=
[
u
,
v
]
result
[
"faceUVs"
][
i
].
append
(
faceUv
)
...
...
@@ -452,18 +452,18 @@ def extract_faces(data):
z
=
normals
[
normalIndex
+
2
]
faceNormal
=
[
x
,
y
,
z
]
else
:
faceNormal
=
None
result
[
"faceNormals"
].
append
(
faceNormal
)
if
hasFaceVertexNormal
:
vertexNormals
=
[]
for
j
in
range
(
nVertices
):
normalIndex
=
faces
[
offset
]
*
3
...
...
@@ -472,14 +472,14 @@ def extract_faces(data):
x
=
normals
[
normalIndex
]
y
=
normals
[
normalIndex
+
1
]
z
=
normals
[
normalIndex
+
2
]
vertexNormals
.
append
(
[
x
,
y
,
z
]
)
else
:
vertexNormals
=
None
result
[
"vertexNormals"
].
append
(
vertexNormals
)
...
...
@@ -487,11 +487,11 @@ def extract_faces(data):
colorIndex
=
faces
[
offset
]
offset
+=
1
faceColor
=
hexToTuple
(
colors
[
colorIndex
]
)
else
:
faceColor
=
None
result
[
"faceColors"
].
append
(
faceColor
)
...
...
@@ -510,14 +510,14 @@ def extract_faces(data):
vertexColors
.
append
(
color
)
else
:
vertexColors
=
None
result
[
"vertexColors"
].
append
(
vertexColors
)
return
result
# #####################################################
# Utils
# #####################################################
...
...
@@ -527,10 +527,10 @@ def hexToTuple( hexColor ):
g
=
((
hexColor
>>
8
)
&
0xff
)
/
255.0
b
=
(
hexColor
&
0xff
)
/
255.0
return
(
r
,
g
,
b
)
def
isBitSet
(
value
,
position
):
return
value
&
(
1
<<
position
)
def
splitArray
(
data
,
chunkSize
):
result
=
[]
chunk
=
[]
...
...
@@ -546,7 +546,7 @@ def splitArray(data, chunkSize):
def
extract_json_string
(
text
):
marker_begin
=
"var model ="
marker_end
=
"postMessage"
start
=
text
.
find
(
marker_begin
)
+
len
(
marker_begin
)
end
=
text
.
find
(
marker_end
)
end
=
text
.
rfind
(
"}"
,
start
,
end
)
...
...
@@ -563,13 +563,13 @@ def get_path(filepath):
# #####################################################
def
load
(
operator
,
context
,
filepath
,
option_flip_yz
=
True
,
recalculate_normals
=
True
):
print
(
'
\n
importing %r'
%
filepath
)
time_main
=
time
.
time
()
print
(
"
\t
parsing JSON file..."
)
time_sub
=
time
.
time
()
file
=
open
(
filepath
,
'rU'
)
...
...
@@ -578,24 +578,24 @@ def load(operator, context, filepath, option_flip_yz = True, recalculate_normals
json_string
=
extract_json_string
(
rawcontent
)
data
=
json
.
loads
(
json_string
)
time_new
=
time
.
time
()
print
(
'parsing %.4f sec'
%
(
time_new
-
time_sub
))
time_sub
=
time_new
# flip YZ
vertices
=
splitArray
(
data
[
"vertices"
],
3
)
if
option_flip_yz
:
vertices
[:]
=
[(
v
[
0
],
-
v
[
2
],
v
[
1
])
for
v
in
vertices
]
vertices
[:]
=
[(
v
[
0
],
-
v
[
2
],
v
[
1
])
for
v
in
vertices
]
# extract faces
face_data
=
extract_faces
(
data
)
# deselect all
bpy
.
ops
.
object
.
select_all
(
action
=
'DESELECT'
)
...
...
@@ -606,19 +606,19 @@ def load(operator, context, filepath, option_flip_yz = True, recalculate_normals
ncolors
=
len
(
data
.
get
(
"colors"
,
[]))
/
3
nuvs
=
len
(
data
.
get
(
"uvs"
,
[]))
/
2
nmaterials
=
len
(
data
.
get
(
"materials"
,
[]))
print
(
'
\t
building geometry...
\n\t
faces:%i, vertices:%i, vertex normals: %i, vertex uvs: %i, vertex colors: %i, materials: %i ...'
%
(
print
(
'
\t
building geometry...
\n\t
faces:%i, vertices:%i, vertex normals: %i, vertex uvs: %i, vertex colors: %i, materials: %i ...'
%
(
nfaces
,
nvertices
,
nnormals
,
nuvs
,
ncolors
,
nmaterials
))
# Create materials
materials
=
create_materials
(
data
,
get_path
(
filepath
))
# Create new obj
create_mesh_object
(
get_name
(
filepath
),
vertices
,
materials
,
face_data
,
option_flip_yz
,
recalculate_normals
)
scene
=
bpy
.
context
.
scene
scene
=
bpy
.
context
.
scene
scene
.
update
()
time_new
=
time
.
time
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录