-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
113 lines (94 loc) · 3.58 KB
/
index.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
document.documentElement.style.height = '100%'
const clay = require('claygl')
const ClayAdvancedRenderer = require('./claygl-advanced-renderer')
document.body.style.height = '100%'
document.body.style.margin = '0'
var canvas = document.createElement('canvas')
canvas.style.width = '100%'
canvas.style.height = '100%'
canvas.id = 'viewport'
document.body.appendChild(canvas)
const panoramaUrl = '../assets/Pisa/pisa.hdr'
var app = clay.application.create('#viewport', {
// Auto render should be disabled when using ClayAdvancedRenderer
autoRender: false,
init: function (app) {
// Create camera
this._camera = app.createCamera([0.482, 0.258, 0.836], [0, 0, 0]);
this._camera.fov = 0.8 / Math.PI * 180
this._camera.updateProjectionMatrix()
this._advancedRenderer = new ClayAdvancedRenderer(app.renderer, app.scene, app.timeline, {
shadow: true,
temporalSuperSampling: {
enable: true
},
postEffect: {
enable: true,
bloom: {
enable: false
},
screenSpaceAmbientOcclusion: {
temporalFilter: true,
enable: true,
intensity: 1,
radius: 0.5
},
FXAA: {
enable: true
}
}
});
// Create light
// app.createDirectionalLight([-1, -1, -1]);
// Use orbit control
this._control = new clay.plugin.OrbitControl({
// The target or orbit control. Usually is a camera.
target: this._camera,
// The HTMLDomElement where we need to addEventListener.
domElement: app.container
});
this._control.on('update', function () {
this._advancedRenderer.render();
}, this);
app.createAmbientCubemapLight(panoramaUrl, 1, 1, 0)//0.009125);
var cubemap = new clay.TextureCube();
app.loadTexture(panoramaUrl, {
flipY: false,
exposure: 0
}).then(function (panoramaTexture) {
// Convert panorama to a cubemap
clay.util.texture.panoramaToCubeMap(app.renderer, panoramaTexture, cubemap);
var skybox = new clay.plugin.Skybox({
// Attach skybox to the scene.
scene: app.scene,
// Use the cubemap as environment
environmentMap: cubemap
});
}).catch((e) => console.log(e));
var xAxis = app.createCube({ color: 'red' });
// looks like cube is -1, 1, not 0.5, 0.5 so we scale by 2 not 4
xAxis.scale.x = 0.4 / 2
xAxis.scale.y = 0.003 / 2
xAxis.scale.z = 0.003 / 2
xAxis.position.x = 0.2;
var yAxis = app.createCube({ color: 'green' });
yAxis.scale.x = 0.003 / 2
yAxis.scale.y = 0.4 / 2
yAxis.scale.z = 0.003 / 2
yAxis.position.y = 0.2;
var zAxis = app.createCube({ color: 'blue' });
zAxis.scale.x = 0.003 / 2
zAxis.scale.y = 0.003 / 2
zAxis.scale.z = 0.4 / 2
zAxis.position.z = 0.2;
this._advancedRenderer.render();
// Load model. return a load promise to make sure the look will be start after model loaded.
return app.loadModel('../assets/FlightHelmet/glTF/FlightHelmet.gltf').then(function (scene) {
// scene.meshes.forEach((m) => m.material.set('environmentMap', cubemap))
}).catch((e) => console.log(e))
},
loop: function (app) {
// Control status must be updated each frame.
this._control.update(app.frameTime);
}
});