I'm combining 3D content with Three.js with HTML and SVG content. The Three.js CSSLoader does a pretty good job synchronizing placement of HTML and SVG content in the 3D world.
But the SVG/HTML coordinate systems are 'left-handed', whereas Three.js coordinate system is 'right-handed'. This basically means that their y-axes are reversed. In SVG/HTML, y
/top
goes up as you go down the screen, and Three.js uses the more standard mathematical convention of y
going down as you go down the screen.
I have to continually convert from one to the other, which is pretty error prone. I know I am not the first to run into this (for example, look here). Has someone come up with a general solution? Here's what I tried:
Do everything in an
Object3D
with.scale.y = -1
. As you may suspect, this turns out to be a disaster. It turns everything inside-out, and don't even try to put your camera in there.Do everything in an
Object3D
with.rotate.x = Math.PI
. This is more promising, but thez
axis is no longer consistent with the HTML concept of z-index. Still, this is what I'm using now.In HTML, don't use
top
, usebottom
. In SVG, do everything inside a<g transform="scale(1, -1)">
inside a<g transform="translate(0, imageHeight)">
. However, I feel this would be more confusing for developers, and theimageHeight
has to be kept up to date at all times, which is yet another burden.
Has anyone come up with something better? Perhaps a library to help with this?