-
-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathhdr-loader.ts
50 lines (46 loc) · 1.42 KB
/
hdr-loader.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
/**
* @title HDR Background
* @category Scene
* @thumbnail https://mdn.alipayobjects.com/merchant_appfe/afts/img/A*28IwT4efgy8AAAAAAAAAAAAADiR2AQ/original
*/
import { OrbitControl } from "@galacean/engine-toolkit-controls";
import {
AssetType,
BackgroundMode,
Camera,
Logger,
PrimitiveMesh,
SkyBoxMaterial,
TextureCube,
Vector3,
WebGLEngine,
} from "@galacean/engine";
Logger.enable();
WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
engine.canvas.resizeByClientSize();
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();
// Create camera
const cameraNode = rootEntity.createChild("camera_node");
cameraNode.transform.position = new Vector3(-3, 0, 3);
const camera = cameraNode.addComponent(Camera);
cameraNode.addComponent(OrbitControl);
camera.fieldOfView = 65;
// Create sky
const sky = scene.background.sky;
const skyMaterial = new SkyBoxMaterial(engine);
scene.background.mode = BackgroundMode.Sky;
sky.material = skyMaterial;
sky.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);
engine.resourceManager
.load<TextureCube>({
type: AssetType.HDR,
url: "https://gw.alipayobjects.com/os/bmw-prod/b578946a-8a25-4543-8161-fa92f92ae1ac.bin",
})
.then((texture) => {
skyMaterial.texture = texture;
// HDR output is in RGBM format.
skyMaterial.textureDecodeRGBM = true;
engine.run();
});
});