Some other major webgl frameworks (three.js, babylon, unity) support loading OBJ files in the application’s runtime. Using this webgl-obj-loader I was able to accomplish this in my Playcanvas project. However, this does not read in the texture information in the MTL file, and the result in PC is a beige model that is otherwise correct. MTL loading is listed as one of the Github issues on that project, where the author says he is unsure how to approach the problem.
The significance of being able to import OBJ with MTL is that, using the FBX SDK, one could programmatically import any format by first converting to OBJ (Will’s suggestion). OBJ is arbitrary but the simplest format. I was unable to find webgl importers for other formats and also unable to get my head around writing an importer from scratch.
Another OBJ loader has MTL support but it is much simpler in that its output more closely resembles the original OBJ, containing faces data. I notice that three.js seems to natively support drawing faces in its drawmesh function whereas playcanvas does not. I think that if PC could draw facewise, then applying the material from MTL would be simpler. Anyways, the resultant model using this method in PC looks like this (a motorcycle):
Also, here is some sample code how I use the webgl-obj-loader’s output in Playcanvas :
var app = pc.Application.getApplication("application-canvas");
var context = app.context;
var sceneEntity = context.root.findByName("scene");
var pcMesh = pc.createMesh(
pc.app.graphicsDevice,
mesh.vertices,
{
normals: mesh.vertexNormals,
uvs: mesh.textures,
indices: mesh.indices
});
var material = new pc.StandardMaterial();
var node = new pc.GraphNode();
var instance = new pc.scene.MeshInstance(node, pcMesh, material);
var model = new pc.scene.Model();
model.graph = node;
model.meshInstances = [ instance ];
sceneEntity.addChild(node);
context.scene.addModel(model)
Relevant links: