Update saver.js
This commit is contained in:
parent
a68006572e
commit
d5b183ea33
63
scr/saver.js
63
scr/saver.js
|
@ -9,8 +9,9 @@ import { finalizeMesh } from './finalizeMesh.js';
|
|||
|
||||
function save_stl() {
|
||||
var smooth = jQuery('#subdivideSLT').val() > 0 ? jQuery('#subdivideSLT').val() : undefined;
|
||||
var mirroredPose = CK.character.data.mirroredPose;
|
||||
|
||||
var group = process(CK.character, smooth);
|
||||
var group = process(CK.character, smooth, mirroredPose);
|
||||
|
||||
var exporter = new STLExporter();
|
||||
var fileString = exporter.parse(group);
|
||||
|
@ -22,9 +23,11 @@ function save_stl() {
|
|||
};
|
||||
|
||||
function save_obj() {
|
||||
var smooth = jQuery('#subdivideSLT').val();
|
||||
var smooth = jQuery('#subdivideSLT').val() > 0 ? jQuery('#subdivideSLT').val() : undefined;
|
||||
var mirroredPose = CK.character.data.mirroredPose;
|
||||
|
||||
var group = process(CK.character, smooth);
|
||||
|
||||
var group = process(CK.character, smooth, mirroredPose);
|
||||
|
||||
var exporter = new OBJExporter();
|
||||
var fileString = exporter.parse(group);
|
||||
|
@ -67,7 +70,28 @@ function subdivide(geometry, subdivisions) {
|
|||
return smoothGeometry;
|
||||
};
|
||||
|
||||
function process(object3d, smooth) {
|
||||
function mirror(geometry) {
|
||||
const tempXYZ = [0, 0, 0];
|
||||
if (geometry.index) geometry.copy(geometry.toNonIndexed());
|
||||
|
||||
for (let i = 0; i < geometry.attributes.position.array.length / 9; i++) {
|
||||
tempXYZ[0] = geometry.attributes.position.array[i * 9];
|
||||
tempXYZ[1] = geometry.attributes.position.array[i * 9 + 1];
|
||||
tempXYZ[2] = geometry.attributes.position.array[i * 9 + 2];
|
||||
|
||||
geometry.attributes.position.array[i * 9] = geometry.attributes.position.array[i * 9 + 6];
|
||||
geometry.attributes.position.array[i * 9 + 1] = geometry.attributes.position.array[i * 9 + 7];
|
||||
geometry.attributes.position.array[i * 9 + 2] = geometry.attributes.position.array[i * 9 + 8];
|
||||
|
||||
geometry.attributes.position.array[i * 9 + 6] = tempXYZ[0];
|
||||
geometry.attributes.position.array[i * 9 + 7] = tempXYZ[1];
|
||||
geometry.attributes.position.array[i * 9 + 8] = tempXYZ[2];
|
||||
}
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
function process(object3d, smooth, mirroredPose) {
|
||||
var material = new MeshBasicMaterial();
|
||||
var group = new Group();
|
||||
|
||||
|
@ -77,6 +101,10 @@ function process(object3d, smooth) {
|
|||
var exporter = new finalizeMesh();
|
||||
var geometry = exporter.parse(object);
|
||||
|
||||
if (mirroredPose == true) {
|
||||
geometry = mirror(geometry)
|
||||
}
|
||||
|
||||
if (smooth
|
||||
&& object.name != 'baseRim'
|
||||
&& object.name != 'base') {
|
||||
|
@ -94,23 +122,28 @@ function process(object3d, smooth) {
|
|||
document.body.arrive(".footer", { onceOnly: true, existing: true }, function () {
|
||||
jQuery('.headerMenu:last').remove();
|
||||
jQuery('a:contains(Log In)').remove();
|
||||
jQuery(".headerMenu-nav-item:contains(Save)").remove();
|
||||
jQuery(".headerMenu-nav-item:contains(Save)").hide();
|
||||
jQuery(".headerMenu-nav-item:contains(Share)").remove();
|
||||
jQuery(".headerMenu-nav-item:contains(Heroes)").remove();
|
||||
jQuery(".editorFooter").empty();
|
||||
jQuery("li.tab-Material").remove();
|
||||
jQuery(".footer").empty();
|
||||
|
||||
var style = { "margin-left": "20px", "font-size": "1.4em", "color": "rgba(255, 255, 255, 0.8)", "cursor": "pointer" };
|
||||
jQuery("<div/>", { class: "content-side", css: { "align-items": "center" } }).append([
|
||||
jQuery("<a />", { css: style, text: "STL" }).on("click", save_stl),
|
||||
jQuery("<a />", { css: style, text: "OBJ" }).on("click", save_obj),
|
||||
jQuery('<label />', { css: { "margin-left": "20px" }, for: 'subdivideSLT', text: 'Subdivision Passes' }),
|
||||
jQuery('<select />', { css: {"margin-left": "5px"}, id: 'subdivideSLT' })
|
||||
.append(new Option("0", 0))
|
||||
.append(new Option("1", 1))
|
||||
.append(new Option("2", 2))
|
||||
]).insertAfter('.headerMenu-container:first');
|
||||
var character_area = jQuery(".headerMenu-container").first();
|
||||
character_area.css({ "display": "flex", "justify-content": "center", "align-content": "center", "align-items": "center" });
|
||||
|
||||
var style = { "margin-left": "10px", "width": "50px" };
|
||||
|
||||
character_area
|
||||
.append(jQuery("<a />", { css: style, class: "jss7 jss9 jss10", text: "STL" }).on("click", save_stl))
|
||||
.append(jQuery("<a />", { css: style, class: "jss7 jss9 jss10", text: "OBJ" }).on("click", save_obj))
|
||||
.append(jQuery('<label />', { css: { "margin-left": "20px" }, for: 'subdivideSLT', text: 'Subdivision Passes' }))
|
||||
.append(
|
||||
jQuery('<select />', { css: { "margin-left": "5px" }, id: 'subdivideSLT' })
|
||||
.append(new Option("0", 0))
|
||||
.append(new Option("1", 1))
|
||||
.append(new Option("2", 2))
|
||||
);
|
||||
|
||||
jQuery(".headerMenu-nav-scroll:first").append([
|
||||
jQuery('<a class="headerMenu-nav-item" href="#" target="_self"><div class="headerMenu-nav-item-img"><img src="/static/svg/character-menu/save.svg" width="20"></div><div class="headerMenu-nav-item-text">Save</div></a>').on("click", save_json),
|
||||
|
|
Loading…
Reference in New Issue