Spaces:
Running
Running
Julien Chaumond
commited on
Commit
·
430db42
1
Parent(s):
9e5869b
Dog (.fbx)
Browse files- index.html +2 -0
- models/dog/lohound_1.jpg +3 -0
- models/dog/pup_lohound.dae +3 -0
- models/dog_fbx/lohound_1.jpg +3 -0
- models/dog_fbx/puppy-snapchat.fbx +3 -0
- src/index.ts +64 -5
index.html
CHANGED
|
@@ -15,6 +15,8 @@
|
|
| 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/GLTFLoader.js"></script>
|
|
|
|
|
|
|
| 18 |
<script src="node_modules/three/examples/js/loaders/ColladaLoader.js"></script>
|
| 19 |
<script src="dist/lib/Log.js"></script>
|
| 20 |
<script src="dist/post/index.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/GLTFLoader.js"></script>
|
| 18 |
+
<script src="node_modules/three/examples/js/libs/inflate.min.js"></script>
|
| 19 |
+
<script src="node_modules/three/examples/js/loaders/FBXLoader.js"></script>
|
| 20 |
<script src="node_modules/three/examples/js/loaders/ColladaLoader.js"></script>
|
| 21 |
<script src="dist/lib/Log.js"></script>
|
| 22 |
<script src="dist/post/index.js"></script>
|
models/dog/lohound_1.jpg
ADDED
|
Git LFS Details
|
models/dog/pup_lohound.dae
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:21a46c13eb056e2cdb74d8b40e52e882a1243f4ebd2014762ab6582ede84f00b
|
| 3 |
+
size 2589509
|
models/dog_fbx/lohound_1.jpg
ADDED
|
Git LFS Details
|
models/dog_fbx/puppy-snapchat.fbx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a302ec3ad7ea7f066df210db1e6579e2ca3b0807a0aad7f0014a628e6504bdd9
|
| 3 |
+
size 4740684
|
src/index.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
import * as THREE from 'three';
|
| 2 |
|
| 3 |
const scene = new THREE.Scene();
|
| 4 |
-
scene.background = new THREE.Color(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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);
|
|
@@ -14,6 +18,8 @@ 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[]> {
|
|
@@ -65,6 +71,33 @@ class Assets {
|
|
| 65 |
);
|
| 66 |
});
|
| 67 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
}
|
| 69 |
class Utils {
|
| 70 |
static boundingBox(o: THREE.Object3D): [THREE.Vector3, THREE.Vector3] {
|
|
@@ -89,13 +122,12 @@ class Utils {
|
|
| 89 |
cube.position.x = 7;
|
| 90 |
scene.add(cube);
|
| 91 |
|
|
|
|
| 92 |
{
|
| 93 |
const egg = await Assets.loadEgg();
|
| 94 |
c.log(egg);
|
| 95 |
egg.scale.setScalar(.2);
|
| 96 |
egg.rotateX(-Math.PI / 2);
|
| 97 |
-
// c.log(egg.rotation);
|
| 98 |
-
// c.log(Utils.boundingBox(egg));
|
| 99 |
const box = new THREE.BoxHelper(egg);
|
| 100 |
scene.add(box);
|
| 101 |
scene.add(egg);
|
|
@@ -115,6 +147,24 @@ class Utils {
|
|
| 115 |
const box = new THREE.BoxHelper(egg, new THREE.Color('red'));
|
| 116 |
scene.add(box);
|
| 117 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
// const geometry = new THREE.CylinderBufferGeometry( 0, 10, 30, 4, 1 );
|
| 120 |
// const material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } );
|
|
@@ -132,9 +182,18 @@ class Utils {
|
|
| 132 |
/**
|
| 133 |
* MAIN()
|
| 134 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
function render() {
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
| 138 |
}
|
| 139 |
function animate() {
|
| 140 |
requestAnimationFrame(animate);
|
|
|
|
| 1 |
import * as THREE from 'three';
|
| 2 |
|
| 3 |
const scene = new THREE.Scene();
|
| 4 |
+
scene.background = new THREE.Color(
|
| 5 |
+
// 0xcccccc
|
| 6 |
+
'white'
|
| 7 |
+
);
|
| 8 |
+
const clock = new THREE.Clock();
|
| 9 |
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 2000);
|
| 10 |
camera.position.set(0, 30, 50);
|
| 11 |
camera.lookAt(0, 3, 0);
|
|
|
|
| 18 |
document.body.appendChild(renderer.domElement);
|
| 19 |
const stats = new Stats();
|
| 20 |
document.body.appendChild(stats.dom);
|
| 21 |
+
/// Anim mixer
|
| 22 |
+
const mixers: THREE.AnimationMixer[] = [];
|
| 23 |
|
| 24 |
class Assets {
|
| 25 |
private static loadEggMtl(): Promise<THREE.Material[]> {
|
|
|
|
| 71 |
);
|
| 72 |
});
|
| 73 |
}
|
| 74 |
+
static loadDogDae(): Promise<{
|
| 75 |
+
animations: THREE.AnimationClip[];
|
| 76 |
+
scene: THREE.Group;
|
| 77 |
+
}> {
|
| 78 |
+
/// In Dae/Collada: did not manage to get
|
| 79 |
+
/// either the anims or the texture.
|
| 80 |
+
return new Promise((resolve, reject) => {
|
| 81 |
+
const loader: THREE.AnyLoader = new (<any>THREE).ColladaLoader();
|
| 82 |
+
loader.load(
|
| 83 |
+
`models/dog/pup_lohound.dae`,
|
| 84 |
+
(collada) => {
|
| 85 |
+
resolve(collada);
|
| 86 |
+
}
|
| 87 |
+
);
|
| 88 |
+
});
|
| 89 |
+
}
|
| 90 |
+
static loadDogFbx(): Promise<THREE.Group> {
|
| 91 |
+
return new Promise((resolve, reject) => {
|
| 92 |
+
const loader: THREE.AnyLoader = new (<any>THREE).FBXLoader();
|
| 93 |
+
loader.load(
|
| 94 |
+
`models/dog_fbx/puppy-snapchat.fbx`,
|
| 95 |
+
(fbx) => {
|
| 96 |
+
resolve(fbx);
|
| 97 |
+
}
|
| 98 |
+
);
|
| 99 |
+
});
|
| 100 |
+
}
|
| 101 |
}
|
| 102 |
class Utils {
|
| 103 |
static boundingBox(o: THREE.Object3D): [THREE.Vector3, THREE.Vector3] {
|
|
|
|
| 122 |
cube.position.x = 7;
|
| 123 |
scene.add(cube);
|
| 124 |
|
| 125 |
+
|
| 126 |
{
|
| 127 |
const egg = await Assets.loadEgg();
|
| 128 |
c.log(egg);
|
| 129 |
egg.scale.setScalar(.2);
|
| 130 |
egg.rotateX(-Math.PI / 2);
|
|
|
|
|
|
|
| 131 |
const box = new THREE.BoxHelper(egg);
|
| 132 |
scene.add(box);
|
| 133 |
scene.add(egg);
|
|
|
|
| 147 |
const box = new THREE.BoxHelper(egg, new THREE.Color('red'));
|
| 148 |
scene.add(box);
|
| 149 |
}
|
| 150 |
+
{
|
| 151 |
+
////// dog_fbx
|
| 152 |
+
const dog = await Assets.loadDogFbx();
|
| 153 |
+
// c.log((<any>dog).animations);
|
| 154 |
+
const mixer = new THREE.AnimationMixer(dog);
|
| 155 |
+
const clip: THREE.AnimationClip = (<any>dog).animations.find(clip => clip.name === "lohound|lohoundAction");
|
| 156 |
+
/// ^^ this is the main parent animation! Do not play all children.
|
| 157 |
+
c.log(clip);
|
| 158 |
+
mixer.clipAction(clip).play();
|
| 159 |
+
mixers.push(mixer);
|
| 160 |
+
const container = new THREE.Group();
|
| 161 |
+
container.add(dog);
|
| 162 |
+
container.scale.setScalar(0.007); /// <- scale a container, not the dog itself or it'll fuck the anims.
|
| 163 |
+
container.position.x = 12;
|
| 164 |
+
scene.add(container);
|
| 165 |
+
const box = new THREE.BoxHelper(container, new THREE.Color('green'));
|
| 166 |
+
scene.add(box);
|
| 167 |
+
}
|
| 168 |
|
| 169 |
// const geometry = new THREE.CylinderBufferGeometry( 0, 10, 30, 4, 1 );
|
| 170 |
// const material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } );
|
|
|
|
| 182 |
/**
|
| 183 |
* MAIN()
|
| 184 |
*/
|
| 185 |
+
window.addEventListener('resize', onWindowResize, false);
|
| 186 |
+
function onWindowResize() {
|
| 187 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 188 |
+
camera.updateProjectionMatrix();
|
| 189 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 190 |
+
}
|
| 191 |
function render() {
|
| 192 |
+
const delta = clock.getDelta();
|
| 193 |
+
for (const mixer of mixers) {
|
| 194 |
+
mixer.update(delta);
|
| 195 |
+
}
|
| 196 |
+
renderer.render(scene, camera);
|
| 197 |
}
|
| 198 |
function animate() {
|
| 199 |
requestAnimationFrame(animate);
|