Spaces:
Running
Running
Julien Chaumond
commited on
Commit
•
11526b7
1
Parent(s):
18a9c33
Egg (.obj)
Browse files
index.html
CHANGED
@@ -11,6 +11,9 @@
|
|
11 |
<body>
|
12 |
<script src="node_modules/three/build/three.js"></script>
|
13 |
<script src="node_modules/three/examples/js/libs/stats.min.js"></script>
|
|
|
|
|
|
|
14 |
<script src="node_modules/three/examples/js/loaders/ColladaLoader.js"></script>
|
15 |
<script src="dist/lib/Log.js"></script>
|
16 |
<script src="dist/post/index.js"></script>
|
|
|
11 |
<body>
|
12 |
<script src="node_modules/three/build/three.js"></script>
|
13 |
<script src="node_modules/three/examples/js/libs/stats.min.js"></script>
|
14 |
+
<script src="node_modules/three/examples/js/controls/OrbitControls.js"></script>
|
15 |
+
<script src="node_modules/three/examples/js/loaders/MTLLoader.js"></script>
|
16 |
+
<script src="node_modules/three/examples/js/loaders/OBJLoader.js"></script>
|
17 |
<script src="node_modules/three/examples/js/loaders/ColladaLoader.js"></script>
|
18 |
<script src="dist/lib/Log.js"></script>
|
19 |
<script src="dist/post/index.js"></script>
|
models/Egg_from_Poly_uovo/90c98926-2b28-4206-938c-2b03459c3001.jpg
ADDED
Git LFS Details
|
models/Egg_from_Poly_uovo/Egg from Poly uovo.mtl
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
newmtl Material 1_8a9546e2-32fb-4748-bc82-8f1719e9b8d5
|
2 |
+
Kd 0.816 0.816 0.816
|
3 |
+
d 1.000
|
4 |
+
map_Kd .\90c98926-2b28-4206-938c-2b03459c3001.jpg
|
5 |
+
newmtl CallKit-IconMask material_dec543aa-4780-4304-aeba-27252f2aee99
|
6 |
+
Kd 0.000 0.000 0.000
|
7 |
+
d 1.000
|
models/Egg_from_Poly_uovo/Egg from Poly uovo.obj
ADDED
The diff for this file is too large to render.
See raw diff
|
|
src/index.ts
CHANGED
@@ -1,3 +1,123 @@
|
|
1 |
import * as THREE from 'three';
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import * as THREE from 'three';
|
2 |
|
3 |
+
const scene = new THREE.Scene();
|
4 |
+
scene.background = new THREE.Color(0xcccccc);
|
5 |
+
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 2000);
|
6 |
+
camera.position.set(0, 30, 50);
|
7 |
+
camera.lookAt(0, 3, 0);
|
8 |
+
const controls = new (<any>THREE).OrbitControls(camera);
|
9 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 1);
|
10 |
+
scene.add(ambientLight);
|
11 |
+
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
12 |
+
renderer.setPixelRatio(window.devicePixelRatio);
|
13 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
14 |
+
document.body.appendChild(renderer.domElement);
|
15 |
+
const stats = new Stats();
|
16 |
+
document.body.appendChild(stats.dom);
|
17 |
+
|
18 |
+
class Assets {
|
19 |
+
private static loadEggMtl(): Promise<THREE.Material[]> {
|
20 |
+
return new Promise((resolve, reject) => {
|
21 |
+
const loader: THREE.AnyLoader = new (<any>THREE).MTLLoader();
|
22 |
+
loader.load(
|
23 |
+
`models/Egg_from_Poly_uovo/Egg from Poly uovo.mtl`,
|
24 |
+
(materials) => {
|
25 |
+
materials.preload();
|
26 |
+
resolve(materials);
|
27 |
+
},
|
28 |
+
(xhr) => {},
|
29 |
+
reject
|
30 |
+
);
|
31 |
+
});
|
32 |
+
}
|
33 |
+
private static loadEggObj(materials: THREE.Material[]): Promise<THREE.Object3D> {
|
34 |
+
return new Promise((resolve, reject) => {
|
35 |
+
const loader: THREE.AnyLoader = new (<any>THREE).OBJLoader();
|
36 |
+
(<any>loader).setMaterials(materials);
|
37 |
+
loader.load(
|
38 |
+
`models/Egg_from_Poly_uovo/Egg from Poly uovo.obj`,
|
39 |
+
(object: THREE.Object3D) => {
|
40 |
+
resolve(object);
|
41 |
+
},
|
42 |
+
(xhr) => {
|
43 |
+
// c.log(`${ xhr.loaded / xhr.total * 100 }% loaded`);
|
44 |
+
},
|
45 |
+
(error) => {
|
46 |
+
c.error(error);
|
47 |
+
reject(error);
|
48 |
+
}
|
49 |
+
);
|
50 |
+
});
|
51 |
+
}
|
52 |
+
static async loadEgg(): Promise<THREE.Object3D> {
|
53 |
+
const materialCreator = await this.loadEggMtl();
|
54 |
+
return this.loadEggObj(materialCreator);
|
55 |
+
}
|
56 |
+
}
|
57 |
+
class Utils {
|
58 |
+
static boundingBox(o: THREE.Object3D): [THREE.Vector3, THREE.Vector3] {
|
59 |
+
const bbox = new THREE.Box3().setFromObject(o);
|
60 |
+
/// vv Just unpack it for easier console logging.
|
61 |
+
return [bbox.min, bbox.max];
|
62 |
+
}
|
63 |
+
}
|
64 |
+
(async () => {
|
65 |
+
/**
|
66 |
+
* scene construction
|
67 |
+
*/
|
68 |
+
const gridHelper = new THREE.GridHelper(100, 100);
|
69 |
+
scene.add(gridHelper);
|
70 |
+
const axesHelper = new THREE.AxesHelper(50);
|
71 |
+
scene.add(axesHelper);
|
72 |
+
|
73 |
+
const cube = new THREE.Mesh(
|
74 |
+
new THREE.BoxGeometry(1, 1, 1),
|
75 |
+
new THREE.MeshBasicMaterial({ color: 0x00ff00 })
|
76 |
+
);
|
77 |
+
cube.position.x = 7;
|
78 |
+
scene.add(cube);
|
79 |
+
|
80 |
+
{
|
81 |
+
const egg = await Assets.loadEgg();
|
82 |
+
c.log(egg);
|
83 |
+
egg.scale.setScalar(.2);
|
84 |
+
egg.rotateX(-Math.PI / 2);
|
85 |
+
// c.log(egg.rotation);
|
86 |
+
// c.log(Utils.boundingBox(egg));
|
87 |
+
const box = new THREE.BoxHelper(egg);
|
88 |
+
scene.add(box);
|
89 |
+
scene.add(egg);
|
90 |
+
///// Manually set the material, for fun.
|
91 |
+
// const eggFace = egg.getObjectByName("CallKit-IconMask") as THREE.Mesh;
|
92 |
+
// c.log(eggFace.material);
|
93 |
+
// (<THREE.MeshPhongMaterial>(eggFace.material)).color.set(0x000000);
|
94 |
+
}
|
95 |
+
|
96 |
+
|
97 |
+
// const geometry = new THREE.CylinderBufferGeometry( 0, 10, 30, 4, 1 );
|
98 |
+
// const material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } );
|
99 |
+
// for ( let i = 0; i < 500; i ++ ) {
|
100 |
+
// const mesh = new THREE.Mesh( geometry, material );
|
101 |
+
// mesh.position.x = Math.random() * 1600 - 800;
|
102 |
+
// mesh.position.y = 0;
|
103 |
+
// mesh.position.z = Math.random() * 1600 - 800;
|
104 |
+
// mesh.updateMatrix();
|
105 |
+
// mesh.matrixAutoUpdate = false;
|
106 |
+
// scene.add( mesh );
|
107 |
+
// }
|
108 |
+
})();
|
109 |
+
|
110 |
+
/**
|
111 |
+
* MAIN()
|
112 |
+
*/
|
113 |
+
function render() {
|
114 |
+
// const delta = clock.getDelta();
|
115 |
+
renderer.render( scene, camera );
|
116 |
+
}
|
117 |
+
function animate() {
|
118 |
+
requestAnimationFrame(animate);
|
119 |
+
render();
|
120 |
+
stats.update();
|
121 |
+
}
|
122 |
+
animate();
|
123 |
+
|
src/types.d.ts
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
declare const Stats: any;
|
3 |
+
|
supervisor.sh
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
#!/bin/bash
|
2 |
|
|
|
3 |
fswatch -o dist/*.js | xargs -n 1 './post-compile.sh' &
|
4 |
php -S localhost:8000
|
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
+
./post-compile.sh
|
4 |
fswatch -o dist/*.js | xargs -n 1 './post-compile.sh' &
|
5 |
php -S localhost:8000
|