Jump to content

Texture problems


mout99
 Share

Recommended Posts

Hello, I have an .obj file and .mtl, when I try to run it the texture gets wrong, look at the images
  var canvas = document.querySelector("#renderCanvas");
      // Load the BABYLON 3D engine
      var engine = new BABYLON.Engine(canvas, true);
      // -------------------------------------------------------------
      // Here begins a function that we will 'call' just after it's built
        var createScene = function () {
            var scene = new BABYLON.Scene(engine);

            //Adding a light
             var light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene);

            //Adding an Arc Rotate Camera
            var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene);
            camera.wheelPrecision = 100.0;
            camera.attachControl(canvas, false);

            // The first parameter can be used to specify which mesh to import. Here we import all meshes
            BABYLON.SceneLoader.ImportMesh("", "js/novo/", "bg4_obj.obj", scene, function (newMeshes) {
                // Set the target of the camera to the first imported mesh
                // camera.maxZ = 100;
                camera.setPosition(new BABYLON.Vector3(30,30,30));
                camera.target = newMeshes[0];
                camera.wheelPrecision = 30;
            });

            // Move the light with the camera
            scene.registerBeforeRender(function () {
                light.position = camera.position;
            });

            return scene;
        }
      // -------------------------------------------------------------
      // Now, call the createScene function that you just finished creating
      var scene = createScene();
      // Register a render loop to repeatedly render the scene
      engine.runRenderLoop(function () {
         scene.render();
      });
      // Watch for browser/canvas resize events
      window.addEventListener("resize", function () {
         engine.resize();
      });

 

img1.png

img2.png

img3.png

bg4_obj.mtl

bg4_obj.obj

Link to comment
Share on other sites

@mout99  : Well you could get all the materials used and then:

aMat.backFaceCulling = false;

replacing aMat with all the different materials you have

But that still leaves the issue of those odd faces - they should probably removed in some 3D software. BJS can not help you there

cheers, gryff :)

Link to comment
Share on other sites

9 hours ago, mout99 said:

Sorry, I do not understand, can you show me in my code how do I do it?

What do you want to do?

This?

On 28.06.2017 at 1:10 AM, gryff said:

@mout99  : Well you could get all the materials used and then:


aMat.backFaceCulling = false;

replacing aMat with all the different materials you have

But that still leaves the issue of those odd faces - they should probably removed in some 3D software. BJS can not help you there

cheers, gryff :)

 

Link to comment
Share on other sites

@mout99 : Are you now trying to apply a texture to the .obj model you linked to in your first post?

Looking at your .obj and .mtl files in a text editor, I find:

1.  no reference to a texture ( lines like this in the .mtl file "map_Kd E:\downloads\textures\cgtextures\brick\TexturesCom_BrickMessy0186_1_seamless_S.jpg") and

2. no lines that begin with "vt" in the .obj file - the uv texture coordinates. Example:

vt 0.250043 0.500000
vt 0.250043 0.749957
vt 0.000087 0.250043

All the two files do is reference materials not textures

What is the final model supposed to look like?

gryff :)

Link to comment
Share on other sites

@mout99 ; Well I looked at the page you linked to, and notice a couple of things (see image below)

1. There is no texture with the file - so what texture are you trying to add?

2. The model specifications say that it is "UVMapped" but does not have "unwrapped UVs".  No idea what he is trying to claim there - I can see no UVmap in your files

The image of the house model you post to is just using materials

properties1.png

Link to comment
Share on other sites

I took your.obj model and imported it into Blender. Then just exported it as a .babylon file. The mesh was not modified but I added an arcRotate camera and a hemiLight.

Her is the house loaded with no modifications to meshes/materials in the loading code

House

Note that some walls are not visible from the outside - normals are pointing inward.

Here is the same model, but this time I have set backFaceCulling to false. so both sides show.

House1

But if you rotate the model you see flashing - z-buffer fighting. Can't change that in BJS with your model. Also, I get the feeling there are missing faces. Not the best of models.

Open web developer console to see the tiny changes I made to the materials using code.

//because of mesh normals - change backFaceCulling to false
var theMaterials = newScene.materials;
console.log(theMaterials.length);
for (i=0; i < theMaterials.length; i++){
	theMaterials[i].backFaceCulling = false;
}
                    

 

Nothing more I can do or say except try a different house

cheers, gryff :).

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