Update herosaver.js
This commit is contained in:
parent
fb729a90a9
commit
1010b47fc3
72
herosaver.js
72
herosaver.js
|
@ -9,7 +9,7 @@ function init() {
|
||||||
|
|
||||||
RK.STLExporter.prototype = {
|
RK.STLExporter.prototype = {
|
||||||
|
|
||||||
constructor: RK.STLExporter,
|
constructor: THREE.STLExporter,
|
||||||
|
|
||||||
parse: ( function () {
|
parse: ( function () {
|
||||||
|
|
||||||
|
@ -17,17 +17,11 @@ 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;
|
||||||
|
@ -38,37 +32,30 @@ function init() {
|
||||||
var mesh = object;
|
var mesh = object;
|
||||||
|
|
||||||
if(geometry instanceof RK.BufferGeometry){
|
if(geometry instanceof RK.BufferGeometry){
|
||||||
//Get pose from skeleton
|
var oldgeometry = geometry.clone();
|
||||||
var bufferGeometry = geometry.clone();
|
|
||||||
geometry = new RK.Geometry().fromBufferGeometry(geometry);
|
geometry = new RK.Geometry().fromBufferGeometry(geometry);
|
||||||
var skinIndex = bufferGeometry.getAttribute('skinIndex0');
|
var skinIndex = oldgeometry.getAttribute('skinIndex0');
|
||||||
var skinWeight = bufferGeometry.getAttribute('skinWeight0');
|
var skinWeight = oldgeometry.getAttribute('skinWeight0');
|
||||||
var morphTarget = bufferGeometry.getAttribute('morphTarget0');
|
var morphTarget = oldgeometry.getAttribute('morphTarget0');
|
||||||
var mtcount = 0;
|
var mtcount = 0;
|
||||||
while(typeof morphTarget !== 'undefined') {
|
while(typeof morphTarget !== 'undefined') {
|
||||||
mtcount++;
|
mtcount++;
|
||||||
morphTarget = bufferGeometry.getAttribute('morphTarget' + mtcount);
|
morphTarget = oldgeometry.getAttribute('morphTarget' + mtcount);
|
||||||
}
|
}
|
||||||
if(typeof skinIndex !== 'undefined') {
|
if(typeof skinIndex !== 'undefined') {
|
||||||
geometry.skinIndices = [];
|
geometry.skinIndices = [];
|
||||||
geometry.skinWeights = [];
|
geometry.skinWeights = [];
|
||||||
geometry.morphTargets = [];
|
//geometry.morphTargets = [];
|
||||||
for(var j = 0; j < mtcount; j++) {
|
/*for(var j = 0; j < mtcount; j++) {
|
||||||
geometry.morphTargets[j] = {};
|
geometry.morphTargets[j] = {};
|
||||||
geometry.morphTargets[j].vertices = [];
|
geometry.morphTargets[j].vertices = [];
|
||||||
}
|
}*/
|
||||||
for(var i = 0; i < geometry.vertices.length; i++) {
|
for(var i = 0; i < geometry.vertices.length; i++) {
|
||||||
geometry.skinIndices.push((new THREE.Vector4 ()).fromBufferAttribute(skinIndex,i));
|
geometry.skinIndices.push((new THREE.Vector4 ()).fromBufferAttribute(skinIndex,i));
|
||||||
geometry.skinWeights.push((new THREE.Vector4 ()).fromBufferAttribute(skinWeight,i));
|
geometry.skinWeights.push((new THREE.Vector4 ()).fromBufferAttribute(skinWeight,i));
|
||||||
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 ()).fromBufferAttribute(oldgeometry.getAttribute('morphTarget' + j)));
|
||||||
new THREE.Vector3(
|
}*/
|
||||||
bufferGeometry.getAttribute('morphTarget' + j).getX(i),
|
|
||||||
bufferGeometry.getAttribute('morphTarget' + j).getY(i),
|
|
||||||
bufferGeometry.getAttribute('morphTarget' + j).getZ(i)
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,12 +116,11 @@ function init() {
|
||||||
];
|
];
|
||||||
|
|
||||||
//this checks to see if the mesh has any morphTargets - jc
|
//this checks to see if the mesh has any morphTargets - jc
|
||||||
if (geometry.morphTargets !== 'undefined') {
|
/*if (geometry.morphTargets !== 'undefined') {
|
||||||
var morphMatricesX = [];
|
var morphMatricesX = [];
|
||||||
var morphMatricesY = [];
|
var morphMatricesY = [];
|
||||||
var morphMatricesZ = [];
|
var morphMatricesZ = [];
|
||||||
var morphMatricesInfluence = [];
|
var morphMatricesInfluence = [];
|
||||||
|
|
||||||
for (var mt = 0; mt < geometry.morphTargets.length; mt++) {
|
for (var mt = 0; mt < geometry.morphTargets.length; mt++) {
|
||||||
//collect the needed vertex info - jc
|
//collect the needed vertex info - jc
|
||||||
morphMatricesX[mt] = geometry.morphTargets[mt].vertices[vertexIndex].x;
|
morphMatricesX[mt] = geometry.morphTargets[mt].vertices[vertexIndex].x;
|
||||||
|
@ -142,32 +128,26 @@ function init() {
|
||||||
morphMatricesZ[mt] = geometry.morphTargets[mt].vertices[vertexIndex].z;
|
morphMatricesZ[mt] = geometry.morphTargets[mt].vertices[vertexIndex].z;
|
||||||
morphMatricesInfluence[mt] = mesh.morphTargetInfluences[mt];
|
morphMatricesInfluence[mt] = mesh.morphTargetInfluences[mt];
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
var finalVector = new THREE.Vector4();
|
var finalVector = new THREE.Vector4();
|
||||||
|
|
||||||
if (geometry.morphTargets !== 'undefined') {
|
/*if (mesh.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);
|
||||||
|
|
||||||
for (var mt = 0; mt < geometry.morphTargets.length; mt++) {
|
for (var mt = 0; mt < geometry.morphTargets.length; mt++) {
|
||||||
//not pretty, but it gets the job done - jc
|
//not pretty, but it gets the job done - jc
|
||||||
morphVector.lerp(new THREE.Vector4(morphMatricesX[mt], morphMatricesY[mt], morphMatricesZ[mt], 1), morphMatricesInfluence[mt]);
|
morphVector.lerp(new THREE.Vector4(morphMatricesX[mt], morphMatricesY[mt], morphMatricesZ[mt], 1), morphMatricesInfluence[mt]);
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
}
|
|
||||||
|
|
||||||
for (var k = 0; k < 4; k++) {
|
for (var k = 0; k < 4; k++) {
|
||||||
if (geometry.morphTargets !== 'undefined') {
|
|
||||||
var tempVector = new THREE.Vector4(morphVector.x, morphVector.y, morphVector.z);
|
var tempVector = new THREE.Vector4(vector.x, vector.y, vector.z);
|
||||||
} else {
|
|
||||||
var tempVector = new THREE.Vector4(vector.x, vector.y, vector.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
//which is then transformed to the appropriate world space
|
tempVector.applyMatrix4(inverses[k])
|
||||||
tempVector.applyMatrix4(inverses[k]).applyMatrix4(skinMatrices[k]);
|
//which is then transformed to the appropriate world space
|
||||||
|
.applyMatrix4(skinMatrices[k]);
|
||||||
finalVector.add(tempVector);
|
finalVector.add(tempVector);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -200,13 +180,13 @@ function init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var model = CK.character;
|
var model = CK.character;
|
||||||
var characterArea_hook = ".content-side:first";
|
var characterArea_hook = ".headerMenu-trigger-label";
|
||||||
var menu_style = {"margin-left": "20px", "font-size": "1.2em", "cursor" : "pointer" };
|
var menu_style = {"margin-left": "20px", "font-size": "1.4em", "color" : "rgba(255, 255, 255, 0.8)", "cursor" : "pointer" };
|
||||||
|
|
||||||
var character_area, stl, stl_base, sjson, ljson, labeljson;
|
var character_area, stl, stl_base, sjson, ljson, labeljson;
|
||||||
|
|
||||||
stl = jQuery("<a />").css(menu_style).text("Export Figure");
|
stl = jQuery("<a />").css(menu_style).text("Export Figure");
|
||||||
stl_base = jQuery("<a />").css(menu_style).css({"margin-left": "125px"}).text("Export Model (STL)");
|
stl_base = jQuery("<a />").css(menu_style).text("Export Model (STL)");
|
||||||
sjson = jQuery("<a />").css(menu_style).text("Export (JSON)");
|
sjson = jQuery("<a />").css(menu_style).text("Export (JSON)");
|
||||||
ljson = jQuery("<input/>").attr({"type": "file", "id": "ljson"}).css({"display":"none"}).text("Import (JSON)");
|
ljson = jQuery("<input/>").attr({"type": "file", "id": "ljson"}).css({"display":"none"}).text("Import (JSON)");
|
||||||
labeljson = jQuery("<label/>").attr({"for": "ljson"}).css(menu_style).text("Import (JSON)");
|
labeljson = jQuery("<label/>").attr({"for": "ljson"}).css(menu_style).text("Import (JSON)");
|
||||||
|
@ -313,8 +293,8 @@ function inject_script(url, callback) {
|
||||||
head.appendChild(script);
|
head.appendChild(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
inject_script("//code.jquery.com/jquery-3.3.1.js", function () {
|
inject_script("//code.jquery.com/jquery-3.3.1.min.js", function () {
|
||||||
inject_script("//cdnjs.cloudflare.com/ajax/libs/three.js/108/three.js", function () { init() })
|
inject_script("//cdnjs.cloudflare.com/ajax/libs/three.js/100/three.js", function () { init() })
|
||||||
});
|
});
|
||||||
|
|
||||||
function download_stl(object){
|
function download_stl(object){
|
||||||
|
|
Loading…
Reference in New Issue