Skip to content

Commit 4d8ce5f

Browse files
committed
Finalized vertex color support: added glTF export
1 parent cfd4f32 commit 4d8ce5f

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

Exporters/ExportGLTF.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ static void ExportSection(GLTFExportContext& Context, const CBaseMeshLod& Lod, c
226226
int NormalBufIndex = Context.Data.AddZeroed();
227227
int TangentBufIndex = Context.Data.AddZeroed();
228228

229+
int ColorBufIndex = -1;
230+
if (Lod.VertexColors)
231+
{
232+
ColorBufIndex = Context.Data.AddZeroed();
233+
}
234+
229235
int BonesBufIndex = -1;
230236
int WeightsBufIndex = -1;
231237
if (Context.IsSkeletal())
@@ -245,6 +251,7 @@ static void ExportSection(GLTFExportContext& Context, const CBaseMeshLod& Lod, c
245251
BufferData& NormalBuf = Context.Data[NormalBufIndex];
246252
BufferData& TangentBuf = Context.Data[TangentBufIndex];
247253
BufferData* UVBuf[MAX_MESH_UV_SETS];
254+
BufferData* ColorBuf = NULL;
248255
BufferData* BonesBuf = NULL;
249256
BufferData* WeightsBuf = NULL;
250257

@@ -257,6 +264,12 @@ static void ExportSection(GLTFExportContext& Context, const CBaseMeshLod& Lod, c
257264
UVBuf[i]->Setup(numLocalVerts, "VEC2", BufferData::FLOAT, sizeof(CMeshUVFloat));
258265
}
259266

267+
if (Lod.VertexColors)
268+
{
269+
ColorBuf = &Context.Data[ColorBufIndex];
270+
ColorBuf->Setup(numLocalVerts, "VEC4", BufferData::UNSIGNED_BYTE, 4, /*InNormalized=*/ true);
271+
}
272+
260273
if (Context.IsSkeletal())
261274
{
262275
BonesBuf = &Context.Data[BonesBufIndex];
@@ -350,6 +363,15 @@ static void ExportSection(GLTFExportContext& Context, const CBaseMeshLod& Lod, c
350363
appSprintf(ARRAY_ARG(buf), "[ %g, %g, %g ]", VECTOR_ARG(Maxs));
351364
PositionBuf.BoundsMax = buf;
352365

366+
if (Lod.VertexColors)
367+
{
368+
for (int i = 0; i < numLocalVerts; i++)
369+
{
370+
int vertIndex = revIndexMap[i];
371+
ColorBuf->Put(Lod.VertexColors[vertIndex]);
372+
}
373+
}
374+
353375
if (Context.IsSkeletal())
354376
{
355377
for (int i = 0; i < numLocalVerts; i++)
@@ -397,6 +419,13 @@ static void ExportSection(GLTFExportContext& Context, const CBaseMeshLod& Lod, c
397419
" \"TANGENT\" : %d,\n",
398420
PositionBufIndex, NormalBufIndex, TangentBufIndex
399421
);
422+
if (Lod.VertexColors)
423+
{
424+
Ar.Printf(
425+
" \"COLOR_0\" : %d,\n",
426+
ColorBufIndex
427+
);
428+
}
400429
if (Context.IsSkeletal())
401430
{
402431
Ar.Printf(

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ detex
212212

213213
Changes
214214
~~~~~~~
215+
13.10.2019
216+
- added full vertex color support (loading, viewing, exporting)
217+
215218
09.10.2019
216219
- supported Borderlands 3 static meshes
217220

umodel

0 Bytes
Binary file not shown.

umodel.exe

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)