Jump to content

Applying material not working with .glb/.gltf but works with .obj


Recommended Posts


I am unable to apply material to objects loaded in .gltf/.glb format but am able to do so for objects loaded in .obj formal.

I have attached chair_gltf.png, chair_obj.png and relevant code below.

I would like to create a demonstration in the babylon playground but cant since I dont know how to add assets to the playground.


1) Can someone help me figure out how to apply materials to models loaded via gltf?

2) How does one add static assets to babylon playground?

function addObject(scene, model){
  var scale = model.scale;
  var pos = function(t) {
      t.loadedMeshes.forEach(function(m) {
        m.scaling = new BABYLON.Vector3(scale,scale,scale);
        let materialSphere1 = new BABYLON.StandardMaterial("texture1", scene);
        materialSphere1.alpha = 0.5;
        materialSphere1.diffuseColor = new BABYLON.Color3(1.0, 0.2, 0.7);
        m.material = materialSphere1;
  var loader = new BABYLON.AssetsManager(scene);
  let file_dir = dirname(model.gltf_url).substring(1) + '/'
  let file_name = basename(model.gltf_url)

  var object = loader.addMeshTask(model.title, "", file_dir, file_name);
  object.onSuccess = pos




Link to comment
Share on other sites

@Luaacro I have this playground to demonstrate the issue. The chair on the left is glb and the chair on right is obj. The relevant code follows

    // create loader
    var loader = new BABYLON.AssetsManager(scene);
    var glbTask = loader.addMeshTask("batman", "", "https://dl.dropboxusercontent.com/u/28136236/models/chair/", "chair.glb");
    var objTask = loader.addMeshTask("batman", "", "https://dl.dropboxusercontent.com/u/28136236/models/chair/", "chair.obj");

    // function that takes a mesh and applies pink material
    function applyMaterialToMesh(mesh){
        var materialSphere1 = new BABYLON.StandardMaterial("texture1", scene);
        materialSphere1.diffuseColor = new BABYLON.Color3(1.0, 0.2, 0.7);
        mesh.material = materialSphere1;

    // applies pink material and move mesh one to left
    objTask.onSuccess = function (task) {
        task.loadedMeshes[0].position.x += 1

    // applies material but does not move to left
    glbTask.onSuccess = function (task) {

I hope this suffices. The code in my project is slightly convoluted. 

Relevant files are here

Edited by cricket
Added link to assets
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...