Exemplo n.º 1
0
        public unsafe void RawArraySlice()
        {
            const int memLen = 5;
            var       mem    = stackalloc int[memLen] {
                0, 1, 2, 3, 4
            };
            var array   = new RawArray <int>((IntPtr)mem, memLen);
            var array03 = new RawArray <int>((IntPtr)mem, 3);
            var array22 = new RawArray <int>((IntPtr)(mem + 2), 2);
            var array32 = new RawArray <int>((IntPtr)(mem + 3), 2);

            AssertEqual(array.Slice(0, array.Length), array);
            AssertEqual(array.Slice(0, 3), array03);
            AssertEqual(array.Slice(2, 2), array22);
            AssertEqual(array.Slice(3, 2), array32);
            AssertEqual(array.Slice(3), array32);
            AssertEqual(array.Slice(0), array);
            Assert.True(array.Slice(5).IsEmpty);
            Assert.True(array.Slice(5, 0).IsEmpty);

            AssertEqual(array.AsSpan(0, array.Length), array);
            AssertEqual(array.AsSpan(0, 3), array03);
            AssertEqual(array.AsSpan(2, 2), array22);
            AssertEqual(array.AsSpan(3, 2), array32);
            AssertEqual(array.AsSpan(3), array32);
            AssertEqual(array.AsSpan(0), array);
            Assert.True(array.AsSpan(5).IsEmpty);
            Assert.True(array.AsSpan(5, 0).IsEmpty);
        }
Exemplo n.º 2
0
 private static void AssertEqual <T>(ReadOnlySpan <T> array1, RawArray <T> array2) where T : unmanaged, IEquatable <T>
 {
     Assert.True(array1.SequenceEqual(array2.AsSpan()));
 }
Exemplo n.º 3
0
        public MeshGeometry(FbxNode geometryNode)
        {
            Debug.Assert(geometryNode.IsMeshGeometry());

            ID   = geometryNode.Properties[0].AsInt64();
            Name = geometryNode.Properties[1].AsString();

            _positions          = default;
            _indicesRaw         = default;
            _normals            = default;
            NormalReferenceType = default;
            NormalMappingType   = default;
            _normalIndices      = default;
            _uv             = default;
            UVReferenceType = default;
            UVMappingType   = default;
            _uvIndices      = default;
            Materials       = default;
            foreach (var node in geometryNode.Children)
            {
                var nodeName = node.Name;
                if (nodeName.SequenceEqual(FbxConstStrings.Vertices()))
                {
                    // "Vertices"

                    _positions = node.Properties[0].AsDoubleArray();
                }
                else if (nodeName.SequenceEqual(FbxConstStrings.PolygonVertexIndex()))
                {
                    // "PolygonVertexindex"

                    _indicesRaw = node.Properties[0].AsInt32Array();
                }
                else if (nodeName.SequenceEqual(FbxConstStrings.LayerElementNormal()))
                {
                    // "LayerElementNormal"

                    _normals = node.FindChild(FbxConstStrings.Normals()).Properties[0].AsDoubleArray();

                    var referenceType = node.FindChild(FbxConstStrings.ReferenceInformationType()).Properties[0].AsString();
                    var mappingType   = node.FindChild(FbxConstStrings.MappingInformationType()).Properties[0].AsString();

                    NormalReferenceType = referenceType.ToReferenceInformationType();
                    NormalMappingType   = mappingType.ToMappingInformationType();

                    if (NormalReferenceType == ReferenceInformationType.IndexToDirect)
                    {
                        _normalIndices = node.FindChild(FbxConstStrings.NormalIndex()).Properties[0].AsInt32Array();
                    }
                }
                else if (nodeName.SequenceEqual(FbxConstStrings.LayerElementUV()))
                {
                    // "LayerElementUV"

                    _uv = node.FindChild(FbxConstStrings.UV()).Properties[0].AsDoubleArray();
                    var referenceType = node.FindChild(FbxConstStrings.ReferenceInformationType()).Properties[0].AsString();
                    var mappingType   = node.FindChild(FbxConstStrings.MappingInformationType()).Properties[0].AsString();
                    UVReferenceType = referenceType.ToReferenceInformationType();
                    UVMappingType   = mappingType.ToMappingInformationType();

                    if (UVReferenceType == ReferenceInformationType.IndexToDirect)
                    {
                        _uvIndices = node.FindChild(FbxConstStrings.UVIndex()).Properties[0].AsInt32Array();
                    }
                }
                else if (nodeName.SequenceEqual(FbxConstStrings.LayerElementMaterial()))
                {
                    // "LayerElementMaterial"

                    Materials = node.FindChild(FbxConstStrings.Materials()).Properties[0].AsInt32Array();
                }
            }
        }