/** * Create the {@link MaterialModel} instances */ private void createMaterialModels() { Map<String, Material> materials = Optionals.of(gltf.getMaterials()); for (int i = 0; i < materials.size(); i++) { materialModels.add(new DefaultMaterialModel()); } }
/** * 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); } }
/** * Validate the {@link GlTF#getMaterials()} * * @param currentContext The optional {@link ValidatorContext} of the glTF * @return The {@link ValidatorResult} */ private ValidatorResult validateMaterials(ValidatorContext currentContext) { ValidatorContext context = new ValidatorContext(currentContext); ValidatorResult validatorResult = new ValidatorResult(); validatorResult.add(validateElements( getGltf().getMaterials(), "materials", false, context, materialValidator::validateMaterial)); if (validatorResult.hasErrors()) { return validatorResult; } return validatorResult; }
Map<String, Material> materials = Optionals.of(gltf.getMaterials()); for (Entry<String, Material> entry : materials.entrySet())
getGltf().getMaterials(), materialId, context)); if (validatorResult.hasErrors()) Material material = getGltf().getMaterials().get(materialId);
Material material = getGltf().getMaterials().get(materialId);
/** * Compute the {@link IndexMappingSet} for the given glTF instance. * The {@link IndexMappingSet} will contain index mappings for all * top-level dictionaries of the given glTF. * * @param gltf The glTF * @return The {@link IndexMappingSet} */ static IndexMappingSet create(GlTF gltf) { IndexMappingSet indexMappingSet = new IndexMappingSet(); indexMappingSet.generate("accessors", gltf.getAccessors()); indexMappingSet.generate("animations", gltf.getAnimations()); indexMappingSet.generate("buffers", gltf.getBuffers()); indexMappingSet.generate("bufferViews", gltf.getBufferViews()); indexMappingSet.generate("cameras", gltf.getCameras()); indexMappingSet.generate("images", gltf.getImages()); indexMappingSet.generate("materials", gltf.getMaterials()); indexMappingSet.generate("meshes", gltf.getMeshes()); indexMappingSet.generate("nodes", gltf.getNodes()); indexMappingSet.generate("programs", gltf.getPrograms()); indexMappingSet.generate("samplers", gltf.getSamplers()); indexMappingSet.generate("scenes", gltf.getScenes()); indexMappingSet.generate("shaders", gltf.getShaders()); indexMappingSet.generate("skins", gltf.getSkins()); indexMappingSet.generate("techniques", gltf.getTechniques()); indexMappingSet.generate("textures", gltf.getTextures()); return indexMappingSet; }