@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
35 lines (27 loc) • 1.09 kB
text/typescript
import { Object3D, Texture } from 'three';
import { GLTFExporterPlugin, GLTFWriter } from 'three/examples/jsm/exporters/GLTFExporter.js';
import { Gizmos } from '../../engine_gizmos.js';
import { createFlatTexture } from '../../engine_shaders.js';
import { RGBAColor } from '../../js-extensions/index.js';
declare type BeforeWriteArgs = { keep: boolean };
export abstract class BaseWriter implements GLTFExporterPlugin {
private readonly writer: GLTFWriter;
constructor(writer: GLTFWriter) {
this.writer = writer;
}
writeNode(_node: Object3D) { }
}
export class GizmoWriter extends BaseWriter {
beforeWriteNode(node: Object3D, args: BeforeWriteArgs) {
if (Gizmos.isGizmo(node)) {
args.keep = false;
}
}
}
export class RenderTextureWriter extends BaseWriter {
beforeWriteTexture(texture: Texture, args: BeforeWriteArgs & { newTexture?: Texture }) {
if (texture.isRenderTargetTexture) {
args.newTexture = createFlatTexture(new RGBAColor(1, 1, 1, 0))
}
}
}