Jump to content

edit material of ImportMesh .obj


al404
 Share

Recommended Posts

I'm correctly loading a spaceship mesh with his material, but the ship looks dark even if other object are bright

I guess it could be emissiveColor or diffuseColor so i try to edit that property

spaceship = spaceshipMeshes[0];

spaceship.material.diffuseColor = new BABYLON.Color3(1.0, 0.2, 0.7);
spaceship.material.emissiveColor = new BABYLON.Color3(1, .2, .7);

i set 2 value from material example

if i use this code my script stops without errors and display the ship but doesn't continue

is not possible to edit material properties? i'm doing it the wrong way?

material is loaded with .obj

i attach my spaceship screenshot ( texture is almost white where it looks grey ) and console log of spaceship

 

capture 2016-08-12_01-49-20_PM.png

capture 2016-08-12_01-47-35_PM.png

Link to comment
Share on other sites

           newload.onSuccess = function (task) {
            $.each(task.loadedMeshes, function(i,e){
                var positions = e.getVerticesData(BABYLON.VertexBuffer.PositionKind);
                var indices = e.getIndices();
                var normals = e.getVerticesData(BABYLON.VertexBuffer.NormalKind);
                BABYLON.VertexData.ComputeNormals(positions, indices, normals);
                e.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals, true, true);
                BABYLON.VertexData.ComputeNormals(positions, e.getIndices(), normals);
...

 



fixed a similar problem I was having

Link to comment
Share on other sites

@al404 If you have "grey areas" on your mesh then it can be solved by importing your spaceship into Blender and "recalculating normals outside" . Then export as a .babylon file.

Or you can use the code @Pryme8 is suggesting which seems to be recalculating normals.

The.obj file format has been around a long time but you will find often find issues with normals -particularly older models.

cheers, gryff :)

 

Link to comment
Share on other sites

i did not specify but it has a .mtl with it

the problem is that i don't know how to use blender even for basic tasks

i bought the model and it comes with blender source too but when i open it i doesn't load the texture, i guess is only a path issue, i can try to look in it

i guess it , because in .mtl file the texture path was referred to windows hard disk since was something like with D:\path\texture.png

i can also remove the texture link in the .mtl file and manually apply the texture in babylon if this can help

Link to comment
Share on other sites

18 minutes ago, JCPalmer said:

@gryff, do you think a exporter option 'Ignore Normals' for .BABYLON exporter, or 'Normals Post Load' for .JS exporter is a good idea to reduce media size?  Would have to be coordinated with 'Flat shading' though.  FYI, shape keys require flat shading be done on export.

yes I think that would save on media size, and if we are recalculating natively why hold that data in the first place? it would be cool to have the object importer handle the normal recalculation as well instead of having to do it on the asset load.

Link to comment
Share on other sites

Sorry, hate to admit, but I do not even know what .obj or object importer are.  Probably should not have changed the subject.  Do not what

4 minutes ago, Pryme8 said:

why hold that data in the first place?

means. 

This really does need to be optional though.  Flipping normals need to be honored, when say you wish the inside of a box be the 'outside'.  Would upgrade .babylon exporter to 'Normals Post Load' as well, if someone handles the BJS side.  With computer built in-line code, I can do anything I want, no .babylon file rules to deal with.

Link to comment
Share on other sites

4 hours ago, Pryme8 said:

           newload.onSuccess = function (task) {
            $.each(task.loadedMeshes, function(i,e){
                var positions = e.getVerticesData(BABYLON.VertexBuffer.PositionKind);
                var indices = e.getIndices();
                var normals = e.getVerticesData(BABYLON.VertexBuffer.NormalKind);
                BABYLON.VertexData.ComputeNormals(positions, indices, normals);
                e.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals, true, true);
                BABYLON.VertexData.ComputeNormals(positions, e.getIndices(), normals);

FYI, the 2nd ComputeNormals should be pulled out.  Does nothing but waste time.

Implemented.  I found that a Mesh with:

num positions      :  11322
num normals        :  0
num uvs            :  22644
num uvs2           :  0
num colors         :  0
num indices        :  51432

this reduced the media file by 225 kb.  It increased the instancing time by 0.8 seconds.

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