minexew Posted April 10, 2016 Share Posted April 10, 2016 Hello, I've started porting my PlayCanvas-based project to BABYLON.js, but I seem to be stuck on a fairly basic thing - I cannot figure how to convince the engine that in my scene, the up axis is not Y, but Z. Basically I'm looking for the BABYLON equivalent of the following code: var camera = new pc.Entity(); g_camera = camera.addComponent("camera", { clearColor: new pc.Color(zoneData.bgColor[0], zoneData.bgColor[1], zoneData.bgColor[2]) }); app.root.addChild(camera); var cameraDist = 10; // look at [0 0 0] from [-1 -1 1]*cameraDist to get a Diablo-style view // [0 0 1] points up var camVec = new pc.Vec3(-1, -1, 1); camVec.scale(cameraDist / camVec.length()); var camLookAt = pc.Vec3.ZERO; var camUp = new pc.Vec3(1, 1, 1); camUp.normalize(); camera.setPosition(camVec); camera.lookAt(camLookAt, camUp); // later on - translate camera to follow the player camera.setPosition(camVec.clone().add(self.playerEntity.getPosition())); I wouldn't mind using ArcRotateCamera if I can get it to work. I tried setting camera.upVector, but that just ended up distorting the view. Then I tried the following dirty hack, but that didn't do the job either (no errors, but nothing is displayed) (<any>camera)._camMatrix = BABYLON.Matrix.Zero(); BABYLON.Matrix.LookAtLHToRef(camVec, camLookAt, camUp, (<any> camera)._camMatrix); Thanks for any help. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 10, 2016 Share Posted April 10, 2016 Hello and welcome, can you provide a sample repro case on the playground. Setting up camera.upVector should work Quote Link to comment Share on other sites More sharing options...
minexew Posted April 10, 2016 Author Share Posted April 10, 2016 Indeed, seems to work in the playground (except for mouse control, but that's not important for me). I'll re-check my code. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 10, 2016 Share Posted April 10, 2016 I love when a plan comes together Quote Link to comment Share on other sites More sharing options...
minexew Posted April 10, 2016 Author Share Posted April 10, 2016 Part of what I had done wrong was setting upVector to the "correct" [1 1 1].normalize() instead of simply [0 0 1]. However, as you can see in the playground I linked, the view is still not quite correct - it's shifted the right and looks slightly tilted. What would be the right way to fix that? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 10, 2016 Share Posted April 10, 2016 I know. THe best option by far would be to keep upAxis unchanged and just rotate your models after loading them. Babylonjs is left handed, Y up. Quote Link to comment Share on other sites More sharing options...
minexew Posted April 10, 2016 Author Share Posted April 10, 2016 Well crap, thought I wasn't asking that much. Chaging to Y-up would mean not only rotating all the models, but also their placement, and also all logic dealing with entities' position, rotation and so on. The codebase is not that small. Is it possible to transform the entire world except the camera? That would do without changing everything. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted April 10, 2016 Share Posted April 10, 2016 Maybe you could place all your Mesh under one node used only for its transform moving from Y to Z up ? I guess your pivot Matrix could look like this: 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 Quote Link to comment Share on other sites More sharing options...
minexew Posted April 10, 2016 Author Share Posted April 10, 2016 That was the first thing I tried to do. Lights seem to ignore the transformation though - see http://www.babylonjs-playground.com/#QQJSV#1 What options do I have left? Would implementing my own Camera work? Quote Link to comment Share on other sites More sharing options...
Sebavan Posted April 10, 2016 Share Posted April 10, 2016 Seems to work with directional light :-) http://www.babylonjs-playground.com/#QQJSV#2 well lit on z up. Hemispheric Light define their direction in world space directly. so basically, as long as you correct hemispheric light maunallly (and probably a few other bits) it should be ok. Quote Link to comment Share on other sites More sharing options...
minexew Posted April 10, 2016 Author Share Posted April 10, 2016 I ended up copying ArcRotateCamera, throwing most of the guts away and fixing what I needed. Seems to work good enough so far. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
dbawel Posted April 11, 2016 Share Posted April 11, 2016 @minexew, Could it be that you exported from a Z axis up application? Perhaps take a look at the last post I wrote on the link below - bottom of the page: DB Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 11, 2016 Share Posted April 11, 2016 @minexew: I'm interested by what you changed in the ArcRotateCamera. Perhaps we can integrate your changes? Quote Link to comment Share on other sites More sharing options...
minexew Posted April 18, 2016 Author Share Posted April 18, 2016 On 4/11/2016 at 7:56 AM, dbawel said: @minexew, Could it be that you exported from a Z axis up application? All our assets, as well as the server software, are built as Z-up. I intend to keep it that way, not just because the work involved in changing everything, but because Z-up is really the only system that makes sense to me in any non-trivial 3D world. On 4/11/2016 at 11:20 PM, Deltakosh said: @minexew: I'm interested by what you changed in the ArcRotateCamera. Perhaps we can integrate your changes? I did it in a rather hacky way, implementing only the absolute minimum needed. However, if you're interesting in merging this, I can look into developing a proper patch. Thanks for all the help. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 19, 2016 Share Posted April 19, 2016 No worry, I understand I'm happy as long as it works for you, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.