MCPcopy
hub / github.com/sparkjsdev/spark / renderTarget

Method renderTarget

src/OldSparkViewpoint.ts:328–365  ·  view source on GitHub ↗
({
    scene,
    camera,
  }: { scene: THREE.Scene; camera?: THREE.Camera })

Source from the content-addressed store, hash-verified

326 // Swaps buffers if doubleBuffer: true was set.
327 // Calls onTextureUpdated(texture) with the resulting texture.
328 renderTarget({
329 scene,
330 camera,
331 }: { scene: THREE.Scene; camera?: THREE.Camera }) {
332 const target = this.back ?? this.target;
333 if (!target) {
334 throw new Error("Must initialize SparkViewpoint with target");
335 }
336
337 camera = camera ?? this.camera;
338 if (!camera) {
339 throw new Error("Must provide camera");
340 }
341 if (camera instanceof THREE.PerspectiveCamera) {
342 const newCam = new THREE.PerspectiveCamera().copy(camera, false);
343 newCam.aspect = target.width / target.height;
344 newCam.updateProjectionMatrix();
345 camera = newCam;
346 }
347 this.viewToWorld = camera.matrixWorld.clone();
348
349 const previousTarget = this.spark.renderer.getRenderTarget();
350 try {
351 this.spark.renderer.setRenderTarget(target);
352 this.spark.prepareViewpoint(this);
353
354 this.spark.renderer.render(scene, camera);
355 } finally {
356 this.spark.prepareViewpoint(this.spark.defaultView);
357 this.spark.renderer.setRenderTarget(previousTarget);
358 }
359
360 if (target !== this.target) {
361 // Swap back buffer and target
362 [this.target, this.back] = [this.back, this.target];
363 }
364 this.onTextureUpdated?.(target.texture);
365 }
366
367 // Read back the previously rendered target image as a Uint8Array of packed
368 // RGBA values (in that order). If superXY was set greater than 1 then

Callers 1

prepareRenderPixelsMethod · 0.95

Calls 2

prepareViewpointMethod · 0.80
renderMethod · 0.45

Tested by

no test coverage detected