-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAYANEO2Window.html
155 lines (108 loc) · 5.41 KB
/
AYANEO2Window.html
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html lang="en">
<head>
<title>Machine Setting Window</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body style="margin: 0;">
<div id="container"></div>
<!--<script src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>-->
<!--<script src="./javascript/es-module-shims@1.6.3.js"></script>-->
<script src="http://local/javascript/es-module-shims@1.6.3.js"></script>
<script type="importmap">
{
"imports": {
// "three": "https://unpkg.com/three@0.148.0/build/three.module.js",
// "three/addons/": "https://unpkg.com/three@0.148.0/examples/jsm/"
// "three": "./javascript/three@0.148.0/build/three.module.js",
// "three/addons/": "./javascript/three@0.148.0/examples/jsm/",
"three": "http://local/javascript/three@0.148.0/build/three.module.js",
"three/addons/": "http://local/javascript/three@0.148.0/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import Stats from 'three/addons/libs/stats.module.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
import { TWEEN } from 'three/addons/libs/tween.module.min.js';
const container = document.getElementById('container');
const stats = new Stats();
container.appendChild(stats.dom);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputEncoding = THREE.sRGBEncoding;
container.appendChild(renderer.domElement);
const pmremGenerator = new THREE.PMREMGenerator(renderer);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff);
scene.environment = pmremGenerator.fromScene(new RoomEnvironment(), 1).texture;
const camera = new THREE.PerspectiveCamera(10, window.innerWidth / window.innerHeight, 1, 100);
camera.position.set(0, 0, 7);
const controls = new OrbitControls(camera, renderer.domElement);
controls.target.set(0, 0, 0);
controls.update();
controls.enablePan = true;
controls.enableDamping = true;
controls.enableZoom = true;
controls.autoRotate = true;
controls.rotateSpeed = 1;
const dracoLoader = new DRACOLoader();
// dracoLoader.setDecoderPath('https://unpkg.com/three@0.148.0/examples/jsm/libs/draco/');
// dracoLoader.setDecoderPath('./javascript/three@0.148.0/examples/jsm/libs/draco/');
dracoLoader.setDecoderPath('http://local/javascript/three@0.148.0/examples/jsm/libs/draco/');
const modelAddress = 'http://local/3dmodel/AYANEO2.gltf';
// const modelAddress = '3dmodel/AYANEO2.gltf';
const loader = new GLTFLoader();
loader.setDRACOLoader(dracoLoader);
loader.load(modelAddress, function (gltf) {
const model = gltf.scene;
model.name = "AYANEO2";
model.position.set(0, 0, 0);
model.scale.set(0.01, 0.01, 0.01);
scene.add(model);
animate();
}, undefined, function (e) {
console.error(e);
});
window.onresize = function () {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
};
function animate() {
requestAnimationFrame(animate);
TWEEN.update();
controls.update();
stats.update();
renderer.render(scene, camera);
}
window.chrome.webview.addEventListener('message', arg => {
const model = scene.getObjectByName('AYANEO2');
controls.autoRotate = false;
new TWEEN.Tween(camera.position).to({ x: 0, y: 0, z: 7 }, 1000).easing(TWEEN.Easing.Quartic.Out).start();
new TWEEN.Tween(controls.target).to({ x: 0, y: 0, z: 0 }, 1000).easing(TWEEN.Easing.Quartic.Out).start();
if (arg.data == "LC") {
new TWEEN.Tween(model.rotation).to({ x: Math.PI / 4, y: Math.PI / 4, z: 0 }, 1000).easing(TWEEN.Easing.Quartic.Out).start();
}
if (arg.data == "RC") {
new TWEEN.Tween(model.rotation).to({ x: Math.PI / 4, y: -Math.PI / 4, z: 0 }, 1000).easing(TWEEN.Easing.Quartic.Out).start();
}
if (arg.data == "LOGO" || arg.data == "BTD") {
new TWEEN.Tween(model.rotation).to({ x: -Math.PI / 4, y: -Math.PI / 4, z: 0 }, 1000).easing(TWEEN.Easing.Quartic.Out).start();
}
if (arg.data == "reset") {
new TWEEN.Tween(model.rotation).to({ x: 0, y: 0, z: 0 }, 1000).easing(TWEEN.Easing.Quartic.Out).start();
controls.autoRotate = true;
controls.rotateSpeed = 1;
}
animate();
});
</script>
</body>
</html>