Jump to content

Generate image thumbnail meshes


Dad72
 Share

Recommended Posts

Hello,

Would anyone have an idea of how to generate image thumbnail of a mesh list. 

 This is to create a list of media with a small image thumbnail preview of the objects rather than a text link (see screen). 

 I guess I should use something like CreateScreenshot but without downloading. I had idea of generating the image when the user imports the object. 

Here is my Asset library :

(Image 1 What I have to do and image 2, the result of what I want to do where we see the previews of 3d models)

asset1.jpg asset2.jpg

Link to comment
Share on other sites

Okay, actually, it's simple: :D  (I have not tested yet, but it should go with some small retouching.)

JS

var createMiniatureScreenshot = function (engine, camera, mesh) {
	var mimeType = "image/jpeg";
	var width = 128;
	var height = 128;
	var screenshotCanvas = document.createElement('canvas');
	screenshotCanvas.width = width;
	screenshotCanvas.height = height;
	camera.position.z = (camera.position.z - (mesh.getBoundingInfo().boundingBox.maximum.z + 1));
	camera.setTarget(BABYLON.Vector3.Zero());
	var renderContext = screenshotCanvas.getContext("2d");
	renderContext.drawImage(engine.getRenderingCanvas(), 0, 0, width, height);
	var base64Image = screenshotCanvas.toDataURL(mimeType);
	return base64Image;
};

More than creating the image with PHP when importing the 3D model and displaying this image in the list of media.

PHP

<?php
header('Content-Type: text/html; charset=UTF-8');
header('Content-Type: image/jpeg');
function saveImg($img, $finalDir, $nameImage) {
	$_img = str_replace('data:image/jpeg;base64,', '', $img);
	$_img = str_replace(' ', '+', $_img);
	$data = base64_decode($_img);
	$file = $finalDir.$nameImage.'.jpg';	
	file_put_contents($file, $data);	
	$image = imagecreatefromjpeg($file);
	imagejpeg($image, $file, 9);
}
$cheminFichier = "root/images/";
saveImg($_POST['imgbase64'], $cheminFichier, "myNameImage");
?>

 

Link to comment
Share on other sites

Alas, if I remember correctly, one cannot grab the image data in @Dad72's way... for it is webgl D:
And webgl is VERY annoying with taking screenshots. VERY messy and dependent on how cache and buffer and stuff is saved on the individual engines.

However, all hope is not lost. There is actually a screenshot feature from within Babylon itself. It is however very hard coded into the system. Luckily I've already dealt with it before to work on a little project: 

And here is my code! Very messy because it was stolen directly from Babylon, but it works!

http://textuploader.com/d5pky

This of course just generates the image data. Now you can do fancy cropping and scaling, then send it off to the server to actually save the image to the server, just like @Dad72 <3 

Good Luck!

Link to comment
Share on other sites

Here is code from 3JS. The same can be replicated inBJS Using DOM.

renderer.setSize( widthOfScreenshot, heightOfScreenshot ); renderer.render( scene, camera ); var screenshot = renderer.domElement.toDataURL(); renderer.setSize( originalWidth, originalHeight ); renderer.render( scene, camera );

Link to comment
Share on other sites

4 hours ago, dbawel said:

Here is code from 3JS. The same can be replicated inBJS Using DOM.

renderer.setSize( widthOfScreenshot, heightOfScreenshot ); renderer.render( scene, camera ); var screenshot = renderer.domElement.toDataURL(); renderer.setSize( originalWidth, originalHeight ); renderer.render( scene, camera );

Alas, if I remember correctly this does not work :( This is due to how Babylon does buffering and stuff ;'(

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...