-
Notifications
You must be signed in to change notification settings - Fork 40
/
DemoHelloWorld.ts
83 lines (69 loc) · 2.27 KB
/
DemoHelloWorld.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { LumaSplatsThree } from "@lumaai/luma-web";
import { Color, DoubleSide, Mesh, MeshStandardMaterial, PlaneGeometry, Texture, Vector3 } from "three";
import { DemoProps } from ".";
export function DemoHelloWorld(props: DemoProps) {
let { renderer, camera, scene, gui } = props;
scene.background = new Color('white');
let splats = new LumaSplatsThree({
// MIT WPU Globe @krazyykrunal
source: 'https://lumalabs.ai/capture/ca9ea966-ca24-4ec1-ab0f-af665cb546ff',
// we disable full three.js for performance
enableThreeShaderIntegration: false,
// particle entrance animation
particleRevealEnabled: true,
});
scene.add(splats);
// the splats file can provide an ideal initial viewing location
splats.onInitialCameraTransform = transform => {
transform.decompose(camera.position, camera.quaternion, new Vector3());
};
scene.add(createText());
return {
dispose: () => {
// stop worker, free resources
splats.dispose();
}
}
}
// create a plane with "Hello World" text
function createText() {
// create canvas
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d')!;
canvas.width = 1024;
canvas.height = 512;
// clear white, 0 alpha
context.fillStyle = 'rgba(255, 255, 255, 0)';
context.fillRect(0, 0, canvas.width, canvas.height);
// draw text
context.fillStyle = 'white';
// 100px helvetica, arial, sans-serif
context.font = '200px sans-serif';
context.textAlign = 'center';
context.textBaseline = 'middle';
// stroke
context.strokeStyle = 'rgba(0, 0, 0, 0.5)'
context.lineWidth = 5;
context.fillText('Hello World', canvas.width / 2, canvas.height / 2);
context.strokeText('Hello World', canvas.width / 2, canvas.height / 2);
// create texture from canvas
const texture = new Texture(canvas);
texture.needsUpdate = true;
// create plane geometry and mesh with the texture
const geometry = new PlaneGeometry(5, 2.5);
const material = new MeshStandardMaterial({
map: texture,
transparent: false,
alphaTest: 0.5,
side: DoubleSide,
premultipliedAlpha: true,
emissive: 'white',
emissiveIntensity: 2,
});
const textPlane = new Mesh(geometry, material);
// position and rotate
textPlane.position.set(0.8, -0.9, 0);
textPlane.rotation.y = Math.PI / 2;
textPlane.scale.setScalar(0.6);
return textPlane;
}