Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Khanat code
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tycho Brahe
Khanat code
Commits
6344d0e5
Commit
6344d0e5
authored
Jan 04, 2017
by
kervala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge with develop
parent
a5c57266
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
49 deletions
+81
-49
code/nel/tools/3d/textures_tool/main.cpp
code/nel/tools/3d/textures_tool/main.cpp
+81
-49
No files found.
code/nel/tools/3d/textures_tool/main.cpp
View file @
6344d0e5
...
...
@@ -44,7 +44,7 @@ const CPoint Down(0, 1);
const
CPoint
Left
(
-
1
,
0
);
const
CPoint
Right
(
1
,
0
);
const
uint
TextureSize
=
4096
;
uint
TextureSize
=
4096
;
const
NLMISC
::
CRGBA
DiscardColor
=
NLMISC
::
CRGBA
::
Red
;
const
NLMISC
::
CRGBA
KeepColor
=
NLMISC
::
CRGBA
::
Blue
;
...
...
@@ -53,8 +53,19 @@ typedef std::vector<CPoint> CPoints;
struct
CFace
{
static
const
uint
INDICES_COUNT
=
3
;
uint
indices
[
INDICES_COUNT
];
std
::
vector
<
uint
>
indices
;
};
struct
CObject
{
std
::
string
name
;
std
::
vector
<
NLMISC
::
CUV
>
textureCoords
;
std
::
vector
<
CFace
>
faces
;
void
display
()
{
nlinfo
(
"Object %s processed with %u vertices and %u faces"
,
name
.
c_str
(),
(
uint
)
textureCoords
.
size
(),
(
uint
)
faces
.
size
());
}
};
bool
fillPoint
(
NLMISC
::
CBitmap
&
bitmap
,
sint
width
,
CPoints
&
points
)
...
...
@@ -100,6 +111,23 @@ bool fillPoint(NLMISC::CBitmap &bitmap, sint width, CPoints &points)
return
true
;
}
void
drawEdge
(
NLMISC
::
CBitmap
&
bitmap
,
const
CObject
&
object
,
const
CFace
&
face
,
uint
index0
,
uint
index1
)
{
NLMISC
::
CUV
uv0
=
object
.
textureCoords
[
face
.
indices
[
index0
]];
NLMISC
::
CUV
uv1
=
object
.
textureCoords
[
face
.
indices
[
index1
]];
std
::
vector
<
std
::
pair
<
sint
,
sint
>
>
pixels
;
// draw the triangle with vertices UV coordinates
NLMISC
::
drawFullLine
(
uv0
.
U
,
uv0
.
V
,
uv1
.
U
,
uv1
.
V
,
pixels
);
// for each pixels, set them to black
for
(
uint
j
=
0
,
jlen
=
pixels
.
size
();
j
<
jlen
;
++
j
)
{
bitmap
.
setPixelColor
(
pixels
[
j
].
first
,
pixels
[
j
].
second
,
NLMISC
::
CRGBA
::
Black
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
NLMISC
::
CApplicationContext
applicationContext
;
...
...
@@ -113,6 +141,7 @@ int main(int argc, char **argv)
args
.
addArg
(
"f"
,
"fill"
,
"color or image"
,
"Fill background part with color or image"
);
args
.
addArg
(
"u"
,
"uvmap"
,
""
,
"Generate a UV Map texture from OBJ file"
);
args
.
addArg
(
"w"
,
"width"
,
"width of border"
,
"Width of the border to fill (default 0)"
);
args
.
addArg
(
"s"
,
"size"
,
"size of output bitmap"
,
"Width and height of generated bitmap (default 4096)"
);
args
.
addArg
(
"b"
,
"background"
,
"background color"
,
"Color to use to fill background"
);
args
.
addArg
(
"o"
,
"output"
,
"filename"
,
"Output filename"
);
args
.
addAdditionalArg
(
"filename"
,
"File to process"
,
true
,
true
);
...
...
@@ -123,6 +152,12 @@ int main(int argc, char **argv)
std
::
string
output
=
args
.
haveArg
(
"o"
)
?
args
.
getArg
(
"o"
).
front
()
:
""
;
if
(
args
.
haveArg
(
"s"
))
{
// size of generated bitmap
NLMISC
::
fromString
(
args
.
getArg
(
"s"
).
front
(),
TextureSize
);
}
if
(
args
.
haveArg
(
"c"
))
{
// colorize
...
...
@@ -278,9 +313,6 @@ int main(int argc, char **argv)
if
(
args
.
haveArg
(
"u"
))
{
std
::
vector
<
NLMISC
::
CUV
>
verticeTextureCoords
;
std
::
vector
<
CFace
>
faces
;
NLMISC
::
CIFile
objFile
;
if
(
!
objFile
.
open
(
filename
))
...
...
@@ -289,6 +321,8 @@ int main(int argc, char **argv)
return
1
;
}
CObject
object
;
char
buffer
[
1024
];
while
(
!
objFile
.
eof
())
...
...
@@ -298,11 +332,18 @@ int main(int argc, char **argv)
std
::
string
line
(
buffer
);
if
(
line
.
size
()
>
1022
)
{
nlwarning
(
"More than 1022 bytes on a line!"
);
return
1
;
}
if
(
line
.
size
()
<
3
)
continue
;
// texture coordinate
if
(
line
.
substr
(
0
,
3
)
==
"vt "
)
{
// vertex texture
std
::
vector
<
std
::
string
>
tokens
;
NLMISC
::
explode
(
line
,
std
::
string
(
" "
),
tokens
);
...
...
@@ -313,7 +354,7 @@ int main(int argc, char **argv)
NLMISC
::
fromString
(
tokens
[
2
],
v
);
// V coordinates are inverted
verticeT
extureCoords
.
push_back
(
NLMISC
::
CUV
(
u
*
(
float
)
TextureSize
,
(
1.
f
-
v
)
*
(
float
)
TextureSize
));
object
.
t
extureCoords
.
push_back
(
NLMISC
::
CUV
(
u
*
(
float
)
TextureSize
,
(
1.
f
-
v
)
*
(
float
)
TextureSize
));
}
else
{
...
...
@@ -322,41 +363,49 @@ int main(int argc, char **argv)
}
else
if
(
line
.
substr
(
0
,
2
)
==
"f "
)
{
// face
std
::
vector
<
std
::
string
>
tokens
;
NLMISC
::
explode
(
line
,
std
::
string
(
" "
),
tokens
);
if
(
tokens
.
size
()
==
4
)
CFace
face
;
face
.
indices
.
resize
(
tokens
.
size
()
-
1
);
bool
faceValid
=
true
;
for
(
uint
i
=
1
,
ilen
=
tokens
.
size
();
i
<
ilen
;
++
i
)
{
CFace
face
;
std
::
vector
<
std
::
string
>
tokens2
;
NLMISC
::
explode
(
tokens
[
i
],
std
::
string
(
"/"
),
tokens2
);
for
(
uint
i
=
1
;
i
<
4
;
++
i
)
if
(
tokens2
.
size
()
==
3
)
{
std
::
vector
<
std
::
string
>
tokens2
;
NLMISC
::
explode
(
tokens
[
i
],
std
::
string
(
"/"
),
tokens2
);
if
(
tokens2
.
size
()
==
3
)
if
(
NLMISC
::
fromString
(
tokens2
[
1
],
face
.
indices
[
i
-
1
]))
{
NLMISC
::
fromString
(
tokens2
[
1
],
face
.
indices
[
i
-
1
]);
// we want indices start from 0 instead of 1
--
face
.
indices
[
i
-
1
];
}
else
{
nlwarning
(
"Not 3 arguments for indices"
)
;
faceValid
=
false
;
}
}
faces
.
push_back
(
face
);
}
else
{
nlwarning
(
"Not 4 arguments for F"
);
else
{
nlwarning
(
"Not 3 arguments for indices"
);
}
}
if
(
faceValid
)
object
.
faces
.
push_back
(
face
);
}
else
if
(
line
.
substr
(
0
,
2
)
==
"o "
)
{
// object
object
.
name
=
line
.
substr
(
2
);
object
.
display
();
}
}
nlinfo
(
"OBJ file processed with %u vertices and %u faces"
,
(
uint
)
verticeTextureCoords
.
size
(),
(
uint
)
faces
.
size
()
);
object
.
display
(
);
objFile
.
close
();
...
...
@@ -369,35 +418,18 @@ int main(int argc, char **argv)
memset
(
&
outBitmap
.
getPixels
()[
0
],
255
,
TextureSize
*
TextureSize
*
4
);
// process all faces
for
(
uint
i
=
0
,
len
=
faces
.
size
();
i
<
len
;
++
i
)
for
(
uint
i
=
0
,
ilen
=
object
.
faces
.
size
();
i
<
i
len
;
++
i
)
{
const
CFace
&
face
=
faces
[
i
];
// the 3 pixels of a vertice
NLMISC
::
CUV
uv0
=
verticeTextureCoords
[
face
.
indices
[
0
]];
NLMISC
::
CUV
uv1
=
verticeTextureCoords
[
face
.
indices
[
1
]];
NLMISC
::
CUV
uv2
=
verticeTextureCoords
[
face
.
indices
[
2
]];
const
CFace
&
face
=
object
.
faces
[
i
];
std
::
vector
<
std
::
pair
<
sint
,
sint
>
>
pixels
,
temp
;
// draw the triangle with vertices UV coordinates
NLMISC
::
drawFullLine
(
uv0
.
U
,
uv0
.
V
,
uv1
.
U
,
uv1
.
V
,
pixels
);
// append pixels
NLMISC
::
drawFullLine
(
uv1
.
U
,
uv1
.
V
,
uv2
.
U
,
uv2
.
V
,
temp
);
pixels
.
reserve
(
pixels
.
size
()
+
temp
.
size
());
pixels
.
insert
(
pixels
.
end
(),
temp
.
begin
(),
temp
.
end
());
// append pixels
NLMISC
::
drawFullLine
(
uv2
.
U
,
uv2
.
V
,
uv0
.
U
,
uv0
.
V
,
temp
);
pixels
.
reserve
(
pixels
.
size
()
+
temp
.
size
());
pixels
.
insert
(
pixels
.
end
(),
temp
.
begin
(),
temp
.
end
());
// for each pixels, set them to black
for
(
uint
j
=
0
,
jlen
=
pixels
.
size
();
j
<
jlen
;
++
j
)
// pixels of a face
for
(
uint
k
=
1
,
klen
=
face
.
indices
.
size
();
k
<
klen
;
++
k
)
{
outBitmap
.
setPixelColor
(
pixels
[
j
].
first
,
pixels
[
j
].
second
,
NLMISC
::
CRGBA
::
Blac
k
);
drawEdge
(
outBitmap
,
object
,
face
,
k
-
1
,
k
);
}
// link last and fist pixels
drawEdge
(
outBitmap
,
object
,
face
,
face
.
indices
.
size
()
-
1
,
0
);
}
// save output bitmap
...
...
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