Sign in to follow this  
yoric

Applying a Material with Texture to a Mesh imported from Blender

Recommended Posts

Hi everyone,

 

This looks pretty simple to do, but i'm badly stuck.

 

I'd like to apply a texture to a cube imported from Blender.

But i get a colored cube without the texture effect.

 

Below is a link to my playground code

(1 cube is from Blender, 1 other cube is created with BabylonJS)

 

I can't figure out why the same material doesn't have the same rendering.

Are those two cubes different kind of mesh object ?

 

Babylon_js_Playground.jpg

 

Playground link :

 


Share this post


Link to post
Share on other sites

I've just upgraded to "io_export_babylon.py" version 3.0.4 (was using 1.8.2 until now), using Blender 2.75

 

The rendering now looks different on the cube imported from Blender (texture still doesn't show up though).

 

Babylon_js_Playground.jpg

 

Playground update :

 

http://www.babylonjs-playground.com/#IZR8L#2

 

Cube export log : 

        Exporter version: 3.0.4, Blender version: 2.75 (sub 0)========= Conversion from Blender to Babylon.js =========        Python World class constructor completed        processing begun of mesh:  Cube                processing begun of Standard material:  Material                num positions      :  36                num normals        :  36                num uvs            :  0                num uvs2           :  0                num colors         :  0                num indices        :  36        processing begun of camera (FreeCamera):  Camera        processing begun of light (POINT):  Lamp========= Writing of scene file started ================== Writing of scene file completed ================== end of processing =========elapsed time:  0 min, 0.0022 secs

Share this post


Link to post
Share on other sites

Hi yoric. Just a couple of thoughts which may or may not help.

 

I looked at the playground demo - the blender cube is green. If I REM out line 29 of your playground script the Blender cube is grey (Blender standard material?).

 

That suggests that the cube is getting its green colour from the grass texture.

 

However, when I look at your babylon file there are no UVs , and log file you post above has "num uvs : 0"

 

So, I am thinking that the grass texture is just being smeared over the cube.

 

Just my thoughts.

 

cheers, gryff :)

 

 

 

Share this post


Link to post
Share on other sites

Try this Yoric:

 

1. In Blender select your cube object -> go into Edit Mode -> Select all the vertices.

2. Still in edit mode -> Mesh -> UV Unwrap ->Unwrap.

3. Now export your cube as Babylon file. This new .babylon file should now have a line:

"uvs":[1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,0,1,1,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,0,1]

cheers, gryff :)

 

Share this post


Link to post
Share on other sites

Amazing  Gryff !

 
i couldn't believe it, but it works like a charm  :)
 
Babylon_js_Playground.jpg
 
 
 
Before reading your last answer, i was doing the UV Mapping / Unwrapping from Blender like this :
 
Capture_d_e_cran_29_08_2015_18_40.jpg
 
 
So I was getting the cube textured from within Blender, and i could then open it from BabylonJS, giving this kind of result :
 
Babylon_js_Playground.jpg
 
 
But as you guessed, i wanted to apply the texture from BabylonJS, not from Blender.
 
It's getting a bit more clear to me now...
 
I suppose things work like this :
 
With using BabylonJS only :
  1. You create a mesh from BabylonJS
  2. You apply a material with diffuseTexture() to this mesh
With using Blender :
  1. You create a mesh from Blender
  2. You UV -> Unwrap it from Blender
  3. You import it from BabylonJS
  4. You now can apply a material with diffuseTexture() and get the same result
 
I thought creating a cube from BabylonJS or creating it from Blender and then importing it from BabylonJS was the same.
But obviously, it is not.
 
Maybe it means BabylonJS creates the UV's array under the hood when creating a mesh object.
 
 
Thank you so much again for your help Gryff !

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.