Alan Colon 6 năm trước cách đây
mục cha
commit
431fe81222
3 tập tin đã thay đổi với 50 bổ sung53 xóa
  1. 8 45
      src/baker.js
  2. 19 8
      src/index.js
  3. 23 0
      src/ui.js

+ 8 - 45
src/baker.js

@@ -184,53 +184,10 @@ THREE.Baker.prototype = {
               result.applyMatrix4(object.bindMatrixInverse)
 
               p.copy(result)
-              //return result.applyMatrix4 (skin.bindMatrixInverse);
-            
-              // const skinIndex = skinIndices[i]
-              // const skinWeight = skinWeights[i]
-              // skinIndex.forEach((s, j) => {
-              //   //https://stackoverflow.com/questions/31620194/how-to-calculate-transformed-skin-vertices
-              //   //result.add (temp.copy (skinVertex).applyMatrix4 (tempMatrix).multiplyScalar (skinWeights[properties[i]]));
-
-
-              //   const w = skinWeight[j]
-              //   const bone = bones[s]
-              //   if (bone) {
-              //     p.add(p.clone().applyMatrix4(bone.matrixWorld).multiplyScalar(w))
-              //   }
-              // })
             })
 
           }
           
-
-          // attributes.position is a flattened Array<Array<Vector3>>.
-          // attributes.skinIndex is a flattened Array<Array(4)<Int>>. Each is an ordinal to a bone.
-          // attributes.skinWeight is a flattened Array<Array(4)<Float>>. Each is a 0.0 - 1.0 weight for a bone.
-
-
-          // if (attributes.skinIndex) {
-          //   const skinIndex = attributes.skinIndex
-          //   const skinWeight = attributes.skinWeight
-
-          //   const bones = object.skeleton.bones
-          //   const bonesPerPosition = slices(Array.from(skinIndex.array).map(i => bones[i]), 4)
-          //   const weightsPerPosition = slices(skinWeight.array, 4)
-          //   positions.forEach((p, i) => {
-          //     const bones = bonesPerPosition[i]
-          //     const weights = weightsPerPosition[i]
-          //     bones.forEach((bone, b) => {
-          //       const weight = weights[b]
-          //       if (weight !== 0) {
-          //         const matrix = bone.matrix.clone().multiply(object.matrixWorld)
-          //         //matrix.multiplyScalar(weight)
-          //         p.applyMatrix4(matrix)
-          //       }
-          //     })
-          //   })
-          // }
-
-
           pushAll(_triangles, triangles)
 
           /* END FROM*/
@@ -238,8 +195,14 @@ THREE.Baker.prototype = {
 
       });
 
-      console.log('Triangles', triangles)
-      const stl = toStl(rotate(triangles))
+      // Finally, transform each triangle. Apply z-up rotation, and scale by 1000% percent.
+
+      const final = triangles.map(t => t.map(v =>
+        v.clone().set(v.x, -v.z, v.y).multiplyScalar(10)
+      ))
+
+      console.log('Triangles', final)
+      const stl = toStl(final)
       window.save = (filename) => console.save(stl, filename || 'export.stl')
       console.log('save([filename]) to save')
     };

+ 19 - 8
src/index.js

@@ -1,18 +1,19 @@
 const tree = require('./tree')
 const walk = require('./walk')
+require('./ui')
 
 const THREE = require('./three')
 
 window.character = window.CK && CK.characters[0].characterDisplay.threeObj
 window.character = window.character || scene.children[4]
 
-if (window.scene) {
-  var i = -6
-  scene.traverse(o => {
-    o.name = o.type + i++
-  })
-  scene.getObjectByName('Bone3').rotation.z = 32  
-}
+// if (window.scene) {
+//   var i = -6
+//   scene.traverse(o => {
+//     o.name = o.type + i++
+//   })
+//   scene.getObjectByName('Bone3').rotation.z = 32  
+// }
 
 window.bake = () => {
   const baker = new THREE.Baker();
@@ -28,4 +29,14 @@ window.save = (filename) => {
   })
 }
 
-// Your code here...
+// // Your code here...
+// CK.Settings.rez = 'hiRez'
+// CK.Settings.forge = true
+// const CKBLoader = window.FuseBox.packages.creationkit.f["creationkit/resources/loaders/CKBLoader.js"].locals.exports.default
+// const oldLoad = CKBLoader.prototype.load
+// CKBLoader.prototype.load = function() {
+//   const args = Array.from(arguments)
+//   //args[0] = args[0].split('_loRez_').join('_').split('/static/').join('/forge/static/')
+//   console.log(args)
+//   return oldLoad.apply(this, args)
+// }

+ 23 - 0
src/ui.js

@@ -0,0 +1,23 @@
+const load = () => {
+  const nav = document.querySelector('.nav')
+  if (!nav) return false
+  const temp = document.createElement('div')
+  temp.innerHTML = `
+    <a href="javascript:void(0);">
+      <img src="/static/img/icon_save_white.png" />
+      download
+    </a>
+  `
+  const link = temp.children[0]
+  nav.insertAdjacentElement('afterbegin', link)
+
+  link.addEventListener('click', () => {
+    const name = document.querySelector('#namecard').value.trim()
+    bake()
+    save(`${name}.stl`)
+  })
+}
+
+const timer = setInterval(() => {
+  if (load() !== false) clearInterval(timer)
+}, 10)