mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 08:25:19 +01:00
debugging tools
This commit is contained in:
parent
c6c16f664d
commit
2f40461c78
9 changed files with 153 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -6,3 +6,4 @@
|
|||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
/web/app/test/viz/**
|
||||
|
|
@ -7,16 +7,21 @@ TCAD.UI = function(app) {
|
|||
var mainBox = new tk.Box();
|
||||
mainBox.root.css({height : '100%'});
|
||||
var propFolder = new tk.Folder("Solid's Properties");
|
||||
var debugFolder = new tk.Folder("Debug");
|
||||
var cameraFolder = new tk.Folder("Camera");
|
||||
var objectsFolder = new tk.Folder("Objects");
|
||||
var modificationsFolder = new tk.Folder("Modifications");
|
||||
var extrude, cut, edit, refreshSketches;
|
||||
var extrude, cut, edit, refreshSketches, printSolids, printFace, printFaceId;
|
||||
tk.add(mainBox, propFolder);
|
||||
tk.add(propFolder, extrude = new tk.Button("Extrude"));
|
||||
tk.add(propFolder, cut = new tk.Button("Cut"));
|
||||
tk.add(propFolder, edit = new tk.Button("Edit"));
|
||||
tk.add(propFolder, refreshSketches = new tk.Button("Refresh Sketches"));
|
||||
tk.add(propFolder, new tk.Text("Message"));
|
||||
tk.add(mainBox, debugFolder);
|
||||
tk.add(debugFolder, printSolids = new tk.Button("Print Solids"));
|
||||
tk.add(debugFolder, printFace = new tk.Button("Print Face"));
|
||||
tk.add(debugFolder, printFaceId = new tk.Button("Print Face ID"));
|
||||
tk.add(mainBox, cameraFolder);
|
||||
tk.add(cameraFolder, new tk.Number("x"));
|
||||
tk.add(cameraFolder, new tk.Number("y"));
|
||||
|
|
@ -106,7 +111,23 @@ TCAD.UI = function(app) {
|
|||
extrude.root.click(cutExtrude(false));
|
||||
edit.root.click(tk.methodRef(app, "sketchFace"));
|
||||
refreshSketches.root.click(tk.methodRef(app, "refreshSketches"));
|
||||
|
||||
printSolids.root.click(function () {
|
||||
app.viewer.scene.children.map(function(o) {
|
||||
if (o.geometry instanceof TCAD.Solid) {
|
||||
console.log(JSON.stringify(o.geometry.csg));
|
||||
}
|
||||
});
|
||||
});
|
||||
printFace.root.click(function () {
|
||||
var s = app.viewer.selectionMgr.selection[0];
|
||||
console.log(JSON.stringify({
|
||||
polygons : s.csgGroup.polygons,
|
||||
basis : s._basis
|
||||
}));
|
||||
});
|
||||
printFaceId.root.click(function () {
|
||||
console.log(app.viewer.selectionMgr.selection[0].id);
|
||||
});
|
||||
this.solidFolder = null;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,23 @@ TCAD.App = function() {
|
|||
window.addEventListener('storage', storage_handler, false);
|
||||
};
|
||||
|
||||
TCAD.App.prototype.findFace = function(faceId) {
|
||||
var solidId = faceId.split(":")[0];
|
||||
var children = this.viewer.scene.children;
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var obj = children[i];
|
||||
if (!!obj.geometry && obj.geometry.tCadId !== undefined) {
|
||||
for (var j = 0; j < obj.geometry.polyFaces.length; j++) {
|
||||
var face = obj.geometry.polyFaces[j];
|
||||
if (face.id == faceId) {
|
||||
return face;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
TCAD.App.prototype.faceStorageKey = function(polyFaceId) {
|
||||
return "TCAD.projects."+this.id+".sketch." + polyFaceId;
|
||||
};
|
||||
|
|
@ -101,6 +118,9 @@ TCAD.App.prototype.sketchFace = function() {
|
|||
var mid = (arc.length / 2) >> 0;
|
||||
var c = TCAD.math.circleFromPoints(arc[0], arc[mid], arc[arc.length-1]);
|
||||
if (c == null) {
|
||||
for (var i = 1; i < arc.length; i++) {
|
||||
addSegment(arc[i - 1], arc[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!TCAD.geom.isCCW([arc[0], arc[mid], arc[arc.length-1]])) {
|
||||
|
|
|
|||
|
|
@ -153,6 +153,9 @@ TCAD.utils.equal = function(v1, v2) {
|
|||
return TCAD.utils.areEqual(v1, v2, TCAD.TOLERANCE);
|
||||
};
|
||||
|
||||
TCAD.utils.strictEqual = function(a, b) {
|
||||
return a.x == b.x && a.y == b.y && a.z == b.z;
|
||||
};
|
||||
|
||||
TCAD.utils.isPointInsidePolygon = function( inPt, inPolygon ) {
|
||||
var EPSILON = TCAD.TOLERANCE;
|
||||
|
|
@ -858,7 +861,6 @@ TCAD.utils.arrFlatten1L = function(arr) {
|
|||
var result = [];
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
TCAD.utils.addAll(result, arr[i]);
|
||||
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
|
|
|||
4
web/app/test/craft-fixtures.js
Normal file
4
web/app/test/craft-fixtures.js
Normal file
File diff suppressed because one or more lines are too long
21
web/app/test/craft-scripts.js
Normal file
21
web/app/test/craft-scripts.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
function test1() {
|
||||
|
||||
var face;
|
||||
var app = window._TCAD_APP;
|
||||
face = app.findFace('0:2');
|
||||
|
||||
app.craft.modify({
|
||||
type: 'CUT',
|
||||
solids : [face.solid],
|
||||
face : face,
|
||||
params : {target : face.basis()[2].multiply(-250), expansionFactor : 2.5}
|
||||
});
|
||||
|
||||
face = app.findFace('0:4');
|
||||
app.craft.modify({
|
||||
type: 'CUT',
|
||||
solids : [face.solid],
|
||||
face : face,
|
||||
params : {target : face.basis()[2].multiply(-550), expansionFactor : 1}
|
||||
});
|
||||
}
|
||||
15
web/app/test/craft-tests.js
Normal file
15
web/app/test/craft-tests.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
require("./headless-loader.js");
|
||||
|
||||
function testReconstruct0() {
|
||||
|
||||
}
|
||||
|
||||
testReconstruct0();
|
||||
var face = face2;
|
||||
var polygons2D = face.polygons.map(csgPolyToSimple).map(polygonTransform(basisTransformation(face.basis)));
|
||||
var csgPolygons = polygons2D.map(function(p) {return new CSG.Polygon( p.map(function(v) { return new CSG.Vertex(new CSG.Vector3D(v));}) )} );
|
||||
var outline = TCAD.craft.findOutline(csgPolygons);
|
||||
|
||||
|
||||
|
||||
viz("1", polygons2D, outline);
|
||||
64
web/app/test/headless-loader.js
Normal file
64
web/app/test/headless-loader.js
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
TCAD = {};
|
||||
|
||||
require("../engine.js");
|
||||
require("../math/vector.js");
|
||||
require("../math/math.js");
|
||||
require("../workbench.js");
|
||||
require("../math/graph.js");
|
||||
require("../3d/hashmap.js");
|
||||
CSG = require("../../lib/csg.js").CSG;
|
||||
|
||||
require("./craft-fixtures.js");
|
||||
|
||||
var assert = require('assert');
|
||||
viz = function(name, polygons, segments) {
|
||||
var colors = ['aqua', 'black', 'blue', 'brown', 'crimson', 'fuchsia', 'fuschia', 'gray', 'green', 'lemon', 'lime', 'olive', 'orange', 'peach', 'pink', 'purple', 'salmon', 'tan', 'teal', 'violet', 'violet', 'blue', 'white', 'yellow'];
|
||||
var bbox = new TCAD.BBox();
|
||||
var fs = require('fs');
|
||||
var builder = require('xmlbuilder');
|
||||
var svg = builder.create('html')
|
||||
.ele('body')
|
||||
.ele('svg', {width: 800, height: 600});
|
||||
for (var pi = 0; pi < polygons.length; ++ pi) {
|
||||
var poly = polygons[pi];
|
||||
var pointsStr = "";
|
||||
for (var pointIdx = 0; pointIdx < poly.length; ++ pointIdx) {
|
||||
pointsStr += " " + poly[pointIdx].x + "," + poly[pointIdx].y;
|
||||
bbox.checkBounds(poly[pointIdx].x, poly[pointIdx].y);
|
||||
}
|
||||
svg.ele('polygon', {points: pointsStr, style:"fill:"+colors[pi % colors.length]});
|
||||
}
|
||||
for (var si = 0; si < segments.length; ++ si) {
|
||||
var s = segments[si];
|
||||
svg.ele('line', {x1 : s[0].x, y1 : s[0].y, x2 : s[1].x, y2 : s[1].y, stroke:'magenta', 'stroke-width':'2'});
|
||||
svg.ele('ellipse', {cx : s[0].x, cy : s[0].y, rx:3, ry:2, fill : "red"});
|
||||
svg.ele('ellipse', {cx : s[1].x, cy : s[1].y, rx:2, ry:3, fill : "red"});
|
||||
}
|
||||
var length = Math.max(bbox.maxX - bbox.minX, bbox.maxY - bbox.minY) + 100;
|
||||
svg.att('viewBox', (bbox.minX - 100) + " " + (bbox.minY - 100) + " " + length + " " + length)
|
||||
var htmlText = svg.end({ pretty: true});
|
||||
if (!fs.existsSync('viz')) fs.mkdirSync('viz', function(err) {});
|
||||
fs.writeFile("viz/" + name + ".html", htmlText);
|
||||
}
|
||||
|
||||
vertToPoint = function(v) {
|
||||
return {x : v.pos._x, y : v.pos._y, z : v.pos._z};
|
||||
}
|
||||
|
||||
csgPolyToSimple = function(p) {
|
||||
return p.vertices.map(vertToPoint);
|
||||
}
|
||||
|
||||
basisTransformation = function(basis) {
|
||||
var tr = new TCAD.Matrix().setBasis(basis).invert();
|
||||
return function(p) {
|
||||
return tr.apply(p);
|
||||
}
|
||||
}
|
||||
|
||||
polygonTransform = function(tr) {
|
||||
return function(polygon) {
|
||||
return polygon.map(tr);
|
||||
}
|
||||
};
|
||||
|
||||
2
web/app/test/viz.sh
Executable file
2
web/app/test/viz.sh
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
node ./craft-tests.js
|
||||
open viz/1.html
|
||||
Loading…
Reference in a new issue