shawn0326 / zen-3d

JavaScript 3D library.
MIT License
196 stars 24 forks source link

Sorry disturbing again! #23

Closed VanderSP closed 2 years ago

VanderSP commented 2 years ago

Hi! I´ve stuck using zen3d at moment, because of superior performance related to threejs sky shader fps... also wider material compatibility in huge range of mobiles (threejs fails sometimes)

Im really struggling to trying to convert 3d to 2d x and y.... spent weeks already lol

Im trying to layer a div above a plane, i tried using maths to compensate screensize etc... but it works i think reasonable well for scaling, but y got wrongly, like senoidal movement lol

I´ve ran across some threejs based snippets, that uses something like:

getScreenPosition = (position, object) => {
     var vector = new zen3d.Vector3(position.x, position.y, position.z)

     // model to world
     if (object != null) {
          var modelMat = cube.matrixWorld
          vector.applyMatrix4(modelMat)
     }

     // world to view and view to NDC
     vector.project(camera)

     // NDC to pixel
     vector.x = Math.round(((vector.x + 1) * w) / 2)
     vector.y = Math.round(((-vector.y + 1) * h) / 2)

     return vector
}

but i think that in zen3d there´s no vertices exposed in geometry... please help me !!! :D because that "position" function parameter is fed with vertices from geometry on the snippet use example

VanderSP commented 2 years ago

i think better solution was layering a css3d from threejs above...