@Override public int getElementSizeInBytes() { return elementType.getNumComponents() * getComponentSizeInBytes(); }
/** * Create an {@link AccessorModel} in the {@link BufferStructure} that * is currently being built. * * @param id The ID of the {@link AccessorModel} * @param componentType The component type, as a GL constant * @param type The type of the data, as a string corresponding to * the {@link ElementType} of the accessor * @param byteBuffer The actual data */ public void createAccessorModel(String id, int componentType, String type, ByteBuffer byteBuffer) { ElementType elementType = ElementType.valueOf(type); int numComponents = elementType.getNumComponents(); int numBytesPerComponent = Accessors.getNumBytesForAccessorComponentType(componentType); int numBytesPerElement = numComponents * numBytesPerComponent; int count = byteBuffer.capacity() / numBytesPerElement; DefaultAccessorModel accessorModel = new DefaultAccessorModel( componentType, count, elementType); bufferStructure.addAccessorModel(accessorModel, id); currentAccessorModels.add(accessorModel); rawAccessorModelByteBuffers.put(accessorModel, byteBuffer); }
/** * Create an {@link AccessorModel} in the {@link BufferStructure} that * is currently being built. * * @param id The ID for the {@link AccessorModel} * @param data The actual data * @param type The type of the data, as a string corresponding to * the {@link ElementType} of the accessor */ public void createAccessorModel( String id, short data[], String type) { ElementType elementType = ElementType.valueOf(type); int numComponents = elementType.getNumComponents(); if (data.length % numComponents != 0) { throw new IllegalArgumentException("Invalid data for type " + type + ". The data.length is not divisble by " + numComponents); } int componentType = GltfConstants.GL_UNSIGNED_SHORT; ByteBuffer byteBuffer = Buffers.createByteBufferFrom(ShortBuffer.wrap(data)); createAccessorModel(id, componentType, type, byteBuffer); }
/** * Create an {@link AccessorModel} in the {@link BufferStructure} that * is currently being built. * * @param id The ID of the {@link AccessorModel} * @param data The actual data * @param type The type of the data, as a string corresponding to * the {@link ElementType} of the accessor */ public void createAccessorModel( String id, float data[], String type) { ElementType elementType = ElementType.valueOf(type); int numComponents = elementType.getNumComponents(); if (data.length % numComponents != 0) { throw new IllegalArgumentException("Invalid data for type " + type + ". The data.length is not divisble by " + numComponents); } int componentType = GltfConstants.GL_FLOAT; ByteBuffer byteBuffer = Buffers.createByteBufferFrom(FloatBuffer.wrap(data)); createAccessorModel(id, componentType, type, byteBuffer); }
/** * Creates an {@link AccessorFloatData} for the given {@link AccessorModel} * * @param accessorModel The {@link AccessorModel} * @param bufferViewByteBuffer The byte buffer of the * {@link BufferViewModel} referenced by the {@link AccessorModel} * @return The {@link AccessorFloatData} * @throws NullPointerException If any argument is <code>null</code> * @throws IllegalArgumentException If the */ private static AccessorFloatData createFloat( AccessorModel accessorModel, ByteBuffer bufferViewByteBuffer) { return new AccessorFloatData(accessorModel.getComponentType(), bufferViewByteBuffer, accessorModel.getByteOffset(), accessorModel.getCount(), accessorModel.getElementType().getNumComponents(), accessorModel.getByteStride()); }
/** * Creates an {@link AccessorByteData} for the given {@link AccessorModel} * * @param accessorModel The {@link AccessorModel} * @param bufferViewByteBuffer The byte buffer of the * {@link BufferViewModel} referenced by the {@link AccessorModel} * @return The {@link AccessorByteData} * @throws NullPointerException If any argument is <code>null</code> * @throws IllegalArgumentException If the * {@link AccessorModel#getComponentType() component type} of the given * accessorModel is not <code>GL_BYTE</code> or * <code>GL_UNSIGNED_BYTE</code> */ private static AccessorByteData createByte( AccessorModel accessorModel, ByteBuffer bufferViewByteBuffer) { return new AccessorByteData(accessorModel.getComponentType(), bufferViewByteBuffer, accessorModel.getByteOffset(), accessorModel.getCount(), accessorModel.getElementType().getNumComponents(), accessorModel.getByteStride()); }
/** * Creates an {@link AccessorIntData} for the given {@link AccessorModel} * * @param accessorModel The {@link AccessorModel} * @param bufferViewByteBuffer The byte buffer of the * {@link BufferViewModel} referenced by the {@link AccessorModel} * @return The {@link AccessorIntData} * @throws NullPointerException If any argument is <code>null</code> * @throws IllegalArgumentException If the * {@link AccessorModel#getComponentType() component type} of the given * accessorModel is not <code>GL_INT</code> or <code>GL_UNSIGNED_INT</code> */ private static AccessorIntData createInt( AccessorModel accessorModel, ByteBuffer bufferViewByteBuffer) { return new AccessorIntData(accessorModel.getComponentType(), bufferViewByteBuffer, accessorModel.getByteOffset(), accessorModel.getCount(), accessorModel.getElementType().getNumComponents(), accessorModel.getByteStride()); }
/** * Creates an {@link AccessorShortData} for the given {@link AccessorModel} * * @param accessorModel The {@link AccessorModel} * @param bufferViewByteBuffer The byte buffer of the * {@link BufferViewModel} referenced by the {@link AccessorModel} * @return The {@link AccessorShortData} * @throws NullPointerException If any argument is <code>null</code> * @throws IllegalArgumentException If the * {@link AccessorModel#getComponentType() component type} of the given * accessorModel is not <code>GL_SHORT</code> or * <code>GL_UNSIGNED_SHORT</code> */ private static AccessorShortData createShort( AccessorModel accessorModel, ByteBuffer bufferViewByteBuffer) { return new AccessorShortData(accessorModel.getComponentType(), bufferViewByteBuffer, accessorModel.getByteOffset(), accessorModel.getCount(), accessorModel.getElementType().getNumComponents(), accessorModel.getByteStride()); }
int numComponents = accessorType.getNumComponents(); if (numComponents < 3)
int size = accessorModel.getElementType().getNumComponents(); int type = accessorModel.getComponentType(); int stride = accessorModel.getByteStride();
/** * Create a {@link DefaultAccessorModel} for the given {@link Accessor} * * @param accessor The {@link Accessor} * @return The {@link AccessorModel} */ private static DefaultAccessorModel createAccessorModel(Accessor accessor) { Integer componentType = accessor.getComponentType(); Integer byteOffset = accessor.getByteOffset(); Integer count = accessor.getCount(); ElementType elementType = ElementType.forString(accessor.getType()); Integer byteStride = accessor.getByteStride(); if (byteStride == null) { byteStride = elementType.getNumComponents() * Accessors.getNumBytesForAccessorComponentType( componentType); } DefaultAccessorModel accessorModel = new DefaultAccessorModel( componentType, count, elementType); accessorModel.setByteOffset(byteOffset); accessorModel.setByteStride(byteStride); return accessorModel; }
createSparseValuesAccessorData(accessorSparseValues, accessorModel.getComponentType(), elementType.getNumComponents(), count);