Jump to content

model disappears when camera rotates, reappears when window is resized


Recommended Posts

Hi guys, 

something weird is happening. I load a model (using the glTF loader), it's showing up fine, but as soon as I rotate the arcRotateCamera, it disappears. If I resize my window, it comes back.

Edit: an additional clue, the model comes up with flipped normals so I flipped them back once the model is loaded, but the new normals only show up after I have resized the window, you can see that in the gif below.

Edit2: this doesn't happen with the OBJ loader



Any ideas?

Link to comment
Share on other sites

Interesting.  Sorry for slow replies. 

Have you got the latest gfx drivers for your "stuff"?  

And, are you seeing this same symptom in all the major browsers?

Which version of BJS, and are you running any "extra" scripts?

Can you publish, so others can browse it?  hmm.  (beard scratch)

Hey, you asked for ideas.  No mention of needing GOOD ideas.  :D

Link to comment
Share on other sites

Thanks for the suggestions! it's the same in other browsers, and refreshing the bounding box didn't fix it :(

I'm using the latest 2.5 version and the latest gltf loader.

I have a ton of other scripts, it's a pretty big project :) It might be pretty hard to isolate it into a playground example.

Any other ideas? Why would resizing the window refresh the model? Could it have something to do with the gltf loader creating a different camera, maybe?

Link to comment
Share on other sites

Ok so I'm half way there I think. Thanks @Wingnut that code helped:)

 To get the model to show, I need to do 2 things:

1. resize the window

2. rotate the camera (I guess it refreshes the view somehow?)


calling engine.setSize(x,y) after loading the file takes care of 1.

Now how do I fake a camera rotate? Is there any secret function to re-render everything? or just the camera?



Link to comment
Share on other sites

Ok, I "fixed" it, more like horrible hacked it.

I resize the engine to fake a window resize, and I use camera.setTarget to a slightly different position to fake a camera movement. Now it gets refreshed and everything looks fine.

I wonder however, what the hell is going on?! And is there a quicker way to refresh the scene maybe?

If I get a moment I'll try to make a playground for it.


Link to comment
Share on other sites

  • 2 weeks later...

Sorry for the late response. 

I tested with all new versions and the problem was still there.


HOWEVER here is what I discovered:

My scene creation code is quite big so I moved it to a separate script called sceneManager.js, there I do all my things, instantiating the engine, creating the scene, camera etc etc.

It seems to be a bad idea. I found out that removing

var canvas = document.getElementById("renderCanvas");
var engine = new BABYLON.Engine(canvas, true, { stencil: true });

from the file and putting it directly in the html page fixed the problem. This works fine:

    <canvas id="renderCanvas"></canvas>

    <!-- Babylon Files -->
    <script src="http://cdn.babylonjs.com/2-5/babylon.js"></script>
    <script src="js/babylon.objFileLoader.js"></script>
    <script src="js/babylon.glTFFileLoader.js"></script>
    <script src="js/babylon.canvas2d.js"></script>

    <!-- Init engine -->
    var canvas = document.getElementById("renderCanvas");
    var engine = new BABYLON.Engine(canvas, true, { stencil: true });

    <!-- Create scene -->
    <script src="sceneManager.js"></script> 

    <!-- plenty of other things -->


is that... expected? Can someone explain? 


Thanks :)

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.

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.


  • Recently Browsing   0 members

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