/** * Create {@link Material} instances with random colors, and assign * them to the given {@link MeshPrimitive} instances * * @param meshPrimitives The {@link MeshPrimitive} instances * @param withNormals Whether the {@link MeshPrimitive} instances have * normal information */ private void assignRandomColorMaterials( Iterable<? extends MeshPrimitive> meshPrimitives, boolean withNormals) { Random random = new Random(0); for (MeshPrimitive meshPrimitive : meshPrimitives) { float r = random.nextFloat(); float g = random.nextFloat(); float b = random.nextFloat(); Material material = mtlMaterialHandler.createMaterialWithColor( withNormals, r, g, b); String materialId = GltfIds.generateId("material", gltf.getMaterials()); gltf.addMaterials(materialId, material); meshPrimitive.setMaterial(materialId); } }
/** * Create a default {@link Material}, and assign it to all the given * {@link MeshPrimitive} instances * * @param meshPrimitives The {@link MeshPrimitive} instances * @param withNormals Whether the {@link MeshPrimitive} instances have * normal information */ private void assignDefaultMaterial( Iterable<? extends MeshPrimitive> meshPrimitives, boolean withNormals) { Material material = mtlMaterialHandler.createMaterialWithColor( withNormals, 0.75f, 0.75f, 0.75f); String materialId = GltfIds.generateId("material", gltf.getMaterials()); gltf.addMaterials(materialId, material); for (MeshPrimitive meshPrimitive : meshPrimitives) { meshPrimitive.setMaterial(materialId); } }
/** * Create a {@link Material} for the given OBJ and MTL, and assign it * to all the given {@link MeshPrimitive} instances * * @param meshPrimitives The {@link MeshPrimitive} instances * @param obj The OBJ * @param mtl The MTL */ private void assignMaterial( Iterable<? extends MeshPrimitive> meshPrimitives, ReadableObj obj, Mtl mtl) { Material material = mtlMaterialHandler.createMaterial(obj, mtl); String materialId = GltfIds.generateId("material", gltf.getMaterials()); gltf.addMaterials(materialId, material); for (MeshPrimitive meshPrimitive : meshPrimitives) { meshPrimitive.setMaterial(materialId); } }