Skip to content

Commit

Permalink
Merge pull request #90 from Minon/azurarok_colladaFix_01_2024
Browse files Browse the repository at this point in the history
Fix collada dae import for geometry with shared input offsets
  • Loading branch information
soopercool101 authored Feb 6, 2024
2 parents 660c3f4 + c4b873d commit 04c7bd4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion BrawlLib/Internal/Matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ public Vector3 GetAngles()
}
else
{
x = (float) Math.Atan2(p[4], -p[8]);
x = (float) Math.Atan2(-p[4], -p[8]);
}
}
else
Expand Down
26 changes: 16 additions & 10 deletions BrawlLib/Modeling/Collada/ColladaAssetDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,16 +491,19 @@ private static PrimitiveManager DecodePrimitives(GeometryEntry geo)
{
int count = prim._inputs.Count;
//Map inputs to command sequence
foreach (InputEntry inp in prim._inputs)
for (int i = 0; i < count; ++i)
{
InputEntry inp = prim._inputs[i];

if (inp._outputOffset == -1)
{
pCmd[inp._offset].Cmd = 0;
pCmd[i].Cmd = 0;
}
else
{
pCmd[inp._offset].Cmd = (byte) inp._semantic;
pCmd[inp._offset].Index = (byte) inp._outputOffset;
pCmd[i].Cmd = (byte) inp._semantic;
pCmd[i].Index = (byte) inp._outputOffset;
pCmd[i].Offset = (byte)inp._offset;

//Assign input buffer
foreach (SourceEntry src in geo._sources)
Expand Down Expand Up @@ -609,31 +612,32 @@ private static PrimitiveManager DecodePrimitives(GeometryEntry geo)
private static void RunPrimitiveCmd(byte** pIn, byte** pOut, PrimitiveDecodeCommand* pCmd, int cmdCount,
ushort* pIndex, int count)
{
int stride = 0;
int buffer;
while (count-- > 0)
{
for (int i = 0; i < cmdCount; i++)
{
buffer = pCmd[i].Index;
stride = Math.Max(stride, pCmd[i].Offset);
switch ((SemanticType) pCmd[i].Cmd)
{
case SemanticType.None:
*pIndex += 1;
break;

case SemanticType.VERTEX:
//Can't do remap table because weights haven't been assigned yet!
*(ushort*) pOut[buffer] = *pIndex++;
*(ushort*) pOut[buffer] = *(pIndex + pCmd[i].Offset);
pOut[buffer] += 2;
break;

case SemanticType.NORMAL:
*(Vector3*) pOut[buffer] = ((Vector3*) pIn[buffer])[*pIndex++];
*(Vector3*) pOut[buffer] = ((Vector3*) pIn[buffer])[*(pIndex + pCmd[i].Offset)];
pOut[buffer] += 12;
break;

case SemanticType.COLOR:
float* p = (float*) (pIn[buffer] + *pIndex++ * 16);
float* p = (float*) (pIn[buffer] + *(pIndex + pCmd[i].Offset) * 16);
byte* p2 = pOut[buffer];
for (int x = 0; x < 4; x++)
{
Expand All @@ -645,13 +649,14 @@ private static void RunPrimitiveCmd(byte** pIn, byte** pOut, PrimitiveDecodeComm

case SemanticType.TEXCOORD:
//Flip y axis so coordinates are bottom-up
Vector2 v = ((Vector2*) pIn[buffer])[*pIndex++];
Vector2 v = ((Vector2*) pIn[buffer])[*(pIndex + pCmd[i].Offset)];
v._y = 1.0f - v._y;
*(Vector2*) pOut[buffer] = v;
pOut[buffer] += 8;
break;
}
}
pIndex += stride + 1;
}
}

Expand All @@ -660,7 +665,8 @@ private struct PrimitiveDecodeCommand
{
public byte Cmd;
public byte Index;
public byte Pad1, Pad2;
public byte Offset;
public byte Padding;
}
}
}
16 changes: 10 additions & 6 deletions BrawlLib/Modeling/Collada/ColladaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@ private PrimitiveEntry ParsePrimitive(ColladaBeginMode type)
PrimitiveEntry prim = new PrimitiveEntry {_type = type};
PrimitiveFace p;
int val;
int stride = 0, elements = 0;
int stride = 0;
HashSet<int> uniqueOffsets = new HashSet<int>();
int elements = 0;

switch (type)
{
Expand Down Expand Up @@ -706,21 +708,23 @@ private PrimitiveEntry ParsePrimitive(ColladaBeginMode type)
{
if (_reader.Name.Equals("input", true))
{
prim._inputs.Add(ParseInput());
elements++;
InputEntry entry = ParseInput();
prim._inputs.Add(entry);
uniqueOffsets.Add(entry._offset);
++elements;
}
else if (_reader.Name.Equals("p", true))
{
List<ushort> indices = new List<ushort>(stride * elements);
List<ushort> indices = new List<ushort>(stride * uniqueOffsets.Count);

p = new PrimitiveFace();
//p._pointIndices.Capacity = stride * elements;
//p._pointIndices.Capacity = stride * uniqueOffsets.Count;
while (_reader.ReadValue(&val))
{
indices.Add((ushort) val);
}

p._pointCount = indices.Count / elements;
p._pointCount = indices.Count / uniqueOffsets.Count;
p._pointIndices = indices.ToArray();

switch (type)
Expand Down

0 comments on commit 04c7bd4

Please sign in to comment.