/** * 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); }
/** * 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); }