mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-15 21:05:22 +01:00
fix refresh sketch problem
This commit is contained in:
parent
2a358a057d
commit
9f27fcf193
7 changed files with 50 additions and 31 deletions
|
|
@ -11,21 +11,26 @@ export class PreviewWizard extends Wizard {
|
|||
this.previewObject = null;
|
||||
this.app.viewer.workGroup.add(this.previewGroup);
|
||||
this.updatePreview();
|
||||
app.bus.subscribe('refreshSketch', this.onSketchUpdate);
|
||||
}
|
||||
|
||||
onSketchUpdate = () => {
|
||||
this.updatePreview();
|
||||
};
|
||||
|
||||
createPreviewObject() {throw 'abstract'};
|
||||
|
||||
updatePreview() {
|
||||
this.destroyPreviewObject();
|
||||
this.previewObject = this.createPreviewObject(this.app, this.readFormFields());
|
||||
if (this.previewObject != null) {
|
||||
if (this.previewObject !== null) {
|
||||
this.previewGroup.add( this.previewObject );
|
||||
}
|
||||
this.app.viewer.render();
|
||||
}
|
||||
|
||||
destroyPreviewObject() {
|
||||
if (this.previewObject != null) {
|
||||
if (this.previewObject !== null) {
|
||||
this.previewGroup.remove( this.previewObject );
|
||||
this.previewObject.geometry.dispose();
|
||||
this.previewObject = null;
|
||||
|
|
@ -38,6 +43,7 @@ export class PreviewWizard extends Wizard {
|
|||
}
|
||||
|
||||
dispose() {
|
||||
this.app.bus.unsubscribe('refreshSketch', this.onSketchUpdate);
|
||||
this.destroyPreviewObject();
|
||||
this.app.viewer.workGroup.remove(this.previewGroup);
|
||||
this.app.viewer.render();
|
||||
|
|
@ -75,17 +81,7 @@ export class SketchBasedPreviewer {
|
|||
create(app, params) {
|
||||
const face = app.findFace(params.face);
|
||||
if (!face) return null;
|
||||
const needSketchRead = !this.sketch || params.face != this.face;
|
||||
if (needSketchRead) {
|
||||
this.sketch = ReadSketchFromFace(app, face);
|
||||
//for (let polygon of this.sketch) {
|
||||
//if (!Loop.isPolygonCCWOnSurface(polygon, face.surface()) && this.fixToCCW) {
|
||||
// polygon.reverse();
|
||||
//}
|
||||
//}
|
||||
this.face = params.face;
|
||||
}
|
||||
const triangles = this.createImpl(app, params, this.sketch.fetchContours(), face);
|
||||
const triangles = this.createImpl(app, params, face.sketch.fetchContours(), face);
|
||||
return PreviewWizard.createMesh(triangles);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export class Wizard {
|
|||
this.formFields = {};
|
||||
this.box = this.createUI(opearation, metadata);
|
||||
this.overridingHistory = false;
|
||||
if (initialState != undefined) {
|
||||
if (initialState !== undefined) {
|
||||
this.setFormFields(initialState);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class SketchGeom {
|
|||
}
|
||||
|
||||
fetchContours() {
|
||||
if (this._contours == null) {
|
||||
if (this._contours === null) {
|
||||
this._contours = FetchContours(this);
|
||||
}
|
||||
return this._contours;
|
||||
|
|
@ -91,7 +91,9 @@ export function ReadSketchPoint(arr) {
|
|||
|
||||
export function ReadSketchFromFace(app, face) {
|
||||
const savedFace = localStorage.getItem(app.faceStorageKey(face.id));
|
||||
if (savedFace == null) return null;
|
||||
if (savedFace === null) {
|
||||
return null;
|
||||
}
|
||||
return ReadSketch(JSON.parse(savedFace), face.id, true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -622,12 +622,7 @@ App.prototype.findSketches = function(solid) {
|
|||
};
|
||||
|
||||
App.prototype.refreshSketchOnFace = function(sketchFace) {
|
||||
var faceStorageKey = this.faceStorageKey(sketchFace.id);
|
||||
var savedFace = localStorage.getItem(faceStorageKey);
|
||||
if (savedFace != null) {
|
||||
var geom = ReadSketch(JSON.parse(savedFace), sketchFace.id, true);
|
||||
sketchFace.syncSketches(geom);
|
||||
}
|
||||
sketchFace.updateSketch(this);
|
||||
};
|
||||
|
||||
App.prototype.save = function() {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import Counters from '../counters'
|
|||
import {Matrix3, BasisForPlane} from '../../math/l3space'
|
||||
import {isCurveClass} from '../cad-utils'
|
||||
import DPR from '../../utils/dpr'
|
||||
import {ReadSketch, ReadSketchFromFace} from "../craft/sketch/sketch-reader";
|
||||
|
||||
export class SceneSolid {
|
||||
|
||||
|
|
@ -22,6 +23,8 @@ export class SceneSolid {
|
|||
this.mergeable = true;
|
||||
this.sceneFaces = [];
|
||||
|
||||
this.sketch = null;
|
||||
|
||||
this.material = createSolidMaterial(skin);
|
||||
}
|
||||
|
||||
|
|
@ -113,8 +116,24 @@ export class SceneFace {
|
|||
threeFace.__TCAD_SceneFace = this;
|
||||
}
|
||||
|
||||
syncSketches(geom) {
|
||||
if (this.sketch3DGroup != null) {
|
||||
readSketchGeom(app) {
|
||||
let faceStorageKey = app.faceStorageKey(this.id);
|
||||
let savedFace = localStorage.getItem(faceStorageKey);
|
||||
if (savedFace === null) {
|
||||
return null;
|
||||
}
|
||||
return ReadSketch(JSON.parse(savedFace), this.id, true);
|
||||
}
|
||||
|
||||
updateSketch(app) {
|
||||
this.sketch = this.readSketchGeom(app);
|
||||
if (this.sketch !== null) {
|
||||
this.syncSketch(this.sketch);
|
||||
}
|
||||
}
|
||||
|
||||
syncSketch(geom) {
|
||||
if (this.sketch3DGroup !== null) {
|
||||
for (let i = this.sketch3DGroup.children.length - 1; i >= 0; --i) {
|
||||
this.sketch3DGroup.remove(this.sketch3DGroup.children[i]);
|
||||
}
|
||||
|
|
@ -123,10 +142,9 @@ export class SceneFace {
|
|||
this.solid.cadGroup.add(this.sketch3DGroup);
|
||||
}
|
||||
|
||||
const basis = this.basis();
|
||||
const _3dTransformation = new Matrix3().setBasis(basis);
|
||||
//we lost depth or z off in 2d sketch, calculate it again
|
||||
const depth = this.depth();
|
||||
let surface = this.surface();
|
||||
let [u, v] = surface.middle();
|
||||
const _3dTransformation = surface.tangentPlane(u, v).get3DTransformation();
|
||||
const addSketchObjects = (sketchObjects, material, close) => {
|
||||
for (let sketchObject of sketchObjects) {
|
||||
let line = new THREE.Line(undefined, material);
|
||||
|
|
@ -134,7 +152,6 @@ export class SceneFace {
|
|||
const chunks = sketchObject.approximate(10);
|
||||
function addLine(p, q) {
|
||||
const lg = line.geometry;
|
||||
chunks[p].z = chunks[q].z = depth;
|
||||
const a = _3dTransformation.apply(chunks[p]);
|
||||
const b = _3dTransformation.apply(chunks[q]);
|
||||
|
||||
|
|
@ -153,7 +170,7 @@ export class SceneFace {
|
|||
}
|
||||
|
||||
findById(sketchObjectId) {
|
||||
return this.sketch3DGroup.children.find(o => o.__TCAD_SketchObject && o.__TCAD_SketchObject.id == sketchObjectId);
|
||||
return this.sketch3DGroup.children.find(o => o.__TCAD_SketchObject && o.__TCAD_SketchObject.id === sketchObjectId);
|
||||
}
|
||||
|
||||
getSketchObjectVerticesIn3D(sketchObjectId) {
|
||||
|
|
|
|||
|
|
@ -291,6 +291,15 @@ export class NurbsSurface extends Surface {
|
|||
this.simpleSurface = simpleSurface || figureOutSimpleSurface(this);
|
||||
}
|
||||
|
||||
middle() {
|
||||
let {min: uMin, max: uMax} = this.verb.domainU();
|
||||
let {min: vMin, max: vMax} = this.verb.domainV();
|
||||
return [
|
||||
(uMax - uMin) * 0.5,
|
||||
(vMax - vMin) * 0.5
|
||||
];
|
||||
}
|
||||
|
||||
toNurbs() {
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ export class Plane extends Surface {
|
|||
if (!this.__3dTr) {
|
||||
const basis = new Matrix3().setBasis(this.basis());
|
||||
const translate = new Matrix3();
|
||||
translate.tz = this.w
|
||||
translate.tz = this.w;
|
||||
this.__3dTr = basis.combine(translate);
|
||||
// this.__3dTr.tz = this.w;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue