mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-09 09:52:34 +01:00
render sketch primitive in 3d as ScalableLine
This commit is contained in:
parent
7037d3224c
commit
10f9a1fd86
6 changed files with 63 additions and 89 deletions
|
|
@ -11,12 +11,22 @@ export function createGroup() {
|
|||
return new THREE.Object3D();
|
||||
}
|
||||
|
||||
export function emptyGroup(group) {
|
||||
while (group.children.length) {
|
||||
group.remove(group.children[0]);
|
||||
}
|
||||
}
|
||||
|
||||
export function clearGroup(group) {
|
||||
while (group.children.length) {
|
||||
const o = group.children[0];
|
||||
clearGroup(o);
|
||||
o.material.dispose();
|
||||
o.geometry.dispose();
|
||||
if (o.material) {
|
||||
o.material.dispose();
|
||||
}
|
||||
if (o.geometry) {
|
||||
o.geometry.dispose();
|
||||
}
|
||||
group.remove(o);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ export function activate(context) {
|
|||
let pickResults = services.viewer.raycast(event, services.cadScene.workGroup.children);
|
||||
const pickers = [
|
||||
(pickResult) => {
|
||||
if (mask.is(kind, PICK_KIND.SKETCH) && pickResult.object instanceof THREE.Line) {
|
||||
if (mask.is(kind, PICK_KIND.SKETCH)) {
|
||||
let sketchObjectV = getAttribute(pickResult.object, SKETCH_OBJECT);
|
||||
if (sketchObjectV) {
|
||||
return !visitor(sketchObjectV.model, event);
|
||||
|
|
|
|||
37
web/app/cad/scene/views/curveBasedView.js
Normal file
37
web/app/cad/scene/views/curveBasedView.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import {View} from './view';
|
||||
import * as SceneGraph from 'scene/sceneGraph';
|
||||
import {setAttribute} from 'scene/objectData';
|
||||
import ScalableLine from 'scene/objects/scalableLine';
|
||||
|
||||
export class CurveBasedView extends View {
|
||||
constructor(model, tessellation, visualWidth, markerWidth, color, defaultMarkColor) {
|
||||
super(model);
|
||||
this.rootGroup = SceneGraph.createGroup();
|
||||
this.representation = new ScalableLine(tessellation, visualWidth, color, undefined, false, true);
|
||||
this.marker = new ScalableLine(tessellation, markerWidth, defaultMarkColor, undefined, false, true);
|
||||
this.picker = new ScalableLine(tessellation, 10, 0xFA8072, undefined, false, true);
|
||||
this.marker.visible = false;
|
||||
this.picker.material.visible = false;
|
||||
|
||||
setAttribute(this.representation, model.TYPE, this);
|
||||
setAttribute(this.picker, model.TYPE, this);
|
||||
|
||||
this.rootGroup.add(this.representation);
|
||||
this.rootGroup.add(this.marker);
|
||||
this.rootGroup.add(this.picker);
|
||||
}
|
||||
|
||||
mark(color) {
|
||||
this.marker.visible = true;
|
||||
}
|
||||
|
||||
withdraw(color) {
|
||||
this.marker.visible = false;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.representation.dispose();
|
||||
this.marker.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +1,10 @@
|
|||
import {View} from './view';
|
||||
import {setAttribute} from '../../../../../modules/scene/objectData';
|
||||
import * as SceneGraph from '../../../../../modules/scene/sceneGraph';
|
||||
import {EDGE} from '../entites';
|
||||
import ScalableLine from '../../../../../modules/scene/objects/scalableLine';
|
||||
import {CurveBasedView} from './curveBasedView';
|
||||
|
||||
export class EdgeView extends View {
|
||||
export class EdgeView extends CurveBasedView {
|
||||
|
||||
constructor(edge) {
|
||||
super(edge);
|
||||
this.rootGroup = SceneGraph.createGroup();
|
||||
|
||||
let brepEdge = edge.brepEdge;
|
||||
let tesselation = brepEdge.data.tesselation ? brepEdge.data.tesselation : brepEdge.curve.tessellateToData();
|
||||
this.representation = new ScalableLine(tesselation, 1, 0x2B3856, undefined, false, true);
|
||||
this.marker = new ScalableLine(tesselation, 2, 0xd1726c, undefined, false, true);
|
||||
this.picker = new ScalableLine(tesselation, 10, 0xFA8072, undefined, false, true);
|
||||
this.marker.visible = false;
|
||||
this.picker.material.visible = false;
|
||||
|
||||
setAttribute(this.representation, EDGE, this);
|
||||
setAttribute(this.picker, EDGE, this);
|
||||
|
||||
this.rootGroup.add(this.representation);
|
||||
this.rootGroup.add(this.marker);
|
||||
this.rootGroup.add(this.picker);
|
||||
}
|
||||
|
||||
mark(color) {
|
||||
this.marker.visible = true;
|
||||
}
|
||||
|
||||
withdraw(color) {
|
||||
this.marker.visible = false;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.representation.dispose();
|
||||
this.marker.dispose();
|
||||
super.dispose();
|
||||
let tess = brepEdge.data.tesselation ? brepEdge.data.tesselation : brepEdge.curve.tessellateToData();
|
||||
super(edge, tess, 1, 2, 0x2B3856, 0xd1726c);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ export class SketchingView extends View {
|
|||
}
|
||||
|
||||
updateSketch() {
|
||||
SceneGraph.clearGroup(this.sketchGroup);
|
||||
SceneGraph.emptyGroup(this.sketchGroup);
|
||||
this.disposeSketch();
|
||||
this.sketchObjectViews = [];
|
||||
|
||||
const sketchTr = this.model.sketchToWorldTransformation;
|
||||
for (let sketchObject of this.model.sketchObjects) {
|
||||
let sov = new SketchObjectView(sketchObject, sketchTr);
|
||||
SceneGraph.addToGroup(this.sketchGroup, sov.rootGroup);
|
||||
this.sketchObjectViews.push(sov);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +31,7 @@ export class SketchingView extends View {
|
|||
for (let sov of this.sketchObjectViews) {
|
||||
sov.dispose();
|
||||
}
|
||||
this.sketchObjectViews = [];
|
||||
}
|
||||
|
||||
dispose() {
|
||||
|
|
|
|||
|
|
@ -1,52 +1,10 @@
|
|||
import {View} from './view';
|
||||
import {getAttribute, setAttribute} from 'scene/objectData';
|
||||
import staticResource from 'scene/staticResource';
|
||||
import {SKETCH_OBJECT} from '../entites';
|
||||
import Vector from 'math/vector';
|
||||
import {createLineMaterial} from 'scene/materials';
|
||||
import {CurveBasedView} from './curveBasedView';
|
||||
|
||||
export class SketchObjectView extends View {
|
||||
export class SketchObjectView extends CurveBasedView {
|
||||
|
||||
constructor(mSketchObject, _3dTransformation) {
|
||||
super(mSketchObject);
|
||||
|
||||
this.material = mSketchObject.construction ? SKETCH_CONSTRUCTION_MATERIAL : SKETCH_MATERIAL;
|
||||
let line = new THREE.Line(new THREE.Geometry(), this.material);
|
||||
setAttribute(line, SKETCH_OBJECT, this);
|
||||
const chunks = mSketchObject.sketchPrimitive.tessellate(10);
|
||||
function addLine(p, q) {
|
||||
const lg = line.geometry;
|
||||
const a = _3dTransformation.apply(chunks[p]);
|
||||
const b = _3dTransformation.apply(chunks[q]);
|
||||
|
||||
lg.vertices.push(a._plus(OFF_LINES_VECTOR).three());
|
||||
lg.vertices.push(b._plus(OFF_LINES_VECTOR).three());
|
||||
}
|
||||
for (let q = 1; q < chunks.length; q ++) {
|
||||
addLine(q - 1, q);
|
||||
}
|
||||
|
||||
this.rootGroup = line;
|
||||
}
|
||||
|
||||
mark(color) {
|
||||
let line = this.rootGroup;
|
||||
line.material = SKETCH_SELECTION_MATERIAL;
|
||||
}
|
||||
|
||||
withdraw(color) {
|
||||
let line = this.rootGroup;
|
||||
line.material = this.material;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.rootGroup.geometry.dispose();
|
||||
super.dispose();
|
||||
constructor(mSketchObject, sketchToWorldTransformation) {
|
||||
const color = mSketchObject.construction ? 0x777777 : 0xFFFFFF;
|
||||
const tess = mSketchObject.sketchPrimitive.tessellate(10).map(sketchToWorldTransformation.apply).map(v => v.data());
|
||||
super(mSketchObject, tess, 0.3, 1, color, 0x49FFA5);
|
||||
}
|
||||
}
|
||||
|
||||
const OFF_LINES_VECTOR = new Vector();//normal.multiply(0); // disable it. use polygon offset feature of material
|
||||
|
||||
const SKETCH_MATERIAL = staticResource(createLineMaterial(0xFFFFFF, 3));
|
||||
const SKETCH_CONSTRUCTION_MATERIAL = staticResource(createLineMaterial(0x777777, 2));
|
||||
const SKETCH_SELECTION_MATERIAL = staticResource(createLineMaterial(0xFF0000, 6));
|
||||
|
|
|
|||
Loading…
Reference in a new issue