shaogen1995 9 月之前
當前提交
e274433888
共有 10 個文件被更改,包括 71885 次插入0 次删除
  1. 16 0
      index.html
  2. 96 0
      js/main.js
  3. 48830 0
      js/three.core.js
  4. 17313 0
      js/three.module.js
  5. 5630 0
      js/tinyusdz.js
  6. 二進制
      js/tinyusdz.wasm
  7. 二進制
      usdz/UsdCookie.usdz
  8. 二進制
      usdz/data.usdz
  9. 二進制
      usdz/data2.usdz
  10. 二進制
      usdz/test1.usdz

+ 16 - 0
index.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8">
+		<title>TinyUSDZ demo using three.js</title>
+		<style>
+			body { margin: 0; }
+		</style>
+	</head>
+	<body>
+		<script>
+		</script>
+
+		<script type="module" src="./js/main.js"></script>
+	</body>
+</html>

+ 96 - 0
js/main.js

@@ -0,0 +1,96 @@
+//import * as THREE from 'three';
+import * as THREE from '../js/three.module.js';
+
+import initTinyUSDZ from '../js/tinyusdz.js';
+
+const urlAll =window.location.href.split('?m=')[1]
+
+console.log(123456,urlAll);
+
+
+const USDZ_FILEPATH = `https://4dkankan.oss-cn-shenzhen.aliyuncs.com/sxz/${urlAll}.usdz`;
+
+const usd_res = await fetch(USDZ_FILEPATH);
+const usd_data = await usd_res.arrayBuffer();
+
+const usd_binary = new Uint8Array(usd_data);
+
+initTinyUSDZ().then(function(TinyUSDZLoader) {
+
+  const usd = new TinyUSDZLoader.TinyUSDZLoader(usd_binary);
+  console.log(usd.numMeshes());
+
+  const scene = new THREE.Scene();
+  const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
+
+  const renderer = new THREE.WebGLRenderer();
+  renderer.setSize( window.innerWidth, window.innerHeight );
+  renderer.setAnimationLoop( animate );
+  document.body.appendChild( renderer.domElement );
+
+  // First mesh only
+  const mesh = usd.getMesh(0);
+  //console.log("usd", usd)
+  //console.log("mesh", mesh);
+
+  //const geometry = new THREE.BoxGeometry( 1, 1, 1 );
+  const geometry = new THREE.BufferGeometry();
+  geometry.setAttribute( 'position', new THREE.BufferAttribute( mesh.points, 3 ) );
+  // TODO: set normal from mesh
+
+  if (mesh.hasOwnProperty('texcoords')) {
+    console.log(mesh.texcoords);
+    geometry.setAttribute( 'uv', new THREE.BufferAttribute( mesh.texcoords, 2 ) );
+  }
+
+  const usdMaterial = usd.getMaterial(mesh.materialId);
+  //console.log("usdMat", usdMaterial);
+  //if (usdMaterial.aaa) {
+  //  console.log("aaa");
+  //}
+
+  var material;
+
+  if (usdMaterial.hasOwnProperty('diffuseColorTextureId')) {
+    const diffTex = usd.getTexture(usdMaterial.diffuseColorTextureId);
+
+    const img = usd.getImage(diffTex.textureImageId);
+    console.log(img);
+
+    // assume RGBA for now.
+    let image8Array = new Uint8ClampedArray(img.data);
+    let imgData = new ImageData(image8Array, img.width, img.height);
+
+    const texture = new THREE.DataTexture( imgData, img.width, img.height );
+    texture.flipY = true;
+    texture.needsUpdate = true;
+    
+    material = new THREE.MeshBasicMaterial({
+      map: texture
+    });
+  } else {
+    material = new THREE.MeshNormalMaterial();
+  }
+   
+
+  // Assume triangulated indices.
+  geometry.setIndex( new THREE.Uint32BufferAttribute(mesh.faceVertexIndices, 1) );
+
+  geometry.computeVertexNormals();
+
+  //const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
+  const cube = new THREE.Mesh( geometry, material );
+  scene.add( cube );
+
+  //camera.position.z = 25;
+  camera.position.z = 1.0;
+
+  function animate() {
+
+    //cube.rotation.x += 0.01;
+    cube.rotation.y += 0.02;
+
+    renderer.render( scene, camera );
+
+  }
+});

File diff suppressed because it is too large
+ 48830 - 0
js/three.core.js


File diff suppressed because it is too large
+ 17313 - 0
js/three.module.js


File diff suppressed because it is too large
+ 5630 - 0
js/tinyusdz.js


二進制
js/tinyusdz.wasm


二進制
usdz/UsdCookie.usdz


二進制
usdz/data.usdz


二進制
usdz/data2.usdz


二進制
usdz/test1.usdz