@@ -438,36 +438,6 @@ <h2> Support for extended color spaces </h2>
438
438
surface . drawOnce ( drawFrame ) ;
439
439
}
440
440
441
- // Return the inverse of an SkM44. throw an error if it's not invertible
442
- function mustInvert ( m ) {
443
- const m2 = CanvasKit . SkM44 . invert ( m ) ;
444
- if ( m2 === null ) {
445
- throw "Matrix not invertible" ;
446
- }
447
- return m2 ;
448
- }
449
-
450
- // TODO(nifong): This function is in desperate need of some explanation of what it does
451
- // cam is a object having eye, coa, up, near, far, angle
452
- function saveCamera ( canvas , /* rect */ area , /* scalar */ zscale , cam ) {
453
- const camera = CanvasKit . SkM44 . lookat ( cam . eye , cam . coa , cam . up ) ;
454
- const perspective = CanvasKit . SkM44 . perspective ( cam . near , cam . far , cam . angle ) ;
455
- // Calculate viewport scale. Even through we know these values are all constants in this
456
- // example it might be handy to change the size later.
457
- const center = [ ( area . fLeft + area . fRight ) / 2 , ( area . fTop + area . fBottom ) / 2 , 0 ] ;
458
- const viewScale = [ ( area . fRight - area . fLeft ) / 2 , ( area . fBottom - area . fTop ) / 2 , zscale ] ;
459
- const viewport = CanvasKit . SkM44 . multiply (
460
- CanvasKit . SkM44 . translated ( center ) ,
461
- CanvasKit . SkM44 . scaled ( viewScale ) ) ;
462
-
463
- // want "world" to be in our big coordinates (e.g. area), so apply this inverse
464
- // as part of our "camera".
465
- canvas . concat ( CanvasKit . SkM44 . multiply ( viewport , perspective ) ) ;
466
- canvas . concat ( CanvasKit . SkM44 . multiply ( camera , mustInvert ( viewport ) ) ) ;
467
- // Mark the matrix to make it available to the shader by this name.
468
- canvas . markCTM ( 'local_to_world' ) ;
469
- }
470
-
471
441
function Camera3D ( canvas , textureImgData , normalImgData , robotoData ) {
472
442
const surface = CanvasKit . MakeCanvasSurface ( 'camera3d' ) ;
473
443
if ( ! surface ) {
@@ -618,13 +588,13 @@ <h2> Support for extended color spaces </h2>
618
588
619
589
function setClickToWorld ( canvas , matrix ) {
620
590
const l2d = canvas . getLocalToDevice ( ) ;
621
- worldToClick = CanvasKit . SkM44 . multiply ( mustInvert ( matrix ) , l2d ) ;
622
- clickToWorld = mustInvert ( worldToClick ) ;
591
+ worldToClick = CanvasKit . SkM44 . multiply ( CanvasKit . SkM44 . mustInvert ( matrix ) , l2d ) ;
592
+ clickToWorld = CanvasKit . SkM44 . mustInvert ( worldToClick ) ;
623
593
}
624
594
625
595
function drawCubeFace ( canvas , m , color ) {
626
596
const trans = new CanvasKit . SkM44 . translated ( [ vSphereRadius / 2 , vSphereRadius / 2 , 0 ] ) ;
627
- canvas . concat ( CanvasKit . SkM44 . multiply ( trans , m , mustInvert ( trans ) ) ) ;
597
+ canvas . concat ( CanvasKit . SkM44 . multiply ( trans , m , CanvasKit . SkM44 . mustInvert ( trans ) ) ) ;
628
598
const znormal = front ( canvas . getLocalToDevice ( ) ) ;
629
599
if ( znormal < 0 ) {
630
600
return ; // skip faces facing backwards
@@ -645,7 +615,10 @@ <h2> Support for extended color spaces </h2>
645
615
canvas . save ( ) ;
646
616
canvas . translate ( vSphereCenter [ 0 ] - vSphereRadius / 2 , vSphereCenter [ 1 ] - vSphereRadius / 2 ) ;
647
617
// pass surface dimensions as viewport size.
648
- saveCamera ( canvas , CanvasKit . LTRBRect ( 0 , 0 , vSphereRadius , vSphereRadius ) , vSphereRadius / 2 , cam ) ;
618
+ canvas . concat ( CanvasKit . SkM44 . setupCamera (
619
+ CanvasKit . LTRBRect ( 0 , 0 , vSphereRadius , vSphereRadius ) , vSphereRadius / 2 , cam ) ) ;
620
+ // Mark the matrix to make it available to the shader by this name.
621
+ canvas . markCTM ( 'local_to_world' ) ;
649
622
setClickToWorld ( canvas , clickM ) ;
650
623
for ( let f of faces ) {
651
624
const saveCount = canvas . getSaveCount ( ) ;
@@ -863,7 +836,8 @@ <h2> Support for extended color spaces </h2>
863
836
}
864
837
canvas . save ( ) ;
865
838
// Set up 3D view enviroment
866
- saveCamera ( canvas , CanvasKit . LTRBRect ( 0 , 0 , sizeX , sizeY ) , halfDim , cam ) ;
839
+ canvas . concat ( CanvasKit . SkM44 . setupCamera (
840
+ CanvasKit . LTRBRect ( 0 , 0 , sizeX , sizeY ) , halfDim , cam ) ) ;
867
841
868
842
// Rotate the whole paragraph as a unit.
869
843
const paraRotPoint = [ halfDim , halfDim , 1 ] ;
0 commit comments