mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-23 17:04:00 +01:00
purging unused code
This commit is contained in:
parent
f5e44d6785
commit
95c6a0fe05
13 changed files with 3 additions and 460 deletions
|
|
@ -1,114 +0,0 @@
|
|||
import {enclose} from 'brep/operations/brep-enclose'
|
||||
import {BooleanOperation, combineShells} from '../booleanOperation'
|
||||
import {Matrix3x4} from 'math/matrix';
|
||||
import {equal} from 'math/equality';
|
||||
|
||||
|
||||
export function Extrude(params, ctx) {
|
||||
// return doOperation(params, ctx, false);
|
||||
|
||||
return ctx.craftEngine.cutExtrude(false, params);
|
||||
}
|
||||
|
||||
export function Cut(params, ctx) {
|
||||
|
||||
// return doOperation(params, ctx, true);
|
||||
|
||||
return ctx.craftEngine.cutExtrude(true, params);
|
||||
}
|
||||
|
||||
export function doOperation(params, ctx, cut) {
|
||||
const {cadRegistry, sketchStorageService} = ctx;
|
||||
const face = cadRegistry.findFace(params.face);
|
||||
const solid = face.solid;
|
||||
|
||||
let sketch = sketchStorageService.readSketch(face.id);
|
||||
if (!sketch) throw 'sketch not found for the face ' + face.id;
|
||||
|
||||
let vector = resolveExtrudeVector(cadRegistry, face, params, !cut);
|
||||
const details = getEncloseDetails(params, sketch.fetchContours(), vector, face.csys, face.surface, !cut, false);
|
||||
const operand = combineShells(details.map(d => enclose(d.basePath, d.lidPath, d.baseSurface, d.lidSurface)));
|
||||
return BooleanOperation(face, solid, operand, cut ? 'subtract' : 'union');
|
||||
}
|
||||
|
||||
export function resolveExtrudeVector(cadRegistry, face, params, invert) {
|
||||
let vector = null;
|
||||
if (params.datumAxisVector) {
|
||||
const datumAxis = cadRegistry.findDatumAxis(params.datumAxisVector);
|
||||
if (datumAxis) {
|
||||
vector = datumAxis.dir;
|
||||
invert = false;
|
||||
}
|
||||
} else if (params.edgeVector) {
|
||||
const edge = cadRegistry.findEdge(params.edgeVector);
|
||||
const curve = edge.brepEdge.curve;
|
||||
if (curve.degree === 1) {
|
||||
vector = edge.brepEdge.curve.tangentAtParam(edge.brepEdge.curve.uMin);
|
||||
if (vector.dot(face.csys.z) < 0 === invert) {
|
||||
vector = vector.negate();
|
||||
}
|
||||
invert = false;
|
||||
}
|
||||
} else if (params.sketchSegmentVector) {
|
||||
const mSegment = cadRegistry.findSketchObject(params.sketchSegmentVector);
|
||||
if (mSegment.sketchPrimitive.isSegment) {
|
||||
let [a, b] = mSegment.sketchPrimitive.tessellate().map(mSegment.face.sketchToWorldTransformation.apply);
|
||||
vector = b.minus(a)._normalize();
|
||||
if (vector.dot(face.csys.z) < 0 === invert) {
|
||||
vector._negate();
|
||||
}
|
||||
invert = false;
|
||||
}
|
||||
}
|
||||
if (!vector) {
|
||||
invert = !invert;
|
||||
vector = face.csys.z;
|
||||
}
|
||||
|
||||
if (params.flip) {
|
||||
invert = !invert;
|
||||
}
|
||||
|
||||
let value = params.value;
|
||||
if (value < 0) {
|
||||
value = Math.abs(value);
|
||||
invert = !invert;
|
||||
}
|
||||
|
||||
if (invert) {
|
||||
vector = vector.negate();
|
||||
}
|
||||
|
||||
return vector.multiply(value);
|
||||
}
|
||||
|
||||
export function getEncloseDetails(params, contours, target, csys, sketchSurface, invert) {
|
||||
let details = [];
|
||||
for (let contour of contours) {
|
||||
if (invert) contour.reverse();
|
||||
const basePath = contour.transferInCoordinateSystem(csys);
|
||||
if (invert) contour.reverse();
|
||||
|
||||
const lidPath = [];
|
||||
let applyPrism = !equal(params.prism, 1);
|
||||
let prismTr = null;
|
||||
if (applyPrism) {
|
||||
prismTr = new Matrix3x4();
|
||||
prismTr.scale(params.prism, params.prism, params.prism);
|
||||
}
|
||||
for (let i = 0; i < basePath.length; ++i) {
|
||||
const curve = basePath[i];
|
||||
let lidCurve = cur
|
||||
ve.translate(target);
|
||||
if (applyPrism) {
|
||||
lidCurve = lidCurve.transform(prismTr);
|
||||
}
|
||||
lidPath.push(lidCurve);
|
||||
}
|
||||
|
||||
const baseSurface = sketchSurface.tangentPlane(0, 0);
|
||||
const lidSurface = baseSurface.translate(target).invert();
|
||||
details.push({basePath, lidPath, baseSurface, lidSurface});
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ import {
|
|||
import * as vec from 'math/vec';
|
||||
import {MOpenFaceShell} from '../../model/mopenFace';
|
||||
import {BooleanType, EngineAPI_V1} from "engine/api";
|
||||
import {resolveExtrudeVector} from "../cutExtrude/cutExtrude";
|
||||
|
||||
import {ApplicationContext} from "context";
|
||||
import {MBrepShell} from "../../model/mshell";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
import React from 'react';
|
||||
import {Group} from '../wizard/components/form/Form';
|
||||
|
||||
export default function SpatialCurveWizard() {
|
||||
return <Group>
|
||||
</Group>;
|
||||
}
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
import DatumObject3D from '../../datum/datumObject';
|
||||
import {
|
||||
ArcCurve, CatmullRomCurve3, CubicBezierCurve3, CurvePath, ExtrudeBufferGeometry, Mesh, MeshBasicMaterial, Object3D,
|
||||
PolyhedronGeometry,
|
||||
Shape,
|
||||
SphereGeometry, Vector2, Vector3
|
||||
} from 'three';
|
||||
import {CSYS_SIZE_MODEL} from '../../datum/csysObject';
|
||||
import {DisposableMesh} from 'scene/objects/disposableMesh';
|
||||
|
||||
export default class ControlPointObject3D extends DatumObject3D {
|
||||
|
||||
constructor(csys, viewer) {
|
||||
super(csys, viewer);
|
||||
this.affordanceArea = new AffordanceArea();
|
||||
this.csysObj.add(this.affordanceArea);
|
||||
const xrh = new RotationHandleHolder(new RotationHandle(0xff0000));
|
||||
const yrh = new RotationHandleHolder(new RotationHandle(0x00ff00));
|
||||
const zrh = new RotationHandleHolder(new RotationHandle(0x0000ff));
|
||||
|
||||
// yrh.rotateOnAxis(new Vector3(1, 0, 0), Math.PI * 0.5);
|
||||
|
||||
// zrh.rotateOnAxis(new Vector3(1, 0, 0), Math.PI * 0.5);
|
||||
|
||||
// this.csysObj.add(xrh);
|
||||
this.csysObj.add(yrh);
|
||||
// this.csysObj.add(zrh);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class RotationHandleHolder extends Object3D {
|
||||
|
||||
constructor(handle, rotation) {
|
||||
|
||||
super();
|
||||
|
||||
let size = CSYS_SIZE_MODEL * 1.05;
|
||||
|
||||
|
||||
this.position.set(0, 0, -size);
|
||||
handle.scale.set(size, size, size);
|
||||
|
||||
this.add(handle);
|
||||
this.dispose = () => handle.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class RotationHandle extends DisposableMesh {
|
||||
|
||||
constructor(color) {
|
||||
|
||||
const path = new CurvePath();
|
||||
|
||||
const C = 0.551915024494;
|
||||
|
||||
path.curves.push(new CubicBezierCurve3(
|
||||
new Vector3( 0, 1, 0 ),
|
||||
new Vector3( C, 1, 0 ),
|
||||
new Vector3( 1, C, 0 ),
|
||||
new Vector3( 1, 0, 0 ),
|
||||
),
|
||||
new CubicBezierCurve3(
|
||||
new Vector3( 1, 0, 0 ),
|
||||
new Vector3( 1, -C, 0 ),
|
||||
new Vector3( C, -1, 0 ),
|
||||
new Vector3( 0, -1, 0 ),
|
||||
),
|
||||
new CubicBezierCurve3(
|
||||
new Vector3( 0, -1, 0 ),
|
||||
new Vector3( -C, -1, 0 ),
|
||||
new Vector3( -1, -C, 0 ),
|
||||
new Vector3( -1, 0, 0 ),
|
||||
)
|
||||
);
|
||||
|
||||
let extrudeSettings = {
|
||||
steps: 50,
|
||||
extrudePath: path
|
||||
};
|
||||
|
||||
|
||||
let S = 0.01;
|
||||
let shape = new Shape( [new Vector3(-S, -S), new Vector3(S, -S), new Vector3(S, S), new Vector3(-S, S), new Vector3(-S, -S)] );
|
||||
|
||||
let geometry = new ExtrudeBufferGeometry( [shape], extrudeSettings );
|
||||
|
||||
super(geometry, new MeshBasicMaterial({
|
||||
// transparent: true,
|
||||
// opacity: 0.5,
|
||||
color,
|
||||
// visible: false
|
||||
}));
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.geometry.dispose();
|
||||
this.material.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class AffordanceArea extends DisposableMesh {
|
||||
|
||||
constructor() {
|
||||
super(new SphereGeometry( 1, 8, 8), new MeshBasicMaterial({
|
||||
transparent: true,
|
||||
opacity: 0.5,
|
||||
color: 0xAA8439,
|
||||
// visible: false
|
||||
}));
|
||||
|
||||
let size = CSYS_SIZE_MODEL * 1.05;
|
||||
this.scale.set(size, size, size);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.geometry.dispose();
|
||||
this.material.dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
import * as SceneGraph from 'scene/sceneGraph';
|
||||
import ControlPointObject3D from './controlPointObject';
|
||||
|
||||
export default function spatialCurveEditor(workGroup, viewer, frames) {
|
||||
|
||||
function init() {
|
||||
frames.forEach(addPoint);
|
||||
}
|
||||
|
||||
|
||||
function addPoint(pCsys) {
|
||||
SceneGraph.addToGroup(workGroup, new ControlPointObject3D(pCsys, viewer));
|
||||
viewer.requestRender();
|
||||
}
|
||||
|
||||
function dispose() {
|
||||
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
return {
|
||||
dispose
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
export default {
|
||||
points: {
|
||||
type: 'number',
|
||||
defaultValue: 0
|
||||
},
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
import CSys from 'math/csys';
|
||||
import {MDatum} from '../../model/mdatum';
|
||||
|
||||
import spatialCurveOpSchema from './spatialCurveOpSchema';
|
||||
import SpatialCurveWizard from './SpatialCurveWizard';
|
||||
import spatialCurveEditor from './editor/spatialCurveEditor';
|
||||
|
||||
function updateCSys(csys, params, findFace) {
|
||||
csys.copy(CSys.ORIGIN);
|
||||
if (params.originatingFace) {
|
||||
const face = findFace(params.originatingFace);
|
||||
if (face) {
|
||||
csys.copy(face.csys);
|
||||
}
|
||||
}
|
||||
|
||||
csys.origin.x += params.x;
|
||||
csys.origin.y += params.y;
|
||||
csys.origin.z += params.z;
|
||||
}
|
||||
|
||||
function create(params, {cadRegistry}) {
|
||||
let csys = CSys.origin();
|
||||
updateCSys(csys, params, cadRegistry.findFace);
|
||||
|
||||
return {
|
||||
consumed: [],
|
||||
created: [new MDatum(csys)]
|
||||
}
|
||||
}
|
||||
|
||||
function previewer(ctx, initialParams, updateParams) {
|
||||
|
||||
let editor = spatialCurveEditor(ctx.services.cadScene.workGroup, ctx.services.viewer, [CSys.ORIGIN]);
|
||||
|
||||
|
||||
function update(params) {
|
||||
// updateCSys(datum3D.csys, params, ctx.services.cadRegistry.findFace);
|
||||
}
|
||||
|
||||
function dispose() {
|
||||
editor.dispose();
|
||||
}
|
||||
|
||||
|
||||
update(initialParams);
|
||||
|
||||
return {
|
||||
update, dispose
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
id: 'SPATIAL_CURVE',
|
||||
label: 'Edit Spatial Curve',
|
||||
icon: 'img/cad/plane',
|
||||
info: 'create/edit spatial curve',
|
||||
previewer,
|
||||
run: create,
|
||||
form: SpatialCurveWizard,
|
||||
schema: spatialCurveOpSchema
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
import React from 'react';
|
||||
import {Group} from "../../craft/wizard/components/form/Form";
|
||||
import {TextField} from "../../craft/wizard/components/form/Fields";
|
||||
|
||||
export function ImportStepForm() {
|
||||
|
||||
return <Group>
|
||||
<TextField name='url' />
|
||||
</Group>;
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
import React from 'react';
|
||||
import {Group} from "../../craft/wizard/components/form/Form";
|
||||
import {FileField} from "../../craft/wizard/components/form/Fields";
|
||||
|
||||
export function ImportStepLocalForm() {
|
||||
|
||||
return <Group>
|
||||
<FileField name='file' />
|
||||
</Group>;
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
import {ImportStepForm} from "./ImportStepForm";
|
||||
import importStepSchema from "./importStepSchema";
|
||||
import {OperationDescriptor} from "../../craft/operationPlugin";
|
||||
import {ApplicationContext} from "context";
|
||||
import {OperationResult} from "../../craft/craftPlugin";
|
||||
import {GiLunarModule} from "react-icons/gi";
|
||||
import {BiCubeAlt} from "react-icons/bi";
|
||||
import {checkHttpResponseStatus} from "network/checkHttpResponseStatus";
|
||||
import { LocalFile } from "ui/components/controls/FileControl";
|
||||
import { ImportStepLocalForm } from "./ImportStepLocalForm";
|
||||
import { string } from "prop-types";
|
||||
|
||||
export interface ImportStepOperationParams {
|
||||
url: string,
|
||||
}
|
||||
|
||||
export interface ImportStepFromLocalOperationParams {
|
||||
|
||||
file: LocalFile;
|
||||
|
||||
}
|
||||
|
||||
export const ImportStepOperation: OperationDescriptor<ImportStepOperationParams> = {
|
||||
|
||||
id: 'IMPORT_STEP_FILE',
|
||||
label: 'import step file',
|
||||
icon: GiLunarModule,
|
||||
info: 'import step file from external url',
|
||||
paramsInfo: ({url}) => url,
|
||||
previewGeomProvider: null,
|
||||
run: importStepFile,
|
||||
form: ImportStepForm,
|
||||
schema: importStepSchema
|
||||
};
|
||||
|
||||
export const ImportStepFromLocalFileOperation: OperationDescriptor<ImportStepFromLocalOperationParams> = {
|
||||
|
||||
id: 'IMPORT_STEP_LOCAL_FILE',
|
||||
label: 'import local step file',
|
||||
icon: BiCubeAlt,
|
||||
info: 'import step file from local file',
|
||||
paramsInfo: ({file}) => file && file.fileName,
|
||||
previewGeomProvider: null,
|
||||
run: importStepLocalFile,
|
||||
form: ImportStepLocalForm,
|
||||
schema: {
|
||||
file: {
|
||||
type: 'object',
|
||||
schema: {
|
||||
fileName: {
|
||||
type: 'string',
|
||||
},
|
||||
constent: {
|
||||
type: 'string',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function importStepFile(params: ImportStepOperationParams, ctx: ApplicationContext): Promise<OperationResult> {
|
||||
|
||||
const {cadRegistry, remotePartsService} = ctx;
|
||||
|
||||
return fetch(params.url).then(checkHttpResponseStatus).then(res => res.text()).then(data => {
|
||||
|
||||
console.log(data);
|
||||
FS.writeFile('/tmp/test', data);
|
||||
|
||||
return ctx.services.craftEngine.stepImport({
|
||||
file: '/tmp/test'
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
function importStepLocalFile(params: ImportStepFromLocalOperationParams, ctx: ApplicationContext): Promise<OperationResult> {
|
||||
|
||||
const {cadRegistry, remotePartsService} = ctx;
|
||||
|
||||
console.log(params.file.content);
|
||||
FS.writeFile('/tmp/test', params.file.content);
|
||||
|
||||
return ctx.services.craftEngine.stepImport({
|
||||
file: '/tmp/test'
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
export default {
|
||||
url: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
|
@ -16,13 +16,12 @@ import {activate as activateExpressionsPlugin} from '../expressions/expressionsP
|
|||
import {activate as activateCadRegistryPlugin} from '../craft/cadRegistryPlugin';
|
||||
import {activate as activateStoragePlugin} from '../storage/storagePlugin';
|
||||
import {activate as activateSketchStoragePlugin} from '../sketch/sketchStoragePlugin';
|
||||
import {ImportStepFromLocalFileOperation, ImportStepOperation} from "./importStepOperation/importStepOperation";
|
||||
|
||||
export function activate(ctx: ApplicationContext) {
|
||||
|
||||
ctx.domService.contributeComponent(CatalogPartChooser);
|
||||
//ctx.domService.contributeComponent(CatalogPartChooser);
|
||||
|
||||
ctx.operationService.registerOperations([ImportPartOperation, ImportStepOperation, ImportStepFromLocalFileOperation]);
|
||||
//ctx.operationService.registerOperations([ImportPartOperation, ImportStepOperation, ImportStepFromLocalFileOperation]);
|
||||
|
||||
function loadDefinedCatalogs(): Promise<[CatalogCategory, PartsCatalog][]> {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import createDatumOperation from "cad/craft/datum/create/createDatumOperation";
|
|||
import moveDatumOperation from "cad/craft/datum/move/moveDatumOperation";
|
||||
import rotateDatumOperation from "cad/craft/datum/rotate/rotateDatumOperation";
|
||||
import datumOperation from "cad/craft/primitives/plane/planeOperation";
|
||||
import spatialCurveOperation from "cad/craft/spatialCurve/spatialCurveOperation";
|
||||
import {Plugin} from "plugable/pluginSystem";
|
||||
import {WorkbenchService} from "cad/workbench/workbenchService";
|
||||
import {OperationService} from "cad/craft/operationPlugin";
|
||||
|
|
@ -39,6 +38,5 @@ function registerCoreOperations(ctx: WorkbenchesLoaderInputContext) {
|
|||
moveDatumOperation,
|
||||
rotateDatumOperation,
|
||||
datumOperation,
|
||||
spatialCurveOperation,
|
||||
] as any);
|
||||
}
|
||||
Loading…
Reference in a new issue