Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on three.js (use gl-css3d) #5

Closed
deathcap opened this issue Mar 27, 2014 · 3 comments · Fixed by #7
Closed

Remove dependency on three.js (use gl-css3d) #5

deathcap opened this issue Mar 27, 2014 · 3 comments · Fixed by #7

Comments

@deathcap
Copy link
Member

Remove the three.js dependency (port to stackgl for voxel-engine#ndarray). notes:


voxel-webview 0.1 uses the CSS3DRenderer effect for three.js, adding an Object3D to the scene graph then having three.js render it, and afterwards copying the computed transformation matrix then applying it to 3D CSS using transform: matrix3d(…).

With the new voxel-engine#ndarray, using the gl-modules/stackgl suite, all voxel-webview has to do is compute the appropriate transformation matrix, then apply it as 3D CSS to the HTML element, in the gl-render event handler. With WebGL, projection * view * model matrix multiplication is performed on the GU in GLSL, but we can instead do it in JavaScript before setting the CSS transform, and/or stack additional transforms (translate3d, rotate3d, etc., beyond matrix3d). voxel-shader has both a view and projection matrix; voxel-webview can supply its own model matrix.

Hooking up the voxel-shader viewMatrix to the 3D CSS transform, some progress, moves with the camera:

screen shot 2015-02-07 at 6 51 38 pm

but multiplying this.shader.projectionMatrix with this.shaderViewMatrix (in that order) is not quite right:

screen shot 2015-02-07 at 7 02 05 pm

CSS3DRenderer.js does quite a few more transforms:

  if ( object instanceof THREE.CSS3DSprite ) {

    // http://swiftcoder.wordpress.com/2008/11/25/constructing-a-billboard-matrix/

    matrix.copy( camera.matrixWorldInverse );
    matrix.transpose();
    matrix.copyPosition( object.matrixWorld );
    matrix.scale( object.scale );

    matrix.elements[ 3 ] = 0;
    matrix.elements[ 7 ] = 0;
    matrix.elements[ 11 ] = 0;
    matrix.elements[ 15 ] = 1;

    style = getObjectCSSMatrix( matrix );

and getObjectCSSMatrix negates 4,5,6th, before translate3d(-50%,-50%,0). render() sets:

var style = "translate3d(0,0," + fov + "px)" + getCameraCSSMatrix( camera.matrixWorldInverse ) +
  " translate3d(" + _widthHalf + "px," + _heightHalf + "px, 0)";

added the inverted world matrix, and translations before and after, as above, but something is off:

screen shot 2015-02-08 at 12 42 10 pm

@deathcap
Copy link
Member Author

New module working, using stackgl: https://github.com/deathcap/gl-css3d (ref GH-6, this is a more generic "3D CSS synced to WebGL" implementation). Now to integrate it back with voxel.js in voxel-webview...

@deathcap deathcap changed the title Remove dependency on three.js Remove dependency on three.js (use gl-css3d) Feb 16, 2015
@deathcap
Copy link
Member Author

screen shot 2015-02-15 at 10 12 22 pm

with gl-css3d opts.tint=[1,0,0,0]. Fixed disabling blending in deathcap/gl-css3d@e7969da:

screen shot 2015-02-15 at 10 08 58 pm

and with no tint:

screen shot 2015-02-15 at 10 10 20 pm

shows up (though lower than before, have to dig a few blocks into the ground to see), but for some reason, only one side renders and it is inverted (unlike the http://deathcap.github.io/gl-css3d/ demo - different camera parameters?)

@deathcap
Copy link
Member Author

on stackgl branch:

screen shot 2015-02-15 at 10 31 22 pm

shifted lower into the ground than the three.js version (which sat on top of it), but that was never configurable (though see some ideas in GH-3 for crafting a 'web view' block which can be placed and have voxel-webview render on top of it), and this (Google Chrome?) bug makes it cut in and out when the player moves around: deathcap/gl-css3d#3 - but at least it is usable

deathcap added a commit that referenced this issue Feb 16, 2015
Use gl-css3d/stackgl to replace dependency on three.js, closes GH-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant