Matthias Mullie has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/357201 )
Change subject: Fix reflected 3d thumbs
......................................................................
Fix reflected 3d thumbs
Bug: T164563
Change-Id: I4bc019afe25a3d7f1ea23c12bb08ec25f7e47eb7
---
M 3d2png.js
1 file changed, 25 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/3d2png refs/changes/01/357201/1
diff --git a/3d2png.js b/3d2png.js
index 1d99f4d..1616203 100755
--- a/3d2png.js
+++ b/3d2png.js
@@ -110,8 +110,7 @@
// Add the object to the scene
this.scene.add( object );
- // Flip the camera's up, otherwise it's upside down
- this.camera.up.set( 0, 0, -1 );
+ this.camera.up.set( 0, 0, 1 );
// Point camera at the scene
this.camera.lookAt( this.scene.position );
@@ -143,13 +142,37 @@
ctx = outputCanvas.getContext( '2d' );
imgData = ctx.createImageData( this.width, this.height );
imgData.data.set( pixels );
+
ctx.putImageData( imgData, 0, 0 );
+
+ // gl.readPixels starts reading left-bottom instead of left-top,
+ // so everything will be flipped & we need to un-flip the image
+ outputCanvas = this.flip( outputCanvas );
// Open a read stream from the canvas
return outputCanvas.pngStream();
};
/**
+ * Flips canvas over Y axis
+ * @param {Canvas} canvas
+ * @returns {Canvas}
+ */
+ThreeDtoPNG.prototype.flip = function( canvas ) {
+ var flipped = new Canvas( this.width, this.height ),
+ ctx = flipped.getContext( '2d' );
+
+ ctx.globalCompositeOperation = 'copy';
+ ctx.scale( 1, -1 ); // Y flip
+ ctx.translate( 0, -imgData.height ); // so we can draw at 0,0
+ ctx.drawImage( canvas, 0, 0 );
+ ctx.setTransform( 1, 0, 0, 1, 0, 0 );
+ ctx.globalCompositeOperation = 'source-over';
+
+ return ctx.canvas; // getImageData( 0, 0, this.width, this.height );
+};
+
+/**
* Converts a 3D model file into a PNG image
* @param {string} sourcePath Full path to the source 3D model file
* @param {string} destinationPath Full path to the destination PNG file
--
To view, visit https://gerrit.wikimedia.org/r/357201
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4bc019afe25a3d7f1ea23c12bb08ec25f7e47eb7
Gerrit-PatchSet: 1
Gerrit-Project: 3d2png
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits