de.javagl.obj.ObjUtils Java Examples

The following examples show how to use de.javagl.obj.ObjUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjGltfAssetCreatorV1.java    From JglTF with MIT License 5 votes vote down vote up
/**
 * Read the OBJ from the given URI, and return it as a "renderable" OBJ,
 * which contains only triangles, has unique vertex coordinates and
 * normals, and is single-indexed 
 * 
 * @param objUri The OBJ URI
 * @return The OBJ
 * @throws IOException If an IO error occurs
 */
private static Obj readObj(URI objUri) throws IOException
{
    logger.log(level, "Reading OBJ from " + objUri);
    
    try (InputStream objInputStream =  objUri.toURL().openStream())
    {
        Obj obj = ObjReader.read(objInputStream);
        return ObjUtils.convertToRenderable(obj);
    }
}
 
Example #2
Source File: ObjGltfAssetCreatorV2.java    From JglTF with MIT License 5 votes vote down vote up
/**
 * Read the OBJ from the given URI, and return it as a "renderable" OBJ,
 * which contains only triangles, has unique vertex coordinates and
 * normals, and is single-indexed 
 * 
 * @param objUri The OBJ URI
 * @return The OBJ
 * @throws IOException If an IO error occurs
 */
private static Obj readObj(URI objUri) throws IOException
{
    logger.log(level, "Reading OBJ from " + objUri);
    
    try (InputStream objInputStream =  objUri.toURL().openStream())
    {
        Obj obj = ObjReader.read(objInputStream);
        return ObjUtils.convertToRenderable(obj);
    }
}
 
Example #3
Source File: ObjGltfAssetCreatorV1.java    From JglTF with MIT License 4 votes vote down vote up
/**
 * Create the {@link MeshPrimitive}s for the given OBJ- and MTL data
 * 
 * @param obj The OBJ
 * @param mtls The MTLs
 * @return The {@link MeshPrimitive}s
 */
private List<MeshPrimitive> createMeshPrimitives(
    ReadableObj obj, Map<String, Mtl> mtls)
{
    // When there are no materials, create the MeshPrimitives for the OBJ
    int numMaterialGroups = obj.getNumMaterialGroups();
    if (numMaterialGroups == 0 || mtls.isEmpty())
    {
        return createMeshPrimitives(obj);
    }
    
    // Create the MeshPrimitives for the material groups
    List<MeshPrimitive> meshPrimitives = new ArrayList<MeshPrimitive>();
    for (int i = 0; i < numMaterialGroups; i++)
    {
        ObjGroup materialGroup = obj.getMaterialGroup(i);
        String materialGroupName = materialGroup.getName();
        Obj materialObj = ObjUtils.groupToObj(obj, materialGroup, null);
        Mtl mtl = mtls.get(materialGroupName);
        
        logger.log(level, "Creating MeshPrimitive for material " + 
            materialGroupName);

        // If the material group is too large, it may have to
        // be split into multiple parts
        String name = "materialGroup_" + String.valueOf(i);
        List<MeshPrimitive> subMeshPrimitives = 
            createPartMeshPrimitives(materialObj, name);

        assignMaterial(subMeshPrimitives, obj, mtl);
        meshPrimitives.addAll(subMeshPrimitives);
        
        if (bufferStrategy == BufferStrategy.BUFFER_PER_GROUP)
        {
            int bufferCounter = bufferStructureBuilder.getNumBufferModels();
            String bufferName = "buffer" + bufferCounter;
            String uri = bufferName + ".bin";
            bufferStructureBuilder.createBufferModel(bufferName, uri);
        }
        
    }
    return meshPrimitives;
}
 
Example #4
Source File: ObjGltfAssetCreatorV2.java    From JglTF with MIT License 4 votes vote down vote up
/**
 * Create the {@link MeshPrimitive}s for the given OBJ- and MTL data
 * 
 * @param obj The OBJ
 * @param mtls The MTLs
 * @return The {@link MeshPrimitive}s
 */
private List<MeshPrimitive> createMeshPrimitives(
    ReadableObj obj, Map<String, Mtl> mtls)
{
    // When there are no materials, create the MeshPrimitives for the OBJ
    int numMaterialGroups = obj.getNumMaterialGroups();
    if (numMaterialGroups == 0 || mtls.isEmpty())
    {
        return createMeshPrimitives(obj);
    }
    
    // Create the MeshPrimitives for the material groups
    List<MeshPrimitive> meshPrimitives = new ArrayList<MeshPrimitive>();
    for (int i = 0; i < numMaterialGroups; i++)
    {
        ObjGroup materialGroup = obj.getMaterialGroup(i);
        String materialGroupName = materialGroup.getName();
        Obj materialObj = ObjUtils.groupToObj(obj, materialGroup, null);
        Mtl mtl = mtls.get(materialGroupName);
        
        logger.log(level, "Creating MeshPrimitive for material " + 
            materialGroupName);

        // If the material group is too large, it may have to
        // be split into multiple parts
        String name = "materialGroup_" + String.valueOf(i);
        List<MeshPrimitive> subMeshPrimitives = 
            createPartMeshPrimitives(materialObj, name);

        assignMaterial(subMeshPrimitives, obj, mtl);
        meshPrimitives.addAll(subMeshPrimitives);
        
        if (bufferStrategy == BufferStrategy.BUFFER_PER_GROUP)
        {
            int bufferCounter = bufferStructureBuilder.getNumBufferModels();
            String bufferName = "buffer" + bufferCounter;
            String uri = bufferName + ".bin";
            bufferStructureBuilder.createBufferModel(bufferName, uri);
        }
        
    }
    return meshPrimitives;
}