-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay_Car.html
153 lines (119 loc) · 4.94 KB
/
Display_Car.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Display_Car</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
overflow: hidden;
margin: 0px;
}
</style>
</head>
<body>
<div id="app"></div>
<script type="importmap">
{
"imports": {
"three": "./three.module.js",
"three/addons/": "./jsm/",
"three/addons/module_more": "./jsm/module_more"
}
}
</script>
<script type="module">
// sxdhxuvp
fetch('/models/car/car_info.json')
.then(response => response.json())
.then(release => {
console.log(release)
})
.catch(error => {
console.error('Error loading JSON:', error);
});
fetch('/models/car/release.json')
.then(response => response.json())
.then(release => {
for (let i = 0; i < release.assets.length; i++) {
if(release.assets[i].id === "sxdhxuvp") {
console.log(release.assets[i]);
}
}
})
.catch(error => {
console.error('Error loading JSON:', error);
});
import * as THREE from 'three';
import Stats from 'three/addons/stats.module.js';
import { GUI } from 'three/addons/lil-gui.module.min.js';
import { OrbitControls } from 'three/addons/OrbitControls.js';
import { EffectComposer } from "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/postprocessing/EffectComposer.js";
import { RenderPass } from "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/postprocessing/RenderPass.js";
import { UnrealBloomPass } from "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/postprocessing/UnrealBloomPass.js";
import { AfterimagePass } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/postprocessing/AfterimagePass.js';
import { GLTFLoader } from 'three/addons/GLTFLoader.js';
import { DRACOLoader } from 'three/addons/DRACOLoader.js';
import {
computeBoundsTree,
disposeBoundsTree,
acceleratedRaycast
} from "https://cdn.jsdelivr.net/npm/[email protected]/build/index.module.min.js";
import { BufferGeometryUtils } from "three/addons/module_more/BufferGeometryUtils.js";
THREE.BufferGeometry.prototype.computeBoundsTree = computeBoundsTree;
THREE.BufferGeometry.prototype.disposeBoundsTree = disposeBoundsTree;
THREE.Mesh.prototype.raycast = acceleratedRaycast;
let scene = new THREE.Scene();
let camera = new THREE.PerspectiveCamera(
60,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.set(0, 2, 3);
let renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputEncoding = THREE.sRGBEncoding;
document.getElementById("app").appendChild(renderer.domElement);
let controls = new OrbitControls(camera, renderer.domElement);
const directionalLight = new THREE.DirectionalLight(0xffffff, 5.5);
scene.add(directionalLight);
const light = new THREE.AmbientLight(0x404040,5.); // soft white light
scene.add(light);
const loader = new GLTFLoader();
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('https://www.gstatic.com/draco/v1/decoders/');
loader.setDRACOLoader(dracoLoader);
const listMesh = ["BG_SkyDome", "None", "VW_Golf_GTI_MY24_Ext","VW_Golf_GTI_MY24_Int","VW_Golf_GTI_MY24_Wheels_Richmond_19"]
for (let mm = 0; mm < listMesh.length; mm++) {
loader.load(`./models/car/${listMesh[mm]}.glb`, (gltf) => {
let meshDetail = gltf.scene;
meshDetail.traverse((mesh) => {
if (mesh.isMesh) {
let randomHexColor = Math.floor(Math.random() * 16777215).toString(16);
randomHexColor = "#" + randomHexColor.padStart(6, '0');
mesh.material = mesh.material.clone();
mesh.material.color.set(randomHexColor);
console.log(mesh.name)
// console.log(mesh)
// console.log(mesh.material.uuid)
}
});
let a = gltf.scene
let b = gltf.scene
b.position.x =10
scene.add(a);
scene.add(b);
});
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
renderer.setAnimationLoop((_) => {
renderer.render(scene, camera);
});
</script>
</body>
</html>