示例#1
0
        public static int ExtendBufferAndGetAccessorIndex <T>(this glTF gltf, int bufferIndex,
                                                              ArraySegment <T> array,
                                                              glBufferTarget target = glBufferTarget.NONE,
                                                              float[] min           = null,
                                                              float[] max           = null) where T : struct
        {
            if (array.Count == 0)
            {
                return(-1);
            }
            var viewIndex = ExtendBufferAndGetViewIndex(gltf, bufferIndex, array, target);

            // index buffer's byteStride is unnecessary
            gltf.bufferViews[viewIndex].byteStride = 0;

            var accessorIndex = gltf.accessors.Count;
            var accessor      = new glTFAccessor
            {
                bufferView    = viewIndex,
                byteOffset    = 0,
                componentType = GetComponentType <T>(),
                type          = GetAccessorType <T>(),
                count         = array.Count,
            };

            if (min != null)
            {
                accessor.min = min;
            }
            if (max != null)
            {
                accessor.max = max;
            }

            gltf.accessors.Add(accessor);
            return(accessorIndex);
        }
示例#2
0
        IEnumerable <int> _GetIndices(glTFAccessor accessor, out int count)
        {
            count = accessor.count;
            var view = bufferViews[accessor.bufferView];

            switch ((glComponentType)accessor.componentType)
            {
            case glComponentType.UNSIGNED_BYTE:
            {
                return(GetAttrib <Byte>(accessor, view).Select(x => (int)(x)));
            }

            case glComponentType.UNSIGNED_SHORT:
            {
                return(GetAttrib <UInt16>(accessor, view).Select(x => (int)(x)));
            }

            case glComponentType.UNSIGNED_INT:
            {
                return(GetAttrib <UInt32>(accessor, view).Select(x => (int)(x)));
            }
            }
            throw new NotImplementedException("GetIndices: unknown componenttype: " + accessor.componentType);
        }
示例#3
0
 T[] GetAttrib <T>(glTFAccessor accessor, glTFBufferView view) where T : struct
 {
     return(GetAttrib <T>(accessor.count, accessor.byteOffset, view));
 }