Take a screenshot from the current scene and return a Texture. This can be applied to a surface in 3D space.
Provide { type: "texture" } to get a texture instead of a data url.
The texture of the screenshot. Returns null if the screenshot could not be taken.
// Create a texture from the current view
const screenshotTexture = screenshot2({ type: "texture", width: 512, height: 512 });
if (screenshotTexture) {
myMaterial.map = screenshotTexture;
myMaterial.needsUpdate = true;
}
// Update an existing texture
const existingTexture = new Texture();
screenshot2({ type: "texture", target: existingTexture, transparent: true });
Take a screenshot from the current scene and return a data URL string.
Screenshot options. All properties are optional.
The data URL of the screenshot (e.g., "data:image/png;base64,..."). Returns null if the screenshot could not be taken.
// Take a simple screenshot with default settings
const dataUrl = screenshot2({});
console.log(dataUrl); // "data:image/webp;base64,..."
const dataUrl = screenshot2({
width: 2048,
height: 2048,
mimeType: "image/png",
transparent: true,
trim: true, // Remove transparent edges
});
import { Color } from "three";
const dataUrl = screenshot2({
width: 1024,
height: 1024,
background: new Color(0x00ff00), // Green background
});
screenshot2({
width: 1920,
height: 1080,
mimeType: "image/jpeg",
download_filename: "my-scene.jpg",
});
Take a screenshot asynchronously and return a Blob. This is useful when you need to process or upload the image data.
Set { type: "blob" } to get a blob instead of a data url. All other ScreenshotOptions are also available.
A Promise that resolves with the Blob of the screenshot. Returns null if the screenshot could not be taken.
Take a screenshot and share it using the Web Share API (mobile-friendly).
Note: The Web Share API is only available in secure contexts (HTTPS) and may not be supported on all platforms/browsers.
Set { type: "share" } to share the screenshot. Additional options like filename, title, text, and url can be provided.
A Promise that resolves with an object containing the blob and whether it was successfully shared.
const result = await screenshot2({
type: "share",
filename: "my-creation.png",
title: "Check out my 3D scene!",
text: "I created this with Needle Engine",
url: "https://engine.needle.tools",
mimeType: "image/png",
});
if (result.shared) {
console.log("Screenshot shared successfully!");
} else {
console.log("User cancelled or sharing not supported");
}
const result = await screenshot2({
type: "share",
filename: "screenshot.webp",
file_type: "image/webp",
});
if (!result.shared && result.blob) {
// Fallback: download the image instead
const url = URL.createObjectURL(result.blob);
saveImage(url, "screenshot.webp");
URL.revokeObjectURL(url);
}
Take a screenshot from the current scene with advanced options.
This is the main screenshot function in Needle Engine with support for multiple output formats:
Param: opts
Screenshot options. Use the
typeproperty to specify output format. See ScreenshotOptions for all available options.Returns
Depending on the
typeoption:typeis undefined or not specifiedtype: "texture"type: "blob"type: "share"Returns null (or Promise resolving to null) if the screenshot could not be taken.
Example: WebXR / AR Screenshots
Note for AR Screenshots: To include the device camera feed in AR screenshots, you need to request camera access. This is done automatically when you use WebARCameraBackground component in your scene. If you're not using WebARCameraBackground, you can request camera access manually:
Without camera access, AR screenshots will only show your 3D content without the real-world background.
Example: Combining multiple options
See