mirror of
https://git.mirrors.martin98.com/https://github.com/google/draco
synced 2025-08-11 19:59:01 +08:00
retain alpha vertex colour attribute when decompressing unity mesh (#392)
* make sure alpha vertex colour attribute is retained * make sure unity plugin loads alpha vertex colour as well
This commit is contained in:
parent
5a090b9f71
commit
da0df33a89
@ -113,12 +113,12 @@ int DecodeMeshForUnity(char *data, unsigned int length,
|
|||||||
const auto color_att =
|
const auto color_att =
|
||||||
in_mesh->GetNamedAttribute(draco::GeometryAttribute::COLOR);
|
in_mesh->GetNamedAttribute(draco::GeometryAttribute::COLOR);
|
||||||
if (color_att != nullptr) {
|
if (color_att != nullptr) {
|
||||||
unity_mesh->color = new float[in_mesh->num_points() * 3];
|
unity_mesh->color = new float[in_mesh->num_points() * 4];
|
||||||
unity_mesh->has_color = true;
|
unity_mesh->has_color = true;
|
||||||
for (draco::PointIndex i(0); i < in_mesh->num_points(); ++i) {
|
for (draco::PointIndex i(0); i < in_mesh->num_points(); ++i) {
|
||||||
const draco::AttributeValueIndex val_index = color_att->mapped_index(i);
|
const draco::AttributeValueIndex val_index = color_att->mapped_index(i);
|
||||||
if (!color_att->ConvertValue<float, 3>(
|
if (!color_att->ConvertValue<float, 4>(
|
||||||
val_index, unity_mesh->color + i.value() * 3)) {
|
val_index, unity_mesh->color + i.value() * 4)) {
|
||||||
ReleaseUnityMesh(&unity_mesh);
|
ReleaseUnityMesh(&unity_mesh);
|
||||||
return -8;
|
return -8;
|
||||||
}
|
}
|
||||||
|
@ -243,9 +243,9 @@ public unsafe class DracoMeshLoader
|
|||||||
byte* normaladdr = (byte*)tmpMesh->normal;
|
byte* normaladdr = (byte*)tmpMesh->normal;
|
||||||
byte* coloraddr = (byte*)tmpMesh->color;
|
byte* coloraddr = (byte*)tmpMesh->color;
|
||||||
byte* uvaddr = (byte*)tmpMesh->texcoord;
|
byte* uvaddr = (byte*)tmpMesh->texcoord;
|
||||||
for (int i = 0; i < tmpMesh->numVertices; ++i) {
|
for (int i = 0; i < tmpMesh->numVertices; ++i)
|
||||||
|
{
|
||||||
int numValuePerVertex = 3;
|
int numValuePerVertex = 3;
|
||||||
|
|
||||||
for (int j = 0; j < numValuePerVertex; ++j)
|
for (int j = 0; j < numValuePerVertex; ++j)
|
||||||
{
|
{
|
||||||
int byteStridePerVertex = byteStridePerValue * numValuePerVertex;
|
int byteStridePerVertex = byteStridePerValue * numValuePerVertex;
|
||||||
@ -256,12 +256,17 @@ public unsafe class DracoMeshLoader
|
|||||||
{
|
{
|
||||||
newNormals[i][j] = *((float*)(normaladdr + OffSet));
|
newNormals[i][j] = *((float*)(normaladdr + OffSet));
|
||||||
}
|
}
|
||||||
if (tmpMesh->hasColor)
|
|
||||||
{
|
|
||||||
newColors[i][j] = *((float*)(coloraddr + OffSet));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tmpMesh->hasColor)
|
||||||
|
{
|
||||||
|
numValuePerVertex = 4;
|
||||||
|
for (int j = 0; j < numValuePerVertex; ++j)
|
||||||
|
{
|
||||||
|
int byteStridePerVertex = byteStridePerValue * numValuePerVertex;
|
||||||
|
newColors[i][j] = *((float*)(coloraddr + (i * byteStridePerVertex + byteStridePerValue * j)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tmpMesh->hasTexcoord)
|
if (tmpMesh->hasTexcoord)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user