@Override public int getElementSizeInBytes() { return elementType.getNumComponents() * getComponentSizeInBytes(); }
/** * Returns the element type for the given string. If the string is * <code>null</code> or does not describe a valid element type, * then <code>null</code> is returned * * @param string The string * @return The element type */ public static ElementType forString(String string) { if (string == null) { return null; } if (!contains(string)) { return null; } return ElementType.valueOf(string); }
/** * Returns whether the given string is a valid element type name, and may be * passed to <code>ElementType.valueOf</code> without causing an exception. * * @param s The string * @return Whether the given string is a valid element type */ public static boolean contains(String s) { for (ElementType elementType : values()) { if (elementType.name().equals(s)) { return true; } } return false; }
/** * 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 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; }
/** * Create the {@link Accessor} object from the given * {@link AccessorModel} * * @param accessorModel The {@link AccessorModel} * @param bufferViewIndex The {@link BufferView} index * @return The {@link Accessor} object */ private static Accessor createAccessor( AccessorModel accessorModel, int bufferViewIndex) { Accessor accessor = new Accessor(); accessor.setBufferView(bufferViewIndex); accessor.setByteOffset(accessorModel.getByteOffset()); accessor.setComponentType(accessorModel.getComponentType()); accessor.setCount(accessorModel.getCount()); accessor.setType(accessorModel.getElementType().toString()); AccessorData accessorData = accessorModel.getAccessorData(); accessor.setMax(AccessorDatas.computeMax(accessorData)); accessor.setMin(AccessorDatas.computeMin(accessorData)); return accessor; }
/** * Create the {@link AccessorModel} instances */ private void createAccessorModels() { List<Accessor> accessors = Optionals.of(gltf.getAccessors()); for (int i = 0; i < accessors.size(); i++) { Accessor accessor = accessors.get(i); Integer componentType = accessor.getComponentType(); Integer count = accessor.getCount(); ElementType elementType = ElementType.forString(accessor.getType()); DefaultAccessorModel accessorModel = new DefaultAccessorModel( componentType, count, elementType); accessorModels.add(accessorModel); } }
/** * 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 the {@link Accessor} object from the given * {@link AccessorModel} * * @param accessorModel The {@link AccessorModel} * @param bufferViewId The {@link BufferView} ID * @return The {@link Accessor} object */ private static Accessor createAccessor( AccessorModel accessorModel, String bufferViewId) { Accessor accessor = new Accessor(); accessor.setBufferView(bufferViewId); accessor.setByteOffset(accessorModel.getByteOffset()); accessor.setComponentType(accessorModel.getComponentType()); accessor.setCount(accessorModel.getCount()); accessor.setType(accessorModel.getElementType().toString()); accessor.setByteStride(accessorModel.getByteStride()); AccessorData accessorData = accessorModel.getAccessorData(); accessor.setMax(AccessorDatas.computeMax(accessorData)); accessor.setMin(AccessorDatas.computeMin(accessorData)); return accessor; }
/** * 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()); }
/** * 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 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 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 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();
createSparseValuesAccessorData(accessorSparseValues, accessorModel.getComponentType(), elementType.getNumComponents(), count);