Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenFlipper-Free
Plugin-FileOBJ
Commits
b2797cdd
Commit
b2797cdd
authored
Dec 08, 2017
by
Jan Möbius
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'featurePBMaterials' into 'master'
improved material support See merge request
!2
parents
7ceefca0
899eee34
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
186 additions
and
28 deletions
+186
-28
FileOBJ.cc
FileOBJ.cc
+50
-21
Material.hh
Material.hh
+64
-6
OBJImporter.cc
OBJImporter.cc
+72
-1
No files found.
FileOBJ.cc
View file @
b2797cdd
...
...
@@ -171,6 +171,7 @@ bool FileOBJPlugin::readMaterial(QString _filename, OBJImporter& _importer)
f1
=
0
;
f2
=
0
;
f3
=
0
;
static
int
i
;
static
bool
insideDefintion
;
insideDefintion
=
false
;
static
int
textureId
;
...
...
@@ -241,7 +242,7 @@ bool FileOBJPlugin::readMaterial(QString _filename, OBJImporter& _importer)
f2
=
getFloat
(
stream
);
f3
=
getFloat
(
stream
);
if
(
stream
.
status
()
!
=
QTextStream
::
Ok
)
if
(
stream
.
status
()
=
=
QTextStream
::
Ok
)
mat
.
set_Ka
(
f1
,
f2
,
f3
);
}
...
...
@@ -251,20 +252,62 @@ bool FileOBJPlugin::readMaterial(QString _filename, OBJImporter& _importer)
f2
=
getFloat
(
stream
);
f3
=
getFloat
(
stream
);
if
(
stream
.
status
()
!
=
QTextStream
::
Ok
)
if
(
stream
.
status
()
=
=
QTextStream
::
Ok
)
mat
.
set_Ks
(
f1
,
f2
,
f3
);
}
#if 0
else if (keyWrd == QLatin1String("
illum") // diffuse/specular shading model
else
if
(
keyWrd
==
QLatin1String
(
"
Ke"
))
// emission color
{
; // just skip this
f1
=
getFloat
(
stream
);
f2
=
getFloat
(
stream
);
f3
=
getFloat
(
stream
);
if
(
stream
.
status
()
==
QTextStream
::
Ok
)
mat
.
set_Ke
(
f1
,
f2
,
f3
);
}
else if (keyWrd == QLatin1String("Ns") // Shininess [0..200]
else
if
(
keyWrd
==
QLatin1String
(
"illum"
))
// diffuse/specular shading model
{
; // just skip this
stream
>>
i
;
if
(
stream
.
status
()
==
QTextStream
::
Ok
)
mat
.
set_illum
(
i
);
}
else
if
(
keyWrd
==
QLatin1String
(
"Ns"
))
// Shininess;
{
f1
=
getFloat
(
stream
);
if
(
stream
.
status
()
==
QTextStream
::
Ok
)
mat
.
set_Ns
(
f1
);
}
else
if
(
keyWrd
==
QLatin1String
(
"Ni"
))
// Refractive index
{
f1
=
getFloat
(
stream
);
if
(
stream
.
status
()
==
QTextStream
::
Ok
)
mat
.
set_Ni
(
f1
);
}
else
if
(
keyWrd
==
QLatin1String
(
"Tr"
))
// transparency value
{
f1
=
getFloat
(
stream
);
if
(
stream
.
status
()
==
QTextStream
::
Ok
)
mat
.
set_Tr
(
f1
);
}
else
if
(
keyWrd
==
QLatin1String
(
"d"
))
// material dissolve. The result does not depend upon the thickness of the object, no real transparency
// ignored when Tr exists
{
f1
=
getFloat
(
stream
);
if
(
stream
.
status
()
==
QTextStream
::
Ok
&&
!
mat
.
has_Tr
())
mat
.
set_Tr
(
f1
);
}
#if 0
else if (keyWrd == QLatin1String("map_") // map images
{
// map_Ks, specular map
...
...
@@ -282,20 +325,6 @@ bool FileOBJPlugin::readMaterial(QString _filename, OBJImporter& _importer)
if
(
!
textureName
.
isEmpty
()
)
mat
.
set_map_Kd
(
textureName
.
toStdString
(),
textureId
++
);
}
else
if
(
keyWrd
==
QLatin1String
(
"Tr"
))
// transparency value
{
f1
=
getFloat
(
stream
);
if
(
stream
.
status
()
==
QTextStream
::
Ok
)
mat
.
set_Tr
(
f1
);
}
else
if
(
keyWrd
==
QLatin1String
(
"d"
))
// transparency value
{
f1
=
getFloat
(
stream
);
if
(
stream
.
status
()
==
QTextStream
::
Ok
)
mat
.
set_Tr
(
f1
);
}
if
(
matStream
.
status
()
==
QTextStream
::
Ok
&&
insideDefintion
&&
mat
.
is_valid
()
&&
!
matName
.
isEmpty
())
_importer
.
materials
()[
matName
.
toStdString
()]
=
mat
;
...
...
Material.hh
View file @
b2797cdd
...
...
@@ -70,7 +70,11 @@ class Material
Kd_is_set_
(
false
),
Ka_is_set_
(
false
),
Ks_is_set_
(
false
),
Tr_
(
0.0
),
Ke_is_set_
(
false
),
Ni_is_set_
(
false
),
Ns_is_set_
(
false
),
illum_is_set_
(
false
),
Tr_
(
1.0
),
// fully opaque
Tr_is_set_
(
false
),
map_Kd_
(
""
),
index_Kd_
(
0
),
...
...
@@ -85,6 +89,10 @@ class Material
Kd_is_set_
=
false
;
Ka_is_set_
=
false
;
Ks_is_set_
=
false
;
Ke_is_set_
=
false
;
Ni_is_set_
=
false
;
Ns_is_set_
=
false
;
illum_is_set_
=
false
;
Tr_
=
0.0
;
Tr_is_set_
=
false
;
map_Kd_
=
""
;
...
...
@@ -103,6 +111,18 @@ class Material
/// Does material have a specular color?
bool
has_Ks
(
void
)
{
return
Ks_is_set_
;
}
/// Is material emissive?
bool
has_Ke
(
void
)
{
return
Ke_is_set_
;
}
/// Does material have an index of refraction?
bool
has_Ni
(
void
)
{
return
Ni_is_set_
;
}
/// Does material have shininess?
bool
has_Ns
(
void
)
{
return
Ns_is_set_
;
}
/// Does material have illumination model?
bool
has_illum
(
void
)
{
return
illum_is_set_
;
}
/// Does material have transparency?
bool
has_Tr
(
void
)
{
return
Tr_is_set_
;
}
...
...
@@ -115,6 +135,9 @@ class Material
if
(
_mat
.
Kd_
!=
Kd_
||
_mat
.
Ka_
!=
Ka_
||
_mat
.
Ks_
!=
Ks_
||
_mat
.
Ke_
!=
Ke_
||
_mat
.
Ni_
!=
Ni_
||
_mat
.
Ns_
!=
Ns_
||
_mat
.
Tr_
!=
Tr_
||
_mat
.
map_Kd_
!=
map_Kd_
||
_mat
.
index_Kd_
!=
index_Kd_
)
...
...
@@ -141,13 +164,29 @@ class Material
void
set_Ks
(
float
r
,
float
g
,
float
b
)
{
Ks_
=
OpenMesh
::
Vec3f
(
r
,
g
,
b
);
Ks_is_set_
=
true
;
}
/// Set emission
void
set_Ke
(
float
r
,
float
g
,
float
b
)
{
Ke_
=
OpenMesh
::
Vec3f
(
r
,
g
,
b
);
Ke_is_set_
=
true
;
}
/// Set index of refraction
void
set_Ni
(
float
t
)
{
Ni_
=
t
;
Ni_is_set_
=
true
;
}
/// Set shininess
void
set_Ns
(
float
t
)
{
Ns_
=
t
;
Ns_is_set_
=
true
;
}
/// Set illumination model
void
set_illum
(
int
t
)
{
illum_
=
t
;
illum_is_set_
=
true
;
}
/// Set transparency value (between 0 and 1)
void
set_Tr
(
float
t
)
{
Tr_
=
t
;
Tr_is_set_
=
true
;
}
/// Set texture file and index
void
set_map_Kd
(
std
::
string
_name
,
int
_index_Kd
)
{
map_Kd_
=
_name
,
index_Kd_
=
_index_Kd
;
map_Kd_is_set_
=
true
;
}
;
{
map_Kd_
=
_name
,
index_Kd_
=
_index_Kd
;
map_Kd_is_set_
=
true
;
}
/// Get diffuse color
const
OpenMesh
::
Vec3f
&
Kd
(
void
)
const
{
return
Kd_
;
}
...
...
@@ -157,6 +196,21 @@ class Material
/// Get specular color
const
OpenMesh
::
Vec3f
&
Ks
(
void
)
const
{
return
Ks_
;
}
/// Get emission
const
OpenMesh
::
Vec3f
&
Ke
(
void
)
const
{
return
Ke_
;
}
/// Get index of refraction
float
Ni
(
void
)
const
{
return
Ni_
;
}
/// Get shininess
float
Ns
(
void
)
const
{
return
Ns_
;
}
/// Get illumination model
int
illum
(
void
)
const
{
return
illum_
;
}
/// Is the material refractive (translucent)
bool
isRefractive
(
void
)
const
{
return
(
illum_
==
4
||
illum_
==
6
||
illum_
==
7
||
illum_
==
9
);}
/// Get transparency value
float
Tr
(
void
)
const
{
return
Tr_
;
}
...
...
@@ -170,10 +224,14 @@ class Material
private:
unsigned
int
localNum_
;
OpenMesh
::
Vec3f
Kd_
;
bool
Kd_is_set_
;
// diffuse
OpenMesh
::
Vec3f
Ka_
;
bool
Ka_is_set_
;
// ambient
OpenMesh
::
Vec3f
Ks_
;
bool
Ks_is_set_
;
// specular
float
Tr_
;
bool
Tr_is_set_
;
// transperency
OpenMesh
::
Vec3f
Kd_
;
bool
Kd_is_set_
;
// diffuse
OpenMesh
::
Vec3f
Ka_
;
bool
Ka_is_set_
;
// ambient
OpenMesh
::
Vec3f
Ks_
;
bool
Ks_is_set_
;
// specular
OpenMesh
::
Vec3f
Ke_
;
bool
Ke_is_set_
;
// emission
float
Ni_
;
bool
Ni_is_set_
;
// index of refraction
float
Ns_
;
bool
Ns_is_set_
;
// shininess
int
illum_
;
bool
illum_is_set_
;
// illumination model
float
Tr_
;
bool
Tr_is_set_
;
// transperency
std
::
string
map_Kd_
;
int
index_Kd_
;
bool
map_Kd_is_set_
;
// Texture
};
...
...
OBJImporter.cc
View file @
b2797cdd
...
...
@@ -585,6 +585,8 @@ void OBJImporter::addMaterial(std::string _materialName){
//get textureIndex Property
OpenMesh
::
FPropHandleT
<
int
>
indexProperty
;
BaseObjectData
*
triMeshObj
=
PluginFunctions
::
baseObjectData
(
object
(
currentObject
()));
if
(
hasTexture
(
currentObject
()
)
){
bool
textureAllowed
=
!
(
objectOptions_
[
currentObject
()
]
&
FORCE_NOTEXTURES
);
...
...
@@ -597,6 +599,42 @@ void OBJImporter::addMaterial(std::string _materialName){
}
}
// set materialNode color
if
(
mat
.
has_Ka
())
{
TriMesh
::
Color
color
=
OpenMesh
::
color_cast
<
OpenMesh
::
Vec4f
>
(
mat
.
Ka
());
triMeshObj
->
materialNode
()
->
set_ambient_color
(
color
);
}
if
(
mat
.
has_Kd
())
{
TriMesh
::
Color
color
=
OpenMesh
::
color_cast
<
OpenMesh
::
Vec4f
>
(
mat
.
Kd
());
triMeshObj
->
materialNode
()
->
set_diffuse_color
(
color
);
}
if
(
mat
.
has_Ks
())
{
TriMesh
::
Color
color
=
OpenMesh
::
color_cast
<
OpenMesh
::
Vec4f
>
(
mat
.
Ks
());
triMeshObj
->
materialNode
()
->
set_specular_color
(
color
);
}
if
(
mat
.
has_Ke
())
{
TriMesh
::
Color
color
=
OpenMesh
::
color_cast
<
OpenMesh
::
Vec4f
>
(
mat
.
Ke
());
triMeshObj
->
materialNode
()
->
set_emission
(
color
);
}
if
(
mat
.
has_Ni
())
{
float
Ni
=
mat
.
Ni
();
triMeshObj
->
materialNode
()
->
set_indexOfRefraction
(
Ni
);
}
if
(
mat
.
has_Ns
())
{
float
shininess
=
mat
.
Ns
();
triMeshObj
->
materialNode
()
->
set_shininess
(
shininess
);
}
if
(
mat
.
has_illum
())
{
triMeshObj
->
materialNode
()
->
set_refractive
(
mat
.
isRefractive
());
}
for
(
unsigned
int
i
=
0
;
i
<
addedFacesTri_
[
currentGroup_
].
size
();
i
++
){
if
(
mat
.
has_Kd
()
)
{
...
...
@@ -612,7 +650,6 @@ void OBJImporter::addMaterial(std::string _materialName){
}
else
{
color
[
3
]
=
1.0
;
}
currentTriMesh
()
->
set_color
(
addedFacesTri_
[
currentGroup_
][
i
],
color
);
objectOptions_
[
currentObject
()
]
|=
FACECOLOR
;
}
...
...
@@ -631,6 +668,7 @@ void OBJImporter::addMaterial(std::string _materialName){
if
(
hasTexture
(
currentObject
()
)
&&
textureAllowed
)
currentTriMesh
()
->
property
(
indexProperty
,
addedFacesTri_
[
currentGroup_
][
i
])
=
0
;
}
}
}
...
...
@@ -646,6 +684,8 @@ void OBJImporter::addMaterial(std::string _materialName){
//get textureIndex Property
OpenMesh
::
FPropHandleT
<
int
>
indexProperty
;
BaseObjectData
*
polyMeshObj
=
PluginFunctions
::
baseObjectData
(
object
(
currentObject
()));
if
(
hasTexture
(
currentObject
()
)
){
bool
textureAllowed
=
!
(
objectOptions_
[
currentObject
()
]
&
FORCE_NOTEXTURES
);
...
...
@@ -672,10 +712,41 @@ void OBJImporter::addMaterial(std::string _materialName){
}
currentPolyMesh
()
->
set_color
(
addedFacePoly_
,
color
);
polyMeshObj
->
materialNode
()
->
set_diffuse_color
(
color
);
objectOptions_
[
currentObject
()
]
|=
FACECOLOR
;
}
}
// set materialNode color
if
(
mat
.
has_Ka
())
{
TriMesh
::
Color
color
=
OpenMesh
::
color_cast
<
OpenMesh
::
Vec4f
>
(
mat
.
Ka
());
polyMeshObj
->
materialNode
()
->
set_ambient_color
(
color
);
}
if
(
mat
.
has_Ks
())
{
TriMesh
::
Color
color
=
OpenMesh
::
color_cast
<
OpenMesh
::
Vec4f
>
(
mat
.
Ks
());
polyMeshObj
->
materialNode
()
->
set_specular_color
(
color
);
}
if
(
mat
.
has_Ke
())
{
TriMesh
::
Color
color
=
OpenMesh
::
color_cast
<
OpenMesh
::
Vec4f
>
(
mat
.
Ke
());
polyMeshObj
->
materialNode
()
->
set_emission
(
color
);
}
if
(
mat
.
has_Ni
())
{
float
Ni
=
mat
.
Ni
();
polyMeshObj
->
materialNode
()
->
set_indexOfRefraction
(
Ni
);
}
if
(
mat
.
has_Ns
())
{
float
shininess
=
mat
.
Ns
();
polyMeshObj
->
materialNode
()
->
set_shininess
(
shininess
);
}
if
(
mat
.
has_illum
())
{
polyMeshObj
->
materialNode
()
->
set_refractive
(
mat
.
isRefractive
());
}
bool
textureAllowed
=
!
(
objectOptions_
[
currentObject
()
]
&
FORCE_NOTEXTURES
);
// Set the texture index in the face index property
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment