Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
e4f14ab4
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,发现更多精彩内容 >>
提交
e4f14ab4
编写于
11月 05, 2013
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev-blender-lights' of
https://github.com/fscz/three.js
into dev
上级
364cc7ae
58d1b5d2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
174 addition
and
79 deletion
+174
-79
src/loaders/SceneLoader.js
src/loaders/SceneLoader.js
+55
-44
utils/exporters/blender/2.66/scripts/addons/io_mesh_threejs/export_threejs.py
...der/2.66/scripts/addons/io_mesh_threejs/export_threejs.py
+119
-35
未找到文件。
src/loaders/SceneLoader.js
浏览文件 @
e4f14ab4
...
...
@@ -361,50 +361,61 @@ THREE.SceneLoader.prototype = {
// lights
}
else
if
(
objJSON
.
type
===
"
DirectionalLight
"
||
objJSON
.
type
===
"
PointLight
"
||
objJSON
.
type
===
"
AmbientLight
"
)
{
hex
=
(
objJSON
.
color
!==
undefined
)
?
objJSON
.
color
:
0xffffff
;
intensity
=
(
objJSON
.
intensity
!==
undefined
)
?
objJSON
.
intensity
:
1
;
if
(
objJSON
.
type
===
"
DirectionalLight
"
)
{
pos
=
objJSON
.
direction
;
light
=
new
THREE
.
DirectionalLight
(
hex
,
intensity
);
light
.
position
.
fromArray
(
pos
);
if
(
objJSON
.
target
)
{
target_array
.
push
(
{
"
object
"
:
light
,
"
targetName
"
:
objJSON
.
target
}
);
// kill existing default target
// otherwise it gets added to scene when parent gets added
light
.
target
=
null
;
}
}
else
if
(
objJSON
.
type
===
"
PointLight
"
)
{
pos
=
objJSON
.
position
;
dst
=
objJSON
.
distance
;
light
=
new
THREE
.
PointLight
(
hex
,
intensity
,
dst
);
light
.
position
.
fromArray
(
pos
);
}
else
if
(
objJSON
.
type
===
"
AmbientLight
"
)
{
light
=
new
THREE
.
AmbientLight
(
hex
);
}
parent
.
add
(
light
);
light
.
name
=
objID
;
result
.
lights
[
objID
]
=
light
;
result
.
objects
[
objID
]
=
light
;
// cameras
// lights
}
else
if
(
objJSON
.
type
===
"
PointLight
"
||
objJSON
.
type
===
"
AmbientLight
"
||
objJSON
.
type
===
"
SpotLight
"
||
objJSON
.
type
===
"
HemisphereLight
"
||
objJSON
.
type
===
"
AreaLight
"
)
{
function
rotate
(
x
,
y
,
z
,
vector3
)
{
var
target
=
new
THREE
.
Matrix4
(
vector3
[
0
],
0
,
0
,
0
,
vector3
[
1
],
0
,
0
,
0
,
vector3
[
2
],
0
,
0
,
0
,
0
,
0
,
0
,
0
);
var
rotateX
=
new
THREE
.
Matrix4
(),
rotateY
=
new
THREE
.
Matrix4
(),
rotateZ
=
new
THREE
.
Matrix4
();
rotateX
.
makeRotationX
(
x
);
rotateY
.
makeRotationY
(
y
);
rotateZ
.
makeRotationZ
(
z
);
var
rotateM
=
new
THREE
.
Matrix4
();
rotateM
.
multiplyMatrices
(
rotateX
,
rotateY
,
rotateZ
);
target
.
multiplyMatrices
(
rotateM
,
target
);
return
target
;
}
var
intensity
=
objJSON
.
intensity
;
var
color
=
objJSON
.
color
;
var
distance
=
objJSON
.
distance
;
var
position
=
objJSON
.
position
;
var
rotation
=
objJSON
.
rotation
;
if
(
objJSON
.
type
===
"
PointLight
"
)
{
light
=
new
THREE
.
PointLight
(
color
,
intensity
,
distance
);
light
.
position
.
fromArray
(
position
);
}
else
if
(
objJSON
.
type
===
"
SpotLight
"
)
{
light
=
new
THREE
.
SpotLight
(
color
,
intensity
,
distance
,
1
);
light
.
angle
=
objJSON
.
angle
;
light
.
position
.
fromArray
(
position
);
var
target
=
rotate
(
rotation
[
0
],
rotation
[
1
],
rotation
[
2
],
[
position
[
0
],
position
[
1
]
-
distance
,
position
[
2
]]);
light
.
target
.
position
=
new
THREE
.
Vector3
(
target
.
elements
[
0
],
target
.
elements
[
1
],
target
.
elements
[
2
]);
}
else
if
(
objJSON
.
type
===
"
AmbientLight
"
)
{
light
=
new
THREE
.
AmbientLight
(
color
);
}
else
if
(
objJSON
.
type
===
"
HemisphereLight
"
)
{
light
=
new
THREE
.
DirectionalLight
(
color
,
intensity
,
distance
);
var
target
=
rotate
(
rotation
[
0
],
rotation
[
1
],
rotation
[
2
],
[
position
[
0
],
position
[
1
]
-
distance
,
position
[
2
]]);
light
.
target
.
position
=
new
THREE
.
Vector3
(
target
.
elements
[
0
],
target
.
elements
[
1
],
target
.
elements
[
2
]);
}
else
if
(
objJSON
.
type
===
"
AreaLight
"
)
{
light
=
new
THREE
.
AreaLight
(
color
,
intensity
);
light
.
position
.
set
(
position
[
0
],
position
[
1
],
position
[
2
]);
light
.
width
=
objJSON
.
size
;
light
.
height
=
objJSON
.
size_y
;
}
parent
.
add
(
light
);
light
.
name
=
objID
;
result
.
lights
[
objID
]
=
light
;
result
.
objects
[
objID
]
=
light
;
// cameras
}
else
if
(
objJSON
.
type
===
"
PerspectiveCamera
"
||
objJSON
.
type
===
"
OrthographicCamera
"
)
{
...
...
utils/exporters/blender/2.66/scripts/addons/io_mesh_threejs/export_threejs.py
浏览文件 @
e4f14ab4
...
...
@@ -196,21 +196,62 @@ TEMPLATE_CAMERA_ORTHO = """\
"target" : %(target)s
}"""
TEMPLATE_LIGHT_DIRECTIONAL
=
"""
\
%(light_id)s : {
"type" : "DirectionalLight",
"direction" : %(direction)s,
"color" : %(color)d,
"intensity" : %(intensity).2f
}"""
TEMPLATE_LIGHT_POINT
=
"""
\
%(light_id)s : {
"type" : "PointLight",
"position" : %(position)s,
"color" : %(color)d,
"intensity" : %(intensity).3f
}"""
%(light_id)s : {
"type" : "PointLight",
"position" : %(position)s,
"rotation" : %(rotation)s,
"color" : %(color)d,
"distance" : %(distance).3f,
"intensity" : %(intensity).3f
}"""
TEMPLATE_LIGHT_SUN
=
"""
\
%(light_id)s : {
"type" : "AmbientLight",
"position" : %(position)s,
"rotation" : %(rotation)s,
"color" : %(color)d,
"distance" : %(distance).3f,
"intensity" : %(intensity).3f
}"""
TEMPLATE_LIGHT_SPOT
=
"""
\
%(light_id)s : {
"type" : "SpotLight",
"position" : %(position)s,
"rotation" : %(rotation)s,
"color" : %(color)d,
"distance" : %(distance).3f,
"intensity" : %(intensity).3f,
"use_shadow" : %(use_shadow)d,
"angle" : %(angle).3f
}"""
TEMPLATE_LIGHT_HEMI
=
"""
\
%(light_id)s : {
"type" : "HemisphereLight",
"position" : %(position)s,
"rotation" : %(rotation)s,
"color" : %(color)d,
"distance" : %(distance).3f,
"intensity" : %(intensity).3f
}"""
TEMPLATE_LIGHT_AREA
=
"""
\
%(light_id)s : {
"type" : "AreaLight",
"position" : %(position)s,
"rotation" : %(rotation)s,
"color" : %(color)d,
"distance" : %(distance).3f,
"intensity" : %(intensity).3f,
"gamma" : %(gamma).3f,
"shape" : "%(shape)s",
"size" : %(size).3f,
"size_y" : %(size_y).3f
}"""
TEMPLATE_VEC4
=
'[ %g, %g, %g, %g ]'
TEMPLATE_VEC3
=
'[ %g, %g, %g ]'
...
...
@@ -1241,7 +1282,7 @@ def generate_materials_string(mesh, scene, option_colors, draw_type, option_copy
def
handle_texture
(
id
,
textures
,
material
,
filepath
,
option_copy_textures
):
if
textures
[
id
]:
if
textures
[
id
]
and
textures
[
id
][
'texture'
].
users
>
0
and
len
(
textures
[
id
][
'texture'
].
users_material
)
>
0
:
texName
=
'map%s'
%
id
.
capitalize
()
repeatName
=
'map%sRepeat'
%
id
.
capitalize
()
wrapName
=
'map%sWrap'
%
id
.
capitalize
()
...
...
@@ -1613,7 +1654,9 @@ def generate_quat(quat):
def
generate_vec4
(
vec
):
return
TEMPLATE_VEC4
%
(
vec
[
0
],
vec
[
1
],
vec
[
2
],
vec
[
3
])
def
generate_vec3
(
vec
):
def
generate_vec3
(
vec
,
flipyz
=
False
):
if
flipyz
:
return
TEMPLATE_VEC3
%
(
vec
[
0
],
vec
[
2
],
vec
[
1
])
return
TEMPLATE_VEC3
%
(
vec
[
0
],
vec
[
1
],
vec
[
2
])
def
generate_vec2
(
vec
):
...
...
@@ -1810,7 +1853,7 @@ def generate_textures_scene(data):
for
texture
in
bpy
.
data
.
textures
:
if
texture
.
type
==
'IMAGE'
and
texture
.
image
:
if
texture
.
type
==
'IMAGE'
and
texture
.
image
and
texture
.
users
>
0
and
len
(
texture
.
users_material
)
>
0
:
img
=
texture
.
image
...
...
@@ -1998,6 +2041,7 @@ def generate_material_string(material):
material_type
=
type_map
.
get
(
shading
,
"MeshBasicMaterial"
)
parameters
=
'"color": %d'
%
rgb2int
(
material
[
"colorDiffuse"
])
parameters
+=
', "ambient": %d'
%
rgb2int
(
material
[
"colorDiffuse"
])
parameters
+=
', "opacity": %.2g'
%
material
[
"transparency"
]
if
shading
==
"Phong"
:
...
...
@@ -2147,33 +2191,73 @@ def generate_lights(data):
chunks
=
[]
if
data
[
"use_lights"
]:
lamps
=
data
[
"objects"
]
lamps
=
[
ob
for
ob
in
lamps
if
(
ob
.
type
==
'LAMP'
)]
lights
=
data
.
get
(
"lights"
,
[])
if
not
lights
:
lights
.
append
(
DEFAULTS
[
"light"
])
for
light
in
lights
:
if
light
[
"type"
]
==
"DirectionalLight"
:
light_string
=
TEMPLATE_LIGHT_DIRECTIONAL
%
{
"light_id"
:
generate_string
(
light
[
"name"
]),
"direction"
:
generate_vec3
(
light
[
"direction"
]),
"color"
:
rgb2int
(
light
[
"color"
]),
"intensity"
:
light
[
"intensity"
]
}
for
lamp
in
lamps
:
light_string
=
""
concrete_lamp
=
lamp
.
data
elif
light
[
"type"
]
==
"PointLight
"
:
if
concrete_lamp
.
type
==
"POINT
"
:
light_string
=
TEMPLATE_LIGHT_POINT
%
{
"light_id"
:
generate_string
(
light
[
"name"
]),
"position"
:
generate_vec3
(
light
[
"position"
]),
"color"
:
rgb2int
(
light
[
"color"
]),
"intensity"
:
light
[
"intensity"
]
"light_id"
:
generate_string
(
concrete_lamp
.
name
),
"position"
:
generate_vec3
(
lamp
.
location
,
data
[
"flipyz"
]),
"rotation"
:
generate_vec3
(
lamp
.
rotation_euler
,
data
[
"flipyz"
]),
"color"
:
rgb2int
(
concrete_lamp
.
color
),
"distance"
:
concrete_lamp
.
distance
,
"intensity"
:
concrete_lamp
.
energy
}
elif
concrete_lamp
.
type
==
"SUN"
:
light_string
=
TEMPLATE_LIGHT_SUN
%
{
"light_id"
:
generate_string
(
concrete_lamp
.
name
),
"position"
:
generate_vec3
(
lamp
.
location
,
data
[
"flipyz"
]),
"rotation"
:
generate_vec3
(
lamp
.
rotation_euler
,
data
[
"flipyz"
]),
"color"
:
rgb2int
(
concrete_lamp
.
color
),
"distance"
:
concrete_lamp
.
distance
,
"intensity"
:
concrete_lamp
.
energy
}
elif
concrete_lamp
.
type
==
"SPOT"
:
light_string
=
TEMPLATE_LIGHT_SPOT
%
{
"light_id"
:
generate_string
(
concrete_lamp
.
name
),
"position"
:
generate_vec3
(
lamp
.
location
,
data
[
"flipyz"
]),
"rotation"
:
generate_vec3
(
lamp
.
rotation_euler
,
data
[
"flipyz"
]),
"color"
:
rgb2int
(
concrete_lamp
.
color
),
"distance"
:
concrete_lamp
.
distance
,
"intensity"
:
concrete_lamp
.
energy
,
"use_shadow"
:
concrete_lamp
.
use_shadow
,
"angle"
:
concrete_lamp
.
spot_size
}
elif
concrete_lamp
.
type
==
"HEMI"
:
light_string
=
TEMPLATE_LIGHT_HEMI
%
{
"light_id"
:
generate_string
(
concrete_lamp
.
name
),
"position"
:
generate_vec3
(
lamp
.
location
,
data
[
"flipyz"
]),
"rotation"
:
generate_vec3
(
lamp
.
rotation_euler
,
data
[
"flipyz"
]),
"color"
:
rgb2int
(
concrete_lamp
.
color
),
"distance"
:
concrete_lamp
.
distance
,
"intensity"
:
concrete_lamp
.
energy
}
elif
concrete_lamp
.
type
==
"AREA"
:
light_string
=
TEMPLATE_LIGHT_AREA
%
{
"light_id"
:
generate_string
(
concrete_lamp
.
name
),
"position"
:
generate_vec3
(
lamp
.
location
,
data
[
"flipyz"
]),
"rotation"
:
generate_vec3
(
lamp
.
rotation_euler
,
data
[
"flipyz"
]),
"color"
:
rgb2int
(
concrete_lamp
.
color
),
"distance"
:
concrete_lamp
.
distance
,
"intensity"
:
concrete_lamp
.
energy
,
"gamma"
:
concrete_lamp
.
gamma
,
"shape"
:
concrete_lamp
.
shape
,
"size"
:
concrete_lamp
.
size
,
"size_y"
:
concrete_lamp
.
size_y
}
chunks
.
append
(
light_string
)
if
not
lamps
:
lamps
.
append
(
DEFAULTS
[
"light"
])
return
",
\n\n
"
.
join
(
chunks
),
len
(
chunks
)
# #####################################################
# Scene exporter - embedded meshes
# #####################################################
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录