Jump to content

[solved] How to fix this?


mout99
 Share

Recommended Posts

I can see through my obj, how to concert it?
 // Get the canvas element from our HTML below
      var canvas = document.querySelector("#renderCanvas");
      // Load the BABYLON 3D engine
      var engine = new BABYLON.Engine(canvas, false);
      // -------------------------------------------------------------
      // 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("Hemi0", new BABYLON.Vector3(0, 1, 0), scene);
				 light.diffuse = new BABYLON.Color3(1, 1, 1);
				 light.intensity = 0.6;
				 light.groundColor = new BABYLON.Color3(1, 1, 1);
				 light.direction = new BABYLON.Vector3(0, -1, 0);

            //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("", "obj/", "teste.obj", scene, function (newMeshes) {
              BABYLON.OBJFileLoader.OPTIMIZE_WITH_UV = true;

                  var zeromat = new BABYLON.StandardMaterial("zeromat", scene);
                   zeromat.diffuseTexture = new BABYLON.Texture("obj/back2.jpg", scene);
                   zeromat.backFaceCulling = true;
                   zeromat.wireframe = false;
                   scene.meshes[0].material = zeromat;

                   var meiomat = new BABYLON.StandardMaterial("meiomat", scene);
                   meiomat.diffuseColor = new BABYLON.Color3(0.9, 0.9, 0.9);
                   scene.meshes[1].material = meiomat;
                  
                // Set the target of the camera to the first imported mesh
                // camera.maxZ = 100;
                camera.maxZ = 0;
                camera.setPosition(new BABYLON.Vector3(7000,7000,7000));
                camera.target = newMeshes[0];
                camera.wheelPrecision = 0.1;
            });

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

            return scene;
        }

      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();
      });

 

nv1.png

nv2.png

Link to comment
Share on other sites

Your PG does not work...we are getting a CORS issue. Can you try to save it to github. I know we can load it from there with rawgit CDN.

Can you make sure you export your objects in left handed mode? Can you try another format (like gltf?) or load your obj in blender and export a .babylon from there

Link to comment
Share on other sites

See, I made a progress, I removed the camera.maxZ = 0; That there was in the code, now the obj appears, but it is disappearing with the distance what I do to solve now?

 -edit:
Finally I managed to solve, but I had to put the value camera.maxZ = 45000; Is not that going to be a problem?

 

 

 

 
Link to comment
Share on other sites

Hey, good to hear that you solved it.  Yeah, big numbers in camera.maxZ are normal and necessary... when you have big numbers like...  camera.setPosition(new BABYLON.Vector3(7000,7000,7000));

Yesterday, I worked on your playground a bit, and had some problems getting .obj to load in playground.  Then I got too busy in my real life.

I came back this morning to do more testing... and you have it solved.  Well done!

As you noticed, forum helpers REALLY LIKE playground demos that can reproduce/show the problem. 

As a less-popular alternative, helpers like zips of the entire project... .blend files, .babylon files, html, JS, etc. 

These helper preferences might seem strict and uncaring, now... but later, when you become a forum helper... you will agree.  Playground demos that show the problem... REALLY helps the forum helpers... a lot. 

Sometimes, our over-worked forum helpers are working 5-8 issues per day, and it gets "heavy".   Sometimes, it is VERY necessary to use playgrounds... simply to help with the work-load.   BabylonJS is very popular... lots of people use it.  I hope you didn't get discouraged.

You did great, though.  You tried to get us a playground, and then you kept experimenting... and you had success.

MY best friend... is the "search in code" (right side) input box... at our playground search page.  Search for correct keywords/terms, and the searcher will nicely-help with issues and learning.  It is like having a personal BJS teacher... 24 hours per day.  I bet I have used that searcher over 500 times, so far.  I love it.  It is my buddy.  :) 

Be well, M... cya around the forum.  Please mark thread as solved if/when finished with it.  Thx.

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