Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
325c9f45
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,发现更多精彩内容 >>
提交
325c9f45
编写于
3月 30, 2019
作者:
A
adrs2002
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix to LWOLoader.js : add suport LWO2 format
上级
072cf7b9
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
165 addition
and
9 deletion
+165
-9
examples/js/loaders/LWOLoader.js
examples/js/loaders/LWOLoader.js
+165
-9
未找到文件。
examples/js/loaders/LWOLoader.js
浏览文件 @
325c9f45
/**
* @author Lewy Blue https://github.com/looeee
*
* Load files in LWO3 format
* Load files in LWO3
and LWO2
format
*
* LWO3 format specification:
* http://static.lightwave3d.com/sdk/2018/html/filefmts/lwo3.html
*
* LWO2 format specification
(not tested, however the loader should be largely backwards compatible)
* LWO2 format specification
:
* http://static.lightwave3d.com/sdk/2018/html/filefmts/lwo2.html
*
*/
...
...
@@ -291,8 +291,16 @@ THREE.LWOLoader = ( function () {
for
(
var
name
in
lwoTree
.
materials
)
{
if
(
lwoTree
.
format
===
'
LWO3
'
)
{
materials
.
push
(
this
.
parseMaterial
(
lwoTree
.
materials
[
name
],
name
,
lwoTree
.
textures
)
);
}
else
if
(
lwoTree
.
format
===
'
LWO2
'
)
{
materials
.
push
(
this
.
parseMaterialLwo2
(
lwoTree
.
materials
[
name
],
name
,
lwoTree
.
textures
)
);
}
}
return
materials
;
...
...
@@ -326,6 +334,20 @@ THREE.LWOLoader = ( function () {
},
parseMaterialLwo2
(
materialData
,
name
,
textures
)
{
var
params
=
{
name
:
name
,
side
:
this
.
getSide
(
materialData
.
attributes
),
flatShading
:
this
.
getSmooth
(
materialData
.
attributes
),
};
var
attributes
=
this
.
parseAttributes
(
materialData
.
attributes
,
{}
);
params
=
Object
.
assign
(
params
,
attributes
);
return
new
THREE
[
'
MeshPhongMaterial
'
](
params
);
},
// Note: converting from left to right handed coords by switching x -> -x in vertices, and
// then switching mat FrontSide -> BackSide
// NB: this means that THREE.FrontSide and THREE.BackSide have been switched!
...
...
@@ -744,7 +766,17 @@ THREE.LWOLoader = ( function () {
);
}
else
if
(
dim
>
4
)
console
.
warn
(
'
LWOLoader: polygons with greater than 4 sides are not supported
'
);
}
else
if
(
dim
>
4
)
{
for
(
var
k
=
1
;
k
<
dim
-
1
;
k
++
)
{
remappedIndices
.
push
(
indices
[
i
],
indices
[
i
+
k
],
indices
[
i
+
k
+
1
]
);
}
console
.
warn
(
'
LWOLoader: polygons with greater than 4 sides are not supported
'
);
}
i
+=
dim
;
...
...
@@ -850,7 +882,16 @@ THREE.LWOLoader = ( function () {
remappedIndices
.
push
(
indices
[
i
*
2
],
indices
[
i
*
2
+
1
],
indices
[
i
*
2
],
indices
[
i
*
2
+
1
]
);
}
// ignore > 4 for now
}
else
{
// ignore > 4 for now
for
(
var
k
=
0
;
k
<
dim
-
2
;
k
++
)
{
remappedIndices
.
push
(
indices
[
i
*
2
],
indices
[
i
*
2
+
1
]
);
}
}
}
);
...
...
@@ -1001,6 +1042,13 @@ THREE.LWOLoader = ( function () {
var
blockID
=
this
.
reader
.
getIDTag
();
var
length
=
this
.
reader
.
getUint32
();
// size of data in bytes
if
(
this
.
tree
.
format
===
'
LWO2
'
&&
length
>
this
.
reader
.
dv
.
byteLength
-
this
.
reader
.
offset
)
{
this
.
reader
.
offset
-=
4
;
length
=
this
.
reader
.
getUint16
();
}
// Data types may be found in either LWO2 OR LWO3 spec
switch
(
blockID
)
{
...
...
@@ -1080,7 +1128,6 @@ THREE.LWOLoader = ( function () {
case
'
NPLA
'
:
case
'
VERS
'
:
case
'
ENUM
'
:
case
'
FLAG
'
:
case
'
TAG
'
:
// Car Material CHUNKS
...
...
@@ -1096,8 +1143,26 @@ THREE.LWOLoader = ( function () {
this
.
reader
.
skip
(
length
);
break
;
case
'
FLAG
'
:
if
(
this
.
tree
.
format
===
'
LWO2
'
)
{
this
.
reader
.
skip
(
4
);
// not suported
}
else
{
this
.
reader
.
skip
(
length
);
}
break
;
// Skipped LWO2 chunks
case
'
DIFF
'
:
// diffuse level, may be necessary to modulate COLR with this
if
(
this
.
tree
.
format
===
'
LWO2
'
)
{
this
.
currentSurface
.
diffusePower
=
this
.
reader
.
getFloat32
();
this
.
reader
.
skip
(
2
);
}
break
;
case
'
TRNL
'
:
case
'
REFL
'
:
case
'
GLOS
'
:
...
...
@@ -1118,7 +1183,20 @@ THREE.LWOLoader = ( function () {
case
'
ENAB
'
:
this
.
reader
.
skip
(
length
);
break
;
case
'
SURF
'
:
if
(
this
.
tree
.
format
===
'
LWO2
'
)
{
this
.
parseSurfaceLwo2
(
length
);
}
break
;
case
'
CLIP
'
:
if
(
this
.
tree
.
format
===
'
LWO2
'
)
{
this
.
parseClipLwo2
(
length
);
}
break
;
// Texture node chunks (not in spec)
case
'
IPIX
'
:
// usePixelBlending
case
'
IMIP
'
:
// useMipMaps
...
...
@@ -1276,7 +1354,8 @@ THREE.LWOLoader = ( function () {
// LWO2: Basic Surface Parameters
case
'
COLR
'
:
this
.
currentSurface
.
attributes
.
color
=
this
.
reader
.
getFloat32Array
(
3
);
this
.
currentSurface
.
attributes
.
Color
=
{};
this
.
currentSurface
.
attributes
.
Color
.
value
=
this
.
reader
.
getFloat32Array
(
3
);
this
.
reader
.
skip
(
2
);
// VX: envelope
break
;
...
...
@@ -1323,7 +1402,15 @@ THREE.LWOLoader = ( function () {
break
;
case
'
IMAP
'
:
if
(
this
.
tree
.
format
===
'
LWO2
'
)
{
this
.
reader
.
skip
(
2
);
}
else
{
this
.
currentSurface
.
attributes
.
imageMapIndex
=
this
.
reader
.
getUint32
();
}
break
;
case
'
IUVI
'
:
// uv channel name
...
...
@@ -1337,6 +1424,11 @@ THREE.LWOLoader = ( function () {
this
.
currentNode
.
heightWrappingMode
=
this
.
reader
.
getUint32
();
break
;
// LWO2 USE
case
'
BLOK
'
:
// skip
break
;
default
:
this
.
parseUnknownCHUNK
(
blockID
,
length
);
...
...
@@ -1420,6 +1512,10 @@ THREE.LWOLoader = ( function () {
this
.
parseTextureNodeAttribute
(
type
);
break
;
case
'
LWO2
'
:
this
.
tree
.
format
=
type
;
break
;
case
'
LWO3
'
:
this
.
tree
.
format
=
type
;
break
;
...
...
@@ -1431,7 +1527,11 @@ THREE.LWOLoader = ( function () {
// CLIP FORM AND SUB FORMS
case
'
CLIP
'
:
this
.
parseClip
(
length
);
if
(
this
.
tree
.
format
===
'
LWO2
'
)
{
this
.
parseForm
(
length
);
}
break
;
case
'
STIL
'
:
...
...
@@ -1574,6 +1674,29 @@ THREE.LWOLoader = ( function () {
var
name
=
this
.
reader
.
getString
();
var
surface
=
{
attributes
:
{},
// LWO2 style non-node attributes will go here
connections
:
{},
name
:
name
,
inputName
:
name
,
nodes
:
{},
source
:
this
.
reader
.
getString
(),
};
this
.
tree
.
materials
[
name
]
=
surface
;
this
.
currentSurface
=
surface
;
this
.
parentForm
=
this
.
tree
.
materials
;
this
.
currentForm
=
surface
;
this
.
currentFormEnd
=
this
.
reader
.
offset
+
length
;
},
parseSurfaceLwo2
(
length
)
{
var
firstOffset
=
this
.
reader
.
offset
;
var
name
=
this
.
reader
.
getString
();
var
surface
=
{
attributes
:
{},
// LWO2 style non-node attributes will go here
connections
:
{},
...
...
@@ -1771,6 +1894,39 @@ THREE.LWOLoader = ( function () {
},
parseClipLwo2
(
length
)
{
var
texture
=
{
index
:
this
.
reader
.
getUint32
(),
fileName
:
""
};
var
readed
=
4
;
// seach STIL block
while
(
true
)
{
var
tag
=
this
.
reader
.
getIDTag
();
var
n_length
=
this
.
reader
.
getUint16
();
if
(
tag
===
'
STIL
'
)
{
texture
.
fileName
=
this
.
reader
.
getString
();
break
;
}
readed
+=
4
+
n_length
;
if
(
n_length
>=
length
)
{
break
;
}
}
this
.
tree
.
textures
.
push
(
texture
);
this
.
currentForm
=
texture
;
},
parseImage
()
{
this
.
reader
.
skip
(
8
);
// unknown
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录