Jump to content

Custom textures on blender file from 3ds max


joeBImagine
 Share

Recommended Posts

Hello Babylon aficionados!!

I was hoping you all would be able to help.  I am not sure what I am doing wrong, but I am trying to attach a custom texture to a babylon file I exported from 3ds max.  This is the error in the console:  

babylon.js:3 BJS - [06:55:16]: Babylon.js engine (v3.0) launched
babylon.js:3 BJS - [06:55:17]: Material not found for mesh fc4bd914-849c-4954-9f0c-8c25b763cecb
t._WarnEnabled @ babylon.js:3
importMesh @ babylon.js:28
m @ babylon.js:28
(anonymous) @ babylon.js:28
a.oncomplete @ babylon.js:29
babylon.js:3 BJS - [06:55:17]: Material not found for mesh 6569d8e7-4fbc-478c-af4f-dbe31c4db185
t._WarnEnabled @ babylon.js:3
importMesh @ babylon.js:28
m @ babylon.js:28
(anonymous) @ babylon.js:28
a.oncomplete @ babylon.js:29

Which I understand, but I do not understand why using Babylon.Standardmaterial is not working.  

Here is the javascript code.  Let me know if anything else is needed to diagnose!!

var canvas, engine, createScene, scene, light, camera, sphere, box;

 canvas = document.querySelector("#renderCanvas");

 engine = new BABYLON.Engine(canvas, true);

 createScene = function() {
  scene = new BABYLON.Scene(engine);

  scene.clearColor = new BABYLON.Color3(0.85, 0.85, 0.85);

  scene.ambientColor = new BABYLON.Color3(0.75, 0.75, 0.75);

  //var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);

  camera = new BABYLON.ArcRotateCamera("camera1", 0, 0, 10, new BABYLON.Vector3.Zero(0, 0, 0), scene);

  //camera.radius = 5000;

  camera.setPosition(new BABYLON.Vector3(0, 5000, -10));

  camera.setTarget(BABYLON.Vector3.Zero(0, 5000, 0));

  camera.attachControl(canvas, true);

  camera.wheelPrecision = .1;

  light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);

  light.intensity = 1.0;

  sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 500, scene);

  //var box = BABYLON.Mesh.CreateBox("box", 6.0, scene, false, BABYLON.Mesh.DEFAULTSIDE);

  sphere.position.y = 1;

  //var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene);

   var meshVar = BABYLON.SceneLoader.ImportMesh("","scenes/31375_ElliotFabricMicrofiber2PieceSectionalSofa_Graphite/test/", "ElliotMicrofiber2PieceSectionalSofa.babylon", scene, function(newMeshes) {
      camera.target = newMeshes[0];

      var customMaterial = new BABYLON.StandardMaterial("customMaterial", scene);
      
      customMaterial.diffuseTexture = new BABYLON.Texture("scenes/31375_ElliotFabricMicrofiber2PieceSectionalSofa_Graphite/test/fabric.dif.jpg", scene);
      
      var customTexture = scene.meshes[0];
      customTexture.material = customMaterial;
     }
  ); 
  

  sphere.dispose();
  

  return scene;
};

scene = createScene();

engine.runRenderLoop(function() {
  scene.render();
});

window.addEventListener("resize", function() {
  engine.resize();
});

 

Link to comment
Share on other sites

Hello Deltakosh!!  

Thank you for the reply.  I have installed the debugger and I am getting this as the names under mesh (the first name is the group/parent):

31375_ElliotFabricMicrofiber2PieceSectionalSofa

ElliotFabricMicrofiber2PieceSectionalSofa_Graphite_Legs001

ElliotFabricMicrofiber2PieceSectionalSofa_Graphite_Base001

I've updated the code to reflect the name in the debugger:

  var meshVar = BABYLON.SceneLoader.ImportMesh("","scenes/31375_ElliotFabricMicrofiber2PieceSectionalSofa_Graphite/test/", "ElliotMicrofiber2PieceSectionalSofa.babylon", scene, function(newMeshes) {
      camera.target = newMeshes[0];
     
      var customMaterial1 = new BABYLON.StandardMaterial("fabric", scene);
      customMaterial1.diffuseTexture = new BABYLON.Texture("scenes/31375_ElliotFabricMicrofiber2PieceSectionalSofa_Graphite/test/fabric.dif.jpg", scene);

      ElliotFabricMicrofiber2PieceSectionalSofa_Graphite_Base001.material = customMaterial1;
     }
  ); 

I've even tried:

meshVar.material = customMaterial1;

But still nothing.  

The texture is definitely there however:  

 

image.png.68e2df298891a37dbad07fd16ceb6e12.png

I am not sure what I am doing wrong and/or missing.

 

Link to comment
Share on other sites

I finally got it!!  

it should have been:  newMeshes[2].material = customMaterial1; as the function newMeshes was the array where my meshes were being held!!  

var meshVar = BABYLON.SceneLoader.ImportMesh("","scenes/31375_ElliotFabricMicrofiber2PieceSectionalSofa_Graphite/test/", "ElliotMicrofiber2PieceSectionalSofa.babylon", scene, function(newMeshes) {
      camera.target = newMeshes[0];
     
      var customMaterial1 = new BABYLON.StandardMaterial("fabric", scene);
      customMaterial1.diffuseTexture = new BABYLON.Texture("scenes/31375_ElliotFabricMicrofiber2PieceSectionalSofa_Graphite/test/fabric.dif.jpg", scene);

      newMeshes[2].material= customMaterial1;
     }
  ); 

Thank you again for the help!!

In the future if a live repo is needed, would I need to add the code to a github repo?  Or an actual live server?

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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