-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from B3zaleel/parse-mesh-data
Implement parsing of mesh connectivity data
- Loading branch information
Showing
37 changed files
with
3,243 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Draco.IO.Attributes; | ||
|
||
public class AttributeTransformData | ||
{ | ||
public AttributeTransformType TransformType { get; set; } = AttributeTransformType.InvalidTransform; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Draco.IO.Attributes; | ||
|
||
public class GeometryAttribute | ||
{ | ||
public GeometryAttributeType AttributeType { get; set; } | ||
public bool Normalized { get; set; } | ||
public long ByteOffset { get; set; } | ||
public uint UniqueId { get; set; } | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Draco/IO/Attributes/MeshAttributeIndicesEncodingData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Draco.IO.Extensions; | ||
|
||
namespace Draco.IO.Attributes; | ||
|
||
public class MeshAttributeIndicesEncodingData | ||
{ | ||
/// <summary> | ||
/// Total number of encoded/decoded attribute entries. | ||
/// </summary> | ||
public int NumValues { get; set; } = 0; | ||
public List<uint> EncodedAttributeValueIndexToCornerMap { get; set; } = []; | ||
public List<int> VertexToEncodedAttributeValueIndexMap { get; set; } = []; | ||
|
||
public MeshAttributeIndicesEncodingData(int numVertices) | ||
{ | ||
EncodedAttributeValueIndexToCornerMap.Resize(numVertices, 0U); | ||
VertexToEncodedAttributeValueIndexMap.Resize(numVertices, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Draco.IO.Extensions; | ||
|
||
namespace Draco.IO.Attributes; | ||
|
||
public class PointAttribute : GeometryAttribute | ||
{ | ||
private uint _numUniqueEntries = 0; | ||
private readonly List<uint> _indicesMap = []; | ||
|
||
public Stream? Buffer { get; private set; } | ||
public bool IsMappingIdentity { get; private set; } = false; | ||
public int IndicesMapSize { get => IsMappingIdentity ? 0 : _indicesMap.Count; } | ||
|
||
/// <summary> | ||
/// Contains the type and parameters of the transform that is applied on the attribute data. | ||
/// </summary> | ||
/// <value></value> | ||
public AttributeTransformData? AttributeTransformData { get; set; } | ||
|
||
public PointAttribute() { } | ||
|
||
public PointAttribute(GeometryAttribute att) | ||
{ | ||
AttributeType = att.AttributeType; | ||
Normalized = att.Normalized; | ||
ByteOffset = att.ByteOffset; | ||
UniqueId = att.UniqueId; | ||
} | ||
|
||
public uint MappedIndex(uint pointIndex) | ||
{ | ||
return IsMappingIdentity ? pointIndex : _indicesMap[(int)pointIndex]; | ||
} | ||
|
||
public void Reset(int numAttributeValues) | ||
{ | ||
// TODO: implement this | ||
_numUniqueEntries = (uint)numAttributeValues; | ||
} | ||
|
||
public void SetIdentityMapping() | ||
{ | ||
IsMappingIdentity = true; | ||
_indicesMap.Clear(); | ||
} | ||
|
||
public void SetExplicitMapping(int numPoints) | ||
{ | ||
IsMappingIdentity = false; | ||
_indicesMap.Resize(numPoints, Constants.kInvalidAttributeValueIndex); | ||
} | ||
|
||
public void SetPointMapEntry(uint pointIndex, uint entryIndex) | ||
{ | ||
Assertions.ThrowIfNot(IsMappingIdentity); | ||
_indicesMap[(int)pointIndex] = entryIndex; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Draco.IO.Entropy; | ||
using Draco.IO.Extensions; | ||
|
||
namespace Draco.IO.BitCoders; | ||
|
||
internal class RAnsBitDecoder | ||
{ | ||
private byte _probZero = 0; | ||
private AnsDecoder _ansDecoder = new(); | ||
|
||
public void StartDecoding(DecoderBuffer decoderBuffer) | ||
{ | ||
_probZero = decoderBuffer.ReadByte(); | ||
_ansDecoder = new(); | ||
uint size_in_bytes = decoderBuffer.BitStream_Version < Constants.BitStreamVersion(2, 2) ? decoderBuffer.ReadUInt32() : (uint)decoderBuffer.DecodeVarIntUnsigned(); | ||
_ansDecoder.ReadInit(decoderBuffer.ReadBytes((int)size_in_bytes), (int)size_in_bytes); | ||
} | ||
|
||
public uint DecodeNextBit() | ||
{ | ||
return _ansDecoder.RAbsRead(_probZero) ? 1U : 0U; | ||
} | ||
|
||
public uint DecodeLeastSignificantBits32(byte count) | ||
{ | ||
Assertions.ThrowIfNot(count > 0, "Count must be greater than 0"); | ||
Assertions.ThrowIfNot(count <= 32, "Count must be less than or equal to 32"); | ||
uint value = 0; | ||
while (count > 0) | ||
{ | ||
value = (value << 1) + DecodeNextBit(); | ||
count--; | ||
} | ||
return value; | ||
} | ||
|
||
public void EndDecoding(DecoderBuffer decoderBuffer) | ||
{ | ||
decoderBuffer.EndBitDecoding(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Draco.IO.Entropy; | ||
|
||
internal static class Ans | ||
{ | ||
public static uint MemGetLE16(byte[] data) | ||
{ | ||
uint value = (uint)data[1] << 8; | ||
value |= data[0]; | ||
return value; | ||
} | ||
|
||
public static uint MemGetLE24(byte[] data) | ||
{ | ||
var value = (uint)data[2] << 16; | ||
value |= (uint)data[1] << 8; | ||
value |= data[0]; | ||
return value; | ||
} | ||
|
||
public static uint MemGetLE32(byte[] data) | ||
{ | ||
var value = (uint)data[3] << 24; | ||
value |= (uint)data[2] << 16; | ||
value |= (uint)data[1] << 8; | ||
value |= data[0]; | ||
return value; | ||
} | ||
} |
Oops, something went wrong.