@Override public Number[] getMin() { if (min == null) { min = AccessorDatas.computeMin(getAccessorData()); } return min.clone(); }
@Override public AccessorData getAccessorData() { if (accessorData == null) { accessorData = AccessorDatas.create(this); } return accessorData; }
/** * Make sure that the given type is <code>GL_BYTE</code> or * <code>GL_UNSIGNED_BYTE</code>, and throw an * <code>IllegalArgumentException</code> if this is not the case. * * @param type The type constant * @throws IllegalArgumentException If the given type is not * <code>GL_BYTE</code> or <code>GL_UNSIGNED_BYTE</code> */ static void validateByteType(int type) { if (!isByteType(type)) { throw new IllegalArgumentException( "The type is not GL_BYTE or GL_UNSIGNED_BYTE, but " + GltfConstants.stringFor(type)); } }
int count, int numComponentsPerElement, Integer byteStride) if (isByteType(componentType)) numComponentsPerElement, byteStride); if (isShortType(componentType)) numComponentsPerElement, byteStride); if (isIntType(componentType)) numComponentsPerElement, byteStride); if (isFloatType(componentType))
return createByte(accessorModel, byteBuffer); return createShort(accessorModel, byteBuffer); return createInt(accessorModel, byteBuffer); return createFloat(accessorModel, byteBuffer);
/** * 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; }
@Override public float[] getInverseBindMatrix(int index, float[] result) { float localResult[] = Utils.validate(result, 16); AccessorFloatData inverseBindMatricesData = AccessorDatas.createFloat(inverseBindMatrices); for (int j = 0; j < 16; j++) { localResult[j] = inverseBindMatricesData.get(index, j); } return localResult; }
/** * Make sure that the given type is <code>GL_FLOAT</code>, and throw an * <code>IllegalArgumentException</code> if this is not the case. * * @param type The type constant * @throws IllegalArgumentException If the given type is not * <code>GL_FLOAT</code> */ static void validateFloatType(int type) { if (!isFloatType(type)) { throw new IllegalArgumentException( "The type is not GL_FLOAT, but " + GltfConstants.stringFor(type)); } }
/** * Make sure that the given type is <code>GL_INT</code> or * <code>GL_UNSIGNED_INT</code>, and throw an * <code>IllegalArgumentException</code> if this is not the case. * * @param type The type constant * @throws IllegalArgumentException If the given type is not * <code>GL_INT</code> or <code>GL_UNSIGNED_INT</code> */ static void validateIntType(int type) { if (!isIntType(type)) { throw new IllegalArgumentException( "The type is not GL_INT or GL_UNSIGNED_INT, but " + GltfConstants.stringFor(type)); } }
@Override public Number[] getMax() { if (max == null) { max = AccessorDatas.computeMax(getAccessorData()); } return max.clone(); }
/** * Creates an {@link AccessorShortData} for the given {@link AccessorModel} * * @param accessorModel The {@link AccessorModel} * @return The {@link AccessorShortData} * @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> */ static AccessorShortData createShort(AccessorModel accessorModel) { BufferViewModel bufferViewModel = accessorModel.getBufferViewModel(); return createShort(accessorModel, bufferViewModel.getBufferViewData()); }
/** * Creates an {@link AccessorByteData} for the given {@link AccessorModel} * * @param accessorModel The {@link AccessorModel} * @return The {@link AccessorByteData} * @throws IllegalArgumentException If the * {@link AccessorModel#getComponentType() component type} of the given * accessor is not <code>GL_BYTE</code> or <code>GL_UNSIGNED_BYTE</code> */ static AccessorByteData createByte(AccessorModel accessorModel) { BufferViewModel bufferViewModel = accessorModel.getBufferViewModel(); return createByte(accessorModel, bufferViewModel.getBufferViewData()); }
/** * Creates an {@link AccessorIntData} for the given {@link AccessorModel} * * @param accessorModel The {@link AccessorModel} * @return The {@link AccessorIntData} * @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> */ static AccessorIntData createInt(AccessorModel accessorModel) { BufferViewModel bufferViewModel = accessorModel.getBufferViewModel(); return createInt(accessorModel, bufferViewModel.getBufferViewData()); }
/** * 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} * @return The {@link AccessorFloatData} * @throws IllegalArgumentException If the * {@link AccessorModel#getComponentType() component type} of the given * accessorModel is not <code>GL_FLOAT</code> */ public static AccessorFloatData createFloat(AccessorModel accessorModel) { BufferViewModel bufferViewModel = accessorModel.getBufferViewModel(); return createFloat(accessorModel, bufferViewModel.getBufferViewData()); }
/** * Create the {@link AccessorData} for the given {@link AccessorModel} * * @param accessorModel The {@link AccessorModel} * @return The {@link AccessorData} */ public static AccessorData create(AccessorModel accessorModel) { BufferViewModel bufferViewModel = accessorModel.getBufferViewModel(); ByteBuffer bufferViewData = bufferViewModel.getBufferViewData(); return create(accessorModel, bufferViewData); }
/** * Create the {@link AccessorData} for the given * {@link AccessorSparseValues} * * @param accessorSparseValues The {@link AccessorSparseValues} * @param componentType The component type of the {@link Accessor} * @param numComponentsPerElement The number of components per element * of the {@link AccessorModel#getElementType() accessor element type} * @param count The count from the {@link AccessorSparse} * @return The {@link AccessorData} */ private AccessorData createSparseValuesAccessorData( AccessorSparseValues accessorSparseValues, int componentType, int numComponentsPerElement, int count) { Integer bufferViewIndex = accessorSparseValues.getBufferView(); BufferViewModel bufferViewModel = bufferViewModels.get(bufferViewIndex); ByteBuffer bufferViewData = bufferViewModel.getBufferViewData(); int byteOffset = Optionals.of(accessorSparseValues.getByteOffset(), 0); return AccessorDatas.create( componentType, bufferViewData, byteOffset, count, numComponentsPerElement, null); }
/** * Create the {@link AccessorData} for the given * {@link AccessorSparseIndices} * * @param accessorSparseIndices The {@link AccessorSparseIndices} * @param count The count from the {@link AccessorSparse} * @return The {@link AccessorData} */ private AccessorData createSparseIndicesAccessorData( AccessorSparseIndices accessorSparseIndices, int count) { Integer componentType = accessorSparseIndices.getComponentType(); Integer bufferViewIndex = accessorSparseIndices.getBufferView(); BufferViewModel bufferViewModel = bufferViewModels.get(bufferViewIndex); ByteBuffer bufferViewData = bufferViewModel.getBufferViewData(); int byteOffset = Optionals.of(accessorSparseIndices.getByteOffset(), 0); return AccessorDatas.create( componentType, bufferViewData, byteOffset, count, 1, null); }
ByteBuffer baseBufferViewData = baseBufferViewModel.getBufferViewData(); AccessorData baseAccessorData = AccessorDatas.create( accessorModel, baseBufferViewData); AccessorData denseAccessorData = AccessorDatas.create(accessorModel, bufferData); substituteSparseAccessorData(accessor, accessorModel, denseAccessorData, baseAccessorData); AccessorDatas.create(accessorModel, bufferData); substituteSparseAccessorData(accessor, accessorModel, denseAccessorData, null);