Minor adjustments

This commit is contained in:
Lucas 2019-09-08 14:25:59 +01:00 committed by GitHub
parent e30e85f81b
commit 74276142fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 16 deletions

View File

@ -9,7 +9,7 @@ function init() {
RK.STLExporter.prototype = { RK.STLExporter.prototype = {
constructor: THREE.STLExporter, constructor: RK.STLExporter,
parse: ( function () { parse: ( function () {
@ -17,11 +17,17 @@ function init() {
var normalMatrixWorld = new THREE.Matrix3(); var normalMatrixWorld = new THREE.Matrix3();
return function ( scenes ) { return function ( scenes ) {
console.log(scenes); console.log(scenes);
var output = ''; var output = '';
output += 'solid exported\n'; output += 'solid exported\n';
for(var scene_nr in scenes) { for(var scene_nr in scenes) {
scenes[scene_nr].traverse( function ( object ) { scenes[scene_nr].traverse( function ( object ) {
if(object instanceof RK.Mesh){ if(object instanceof RK.Mesh){
// if object is hidden - exit // if object is hidden - exit
if(object.visible == false) return; if(object.visible == false) return;
@ -32,15 +38,16 @@ function init() {
var mesh = object; var mesh = object;
if(geometry instanceof RK.BufferGeometry){ if(geometry instanceof RK.BufferGeometry){
var oldgeometry = geometry.clone(); //Get pose from skeleton
var bufferGeometry = geometry.clone();
geometry = new RK.Geometry().fromBufferGeometry(geometry); geometry = new RK.Geometry().fromBufferGeometry(geometry);
var skinIndex = oldgeometry.getAttribute('skinIndex'); var skinIndex = bufferGeometry.getAttribute('skinIndex');
var skinWeight = oldgeometry.getAttribute('skinWeight'); var skinWeight = bufferGeometry.getAttribute('skinWeight');
var morphTarget = oldgeometry.getAttribute('morphTarget0'); var morphTarget = bufferGeometry.getAttribute('morphTarget0');
var mtcount = 0; var mtcount = 0;
while(typeof morphTarget !== 'undefined') { while(typeof morphTarget !== 'undefined') {
mtcount++; mtcount++;
morphTarget = oldgeometry.getAttribute('morphTarget' + mtcount); morphTarget = bufferGeometry.getAttribute('morphTarget' + mtcount);
} }
if(typeof skinIndex !== 'undefined') { if(typeof skinIndex !== 'undefined') {
geometry.skinIndices = []; geometry.skinIndices = [];
@ -56,9 +63,9 @@ function init() {
for(var j = 0; j < mtcount; j++) { for(var j = 0; j < mtcount; j++) {
geometry.morphTargets[j].vertices.push(( geometry.morphTargets[j].vertices.push((
new THREE.Vector3( new THREE.Vector3(
oldgeometry.getAttribute('morphTarget' + j).getX(i), bufferGeometry.getAttribute('morphTarget' + j).getX(i),
oldgeometry.getAttribute('morphTarget' + j).getY(i), bufferGeometry.getAttribute('morphTarget' + j).getY(i),
oldgeometry.getAttribute('morphTarget' + j).getZ(i) bufferGeometry.getAttribute('morphTarget' + j).getZ(i)
) )
)); ));
} }
@ -139,7 +146,7 @@ function init() {
var finalVector = new THREE.Vector4(); var finalVector = new THREE.Vector4();
if (mesh.geometry.morphTargets !== 'undefined') { if (geometry.morphTargets !== 'undefined') {
var morphVector = new THREE.Vector4(vector.x, vector.y, vector.z); var morphVector = new THREE.Vector4(vector.x, vector.y, vector.z);
@ -151,7 +158,7 @@ function init() {
} }
for (var k = 0; k < 4; k++) { for (var k = 0; k < 4; k++) {
if (geometry.morphTargets !== undefined) { if (geometry.morphTargets !== 'undefined') {
var tempVector = new THREE.Vector4(morphVector.x, morphVector.y, morphVector.z); var tempVector = new THREE.Vector4(morphVector.x, morphVector.y, morphVector.z);
} else { } else {
var tempVector = new THREE.Vector4(vector.x, vector.y, vector.z); var tempVector = new THREE.Vector4(vector.x, vector.y, vector.z);
@ -159,9 +166,8 @@ function init() {
tempVector.multiplyScalar(weights[k]); tempVector.multiplyScalar(weights[k]);
//the inverse takes the vector into local bone space //the inverse takes the vector into local bone space
tempVector.applyMatrix4(inverses[k]) //which is then transformed to the appropriate world space
//which is then transformed to the appropriate world space tempVector.applyMatrix4(inverses[k]).applyMatrix4(skinMatrices[k]);
.applyMatrix4(skinMatrices[k]);
finalVector.add(tempVector); finalVector.add(tempVector);
} }
@ -307,8 +313,8 @@ function inject_script(url, callback) {
head.appendChild(script); head.appendChild(script);
} }
inject_script("//code.jquery.com/jquery-3.3.1.min.js", function () { inject_script("//code.jquery.com/jquery-3.3.1.js", function () {
inject_script("//cdnjs.cloudflare.com/ajax/libs/three.js/100/three.js", function () { init() }) inject_script("//cdnjs.cloudflare.com/ajax/libs/three.js/108/three.js", function () { init() })
}); });
function download_stl(object){ function download_stl(object){