sambit
sambit

Reputation: 133

How can capture an image along with logo and text in 3D canvas?

enter image description here I am new in Three js .I am showing 3d model in the canvas along with logo and text message .When I capture canvas by renderer.domElement.toDataURL('image/jpeg') .It will give me only model image and it excluded logo and text from capture image.

Please see the attached image . How can i capture 3d model along with logo and text?

<canvas height="1024" id="stageCanvas" width="1024" style="cursor: pointer"></canvas>
<div ng-class="{'preview-gif-option1': gifImageType.type == 'Option 1'}" ng-if="gifImageType.type == 'Option 1'">
  <img ng-src="{{watermarkImage}}" ng-show="watermarkImage != null" alt="" style="height:100px;width:100px" />
  <pre>{{addressInfo.value}}</pre>
</div>
  $scope.captureJpg = function() {
  renderer.render(scene, camera);
  renderer.setSize(WIDTH / 2, HEIGHT / 2);
  rotateAngle = 0;
  rotateObject(rotateAngle);
  animate();
  $scope.captureClicked = false;
  console.log(renderer.domElement.toDataURL('image/jpeg')); 
};

Upvotes: 0

Views: 1267

Answers (1)

user128511
user128511

Reputation:

3 options

  1. Put the logo in a texture, use the texture in a material, apply the material to a plane, put the plane in your scene

    const loader = new THREE.TextureLoader();
    const tex = loader.load('path/to/logo');
    const material = new THREE.MeshBasicMaterial({map: tex});
    const geo = new THREE.PlaneBufferMaterial(width, height);
    const mesh = new THREE.Mesh(geo, material);
    scene.add(mesh);
    mesh.position.set(x, y, z); // choose an appropriate position
    
  2. Create a 2D canvas, draw the three.js canvas into the 2D canvas, draw the logo image into the 2D canvas, call toDataURL on the 2D canvas

    const ctx = document.createElement('canvas').getContext('2d');
    ctx.canvas.width = widthYouWant;
    ctx.canvas.height = heightYouWant;
    ctx.drawImage(renderer.domElement, 0, 0);
    ctx.drawImage(logoImgYouAlreadyLoaded, 300, 150); // set the appropriate position
    const dataURL = ctx.canvas.toDataURL();
    
  3. Use a library for capturing HTML.

    note you will need to pass in preserveDrawingBuffer: true when creating the THREE.WebGLRenderer

Upvotes: 2

Related Questions