Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
a71b541c
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,体验更适合开发者的 AI 搜索 >>
提交
a71b541c
编写于
3月 20, 2011
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactored common methods out of JSONLoader into base Loader.
上级
fb953393
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
176 addition
and
165 deletion
+176
-165
src/extras/io/JSONLoader.js
src/extras/io/JSONLoader.js
+9
-165
src/extras/io/Loader.js
src/extras/io/Loader.js
+167
-0
未找到文件。
src/extras/io/JSONLoader.js
浏览文件 @
a71b541c
...
...
@@ -5,10 +5,7 @@
THREE
.
JSONLoader
=
function
(
showStatus
)
{
THREE
.
Loader
.
call
(
this
);
this
.
showStatus
=
showStatus
;
this
.
statusDomElement
=
showStatus
?
this
.
addStatusElement
()
:
null
;
THREE
.
Loader
.
call
(
this
,
showStatus
);
};
...
...
@@ -19,47 +16,6 @@ THREE.JSONLoader.prototype.supr = THREE.Loader.prototype;
THREE
.
JSONLoader
.
prototype
=
{
addStatusElement
:
function
(
)
{
var
e
=
document
.
createElement
(
"
div
"
);
e
.
style
.
fontSize
=
"
0.8em
"
;
e
.
style
.
textAlign
=
"
left
"
;
e
.
style
.
background
=
"
#b00
"
;
e
.
style
.
color
=
"
#fff
"
;
e
.
style
.
width
=
"
140px
"
;
e
.
style
.
padding
=
"
0.25em 0.25em 0.25em 0.5em
"
;
e
.
style
.
position
=
"
absolute
"
;
e
.
style
.
right
=
"
0px
"
;
e
.
style
.
top
=
"
0px
"
;
e
.
style
.
zIndex
=
1000
;
e
.
innerHTML
=
"
Loading ...
"
;
return
e
;
},
updateProgress
:
function
(
progress
)
{
var
message
=
"
Loaded
"
;
if
(
progress
.
total
)
{
message
+=
(
100
*
progress
.
loaded
/
progress
.
total
).
toFixed
(
0
)
+
"
%
"
;
}
else
{
message
+=
(
progress
.
loaded
/
1000
).
toFixed
(
2
)
+
"
KB
"
;
}
this
.
statusDomElement
.
innerHTML
=
message
;
},
// Load models generated by slim OBJ converter with ASCII option (converter_obj_three_slim.py -t ascii)
// - parameters
// - model (required)
...
...
@@ -70,7 +26,7 @@ THREE.JSONLoader.prototype = {
var
url
=
parameters
.
model
,
callback
=
parameters
.
callback
,
texture_path
=
parameters
.
texture_path
?
parameters
.
texture_path
:
THREE
.
JSON
Loader
.
prototype
.
extractUrlbase
(
url
),
texture_path
=
parameters
.
texture_path
?
parameters
.
texture_path
:
THREE
.
Loader
.
prototype
.
extractUrlbase
(
url
),
s
=
(
new
Date
).
getTime
(),
worker
=
new
Worker
(
url
);
...
...
@@ -93,7 +49,7 @@ THREE.JSONLoader.prototype = {
THREE
.
Geometry
.
call
(
this
);
THREE
.
JSON
Loader
.
prototype
.
init_materials
(
scope
,
json
.
materials
,
texture_path
);
THREE
.
Loader
.
prototype
.
init_materials
(
scope
,
json
.
materials
,
texture_path
);
parse
();
init_skin
();
...
...
@@ -110,6 +66,12 @@ THREE.JSONLoader.prototype = {
}
function
isBitSet
(
value
,
position
)
{
return
value
&
(
1
<<
position
);
};
var
i
,
j
,
type
,
offset
,
...
...
@@ -341,124 +303,6 @@ THREE.JSONLoader.prototype = {
}
},
init_materials
:
function
(
scope
,
materials
,
texture_path
)
{
scope
.
materials
=
[];
for
(
var
i
=
0
;
i
<
materials
.
length
;
++
i
)
{
scope
.
materials
[
i
]
=
[
THREE
.
JSONLoader
.
prototype
.
createMaterial
(
materials
[
i
],
texture_path
)
];
}
},
createMaterial
:
function
(
m
,
texture_path
)
{
function
is_pow2
(
n
)
{
var
l
=
Math
.
log
(
n
)
/
Math
.
LN2
;
return
Math
.
floor
(
l
)
==
l
;
}
function
nearest_pow2
(
n
)
{
var
l
=
Math
.
log
(
n
)
/
Math
.
LN2
;
return
Math
.
pow
(
2
,
Math
.
round
(
l
)
);
}
function
load_image
(
where
,
url
)
{
var
image
=
new
Image
();
image
.
onload
=
function
()
{
if
(
!
is_pow2
(
this
.
width
)
||
!
is_pow2
(
this
.
height
)
)
{
var
w
=
nearest_pow2
(
this
.
width
),
h
=
nearest_pow2
(
this
.
height
);
where
.
image
.
width
=
w
;
where
.
image
.
height
=
h
;
where
.
image
.
getContext
(
"
2d
"
).
drawImage
(
this
,
0
,
0
,
w
,
h
);
}
else
{
where
.
image
=
this
;
}
where
.
needsUpdate
=
true
;
};
image
.
src
=
url
;
}
var
material
,
mtype
,
mpars
,
texture
,
color
;
// defaults
mtype
=
"
MeshLambertMaterial
"
;
mpars
=
{
color
:
0xeeeeee
,
opacity
:
1.0
,
map
:
null
,
lightMap
:
null
,
vertexColors
:
m
.
vertexColors
};
// parameters from model file
if
(
m
.
shading
)
{
if
(
m
.
shading
==
"
Phong
"
)
mtype
=
"
MeshPhongMaterial
"
;
}
if
(
m
.
mapDiffuse
&&
texture_path
)
{
texture
=
document
.
createElement
(
'
canvas
'
);
mpars
.
map
=
new
THREE
.
Texture
(
texture
);
mpars
.
map
.
sourceFile
=
m
.
mapDiffuse
;
load_image
(
mpars
.
map
,
texture_path
+
"
/
"
+
m
.
mapDiffuse
);
}
else
if
(
m
.
colorDiffuse
)
{
color
=
(
m
.
colorDiffuse
[
0
]
*
255
<<
16
)
+
(
m
.
colorDiffuse
[
1
]
*
255
<<
8
)
+
m
.
colorDiffuse
[
2
]
*
255
;
mpars
.
color
=
color
;
mpars
.
opacity
=
m
.
transparency
;
}
else
if
(
m
.
DbgColor
)
{
mpars
.
color
=
m
.
DbgColor
;
}
if
(
m
.
mapLightmap
&&
texture_path
)
{
texture
=
document
.
createElement
(
'
canvas
'
);
mpars
.
lightMap
=
new
THREE
.
Texture
(
texture
);
mpars
.
lightMap
.
sourceFile
=
m
.
mapLightmap
;
load_image
(
mpars
.
lightMap
,
texture_path
+
"
/
"
+
m
.
mapLightmap
);
}
material
=
new
THREE
[
mtype
](
mpars
);
return
material
;
},
extractUrlbase
:
function
(
url
)
{
var
chunks
=
url
.
split
(
"
/
"
);
chunks
.
pop
();
return
chunks
.
join
(
"
/
"
);
}
};
\ No newline at end of file
src/extras/io/Loader.js
浏览文件 @
a71b541c
...
...
@@ -4,4 +4,171 @@
THREE
.
Loader
=
function
()
{
this
.
showStatus
=
showStatus
;
this
.
statusDomElement
=
showStatus
?
this
.
addStatusElement
()
:
null
;
};
THREE
.
Loader
.
prototype
=
{
addStatusElement
:
function
(
)
{
var
e
=
document
.
createElement
(
"
div
"
);
e
.
style
.
fontSize
=
"
0.8em
"
;
e
.
style
.
textAlign
=
"
left
"
;
e
.
style
.
background
=
"
#b00
"
;
e
.
style
.
color
=
"
#fff
"
;
e
.
style
.
width
=
"
140px
"
;
e
.
style
.
padding
=
"
0.25em 0.25em 0.25em 0.5em
"
;
e
.
style
.
position
=
"
absolute
"
;
e
.
style
.
right
=
"
0px
"
;
e
.
style
.
top
=
"
0px
"
;
e
.
style
.
zIndex
=
1000
;
e
.
innerHTML
=
"
Loading ...
"
;
return
e
;
},
updateProgress
:
function
(
progress
)
{
var
message
=
"
Loaded
"
;
if
(
progress
.
total
)
{
message
+=
(
100
*
progress
.
loaded
/
progress
.
total
).
toFixed
(
0
)
+
"
%
"
;
}
else
{
message
+=
(
progress
.
loaded
/
1000
).
toFixed
(
2
)
+
"
KB
"
;
}
this
.
statusDomElement
.
innerHTML
=
message
;
},
extractUrlbase
:
function
(
url
)
{
var
chunks
=
url
.
split
(
"
/
"
);
chunks
.
pop
();
return
chunks
.
join
(
"
/
"
);
},
init_materials
:
function
(
scope
,
materials
,
texture_path
)
{
scope
.
materials
=
[];
for
(
var
i
=
0
;
i
<
materials
.
length
;
++
i
)
{
scope
.
materials
[
i
]
=
[
THREE
.
Loader
.
prototype
.
createMaterial
(
materials
[
i
],
texture_path
)
];
}
},
createMaterial
:
function
(
m
,
texture_path
)
{
function
is_pow2
(
n
)
{
var
l
=
Math
.
log
(
n
)
/
Math
.
LN2
;
return
Math
.
floor
(
l
)
==
l
;
}
function
nearest_pow2
(
n
)
{
var
l
=
Math
.
log
(
n
)
/
Math
.
LN2
;
return
Math
.
pow
(
2
,
Math
.
round
(
l
)
);
}
function
load_image
(
where
,
url
)
{
var
image
=
new
Image
();
image
.
onload
=
function
()
{
if
(
!
is_pow2
(
this
.
width
)
||
!
is_pow2
(
this
.
height
)
)
{
var
w
=
nearest_pow2
(
this
.
width
),
h
=
nearest_pow2
(
this
.
height
);
where
.
image
.
width
=
w
;
where
.
image
.
height
=
h
;
where
.
image
.
getContext
(
"
2d
"
).
drawImage
(
this
,
0
,
0
,
w
,
h
);
}
else
{
where
.
image
=
this
;
}
where
.
needsUpdate
=
true
;
};
image
.
src
=
url
;
}
var
material
,
mtype
,
mpars
,
texture
,
color
;
// defaults
mtype
=
"
MeshLambertMaterial
"
;
mpars
=
{
color
:
0xeeeeee
,
opacity
:
1.0
,
map
:
null
,
lightMap
:
null
,
vertexColors
:
m
.
vertexColors
};
// parameters from model file
if
(
m
.
shading
)
{
if
(
m
.
shading
==
"
Phong
"
)
mtype
=
"
MeshPhongMaterial
"
;
}
if
(
m
.
mapDiffuse
&&
texture_path
)
{
texture
=
document
.
createElement
(
'
canvas
'
);
mpars
.
map
=
new
THREE
.
Texture
(
texture
);
mpars
.
map
.
sourceFile
=
m
.
mapDiffuse
;
load_image
(
mpars
.
map
,
texture_path
+
"
/
"
+
m
.
mapDiffuse
);
}
else
if
(
m
.
colorDiffuse
)
{
color
=
(
m
.
colorDiffuse
[
0
]
*
255
<<
16
)
+
(
m
.
colorDiffuse
[
1
]
*
255
<<
8
)
+
m
.
colorDiffuse
[
2
]
*
255
;
mpars
.
color
=
color
;
mpars
.
opacity
=
m
.
transparency
;
}
else
if
(
m
.
DbgColor
)
{
mpars
.
color
=
m
.
DbgColor
;
}
if
(
m
.
mapLightmap
&&
texture_path
)
{
texture
=
document
.
createElement
(
'
canvas
'
);
mpars
.
lightMap
=
new
THREE
.
Texture
(
texture
);
mpars
.
lightMap
.
sourceFile
=
m
.
mapLightmap
;
load_image
(
mpars
.
lightMap
,
texture_path
+
"
/
"
+
m
.
mapLightmap
);
}
material
=
new
THREE
[
mtype
](
mpars
);
return
material
;
}
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录