fix extrude

This commit is contained in:
xibyte 2022-02-06 01:21:10 -08:00 committed by Val Erastov
parent 0cbd38d36c
commit db7a74c9a4
7 changed files with 51 additions and 35 deletions

View file

@ -37,7 +37,7 @@ const ExtrudeOperation: MDFCommand<ExtrudeParams> = {
const extrusionVector = dir.normalize()._multiply(params.length).data();
const tools = occFaces.map((faceName, i) => {
const shapeName = "Tool" + i;
const shapeName = "Tool/" + i;
oci.prism(shapeName, faceName, ...extrusionVector)
// occIterateFaces(oc, shape, face => {
@ -62,11 +62,7 @@ const ExtrudeOperation: MDFCommand<ExtrudeParams> = {
return shapeName;
});
return {
created: tools.map(shapeName => occ.io.getShell(shapeName)),
consumed: []
}
// return occ.utils.applyBooleanModifier(tools, params.boolean);
return occ.utils.applyBooleanModifier(tools, params.boolean);
},

View file

@ -1,13 +1,9 @@
import {OCCCommandInterface} from "cad/craft/e0/occCommandInterface";
import {Vec3} from "math/vec";
import {SketchGeom} from "cad/sketch/sketchReader";
import {OCCService} from "cad/craft/e0/occService";
import {CoreContext} from "context";
import CSys from "math/csys";
import {OperationResult} from "cad/craft/craftPlugin";
import {MShell} from "cad/model/mshell";
import {BooleanDefinition, BooleanKind} from "cad/craft/schema/common/BooleanDefinition";
import {bool} from "prop-types";
import {MShell} from "cad/model/mshell";
export interface OCCUtils {
@ -59,17 +55,20 @@ export function createOCCUtils(ctx: CoreContext): OCCUtils {
const kind = booleanDef.kind;
let targets = booleanDef.targets;
if (targets.length === 0) {
if (!targets || targets.length === 0) {
targets = ctx.cadRegistry.shells;
}
let targetNames = targets.map((target, i) => {
const targetName = 'Target:' + i;
ctx.occService.io.pushModel(target, targetName)
const targetName = 'Target/' + i;
const wasPushed = ctx.occService.io.pushModel(target, targetName);
if (!wasPushed) {
return null;
}
return targetName;
});
}).filter(targetName => !!targetName);
oci.bfuzzyvalue(0.0001);
oci.bfuzzyvalue(0.01);
oci.bclearobjects();
oci.bcleartools();
@ -77,22 +76,13 @@ export function createOCCUtils(ctx: CoreContext): OCCUtils {
tools.forEach(toolName => oci.baddtools(toolName));
oci.bfillds();
oci.bcbuild("BooleanResult");
// oci.bopcommon("result");
//oci.bopfuse("result");
//oci.bopcut("result");
oci.bbop("BooleanResult", booleanKindToOCCBopType(kind));
return {
consumed: targets,
created: tools.map(shapeName => occ.io.getShell(shapeName), targets)
created: [occ.io.getShell("BooleanResult", targets as MShell[])]
}
}
}
@ -100,4 +90,20 @@ export function createOCCUtils(ctx: CoreContext): OCCUtils {
wiresToFaces, sketchToFaces, applyBooleanModifier
}
}
enum OccBBOPTypes {
COMMON,
FUSE,
CUT,
CUT21,
}
function booleanKindToOCCBopType(kind: BooleanKind): number {
switch (kind) {
case "INTERSECT": return OccBBOPTypes.COMMON;
case "UNION": return OccBBOPTypes.FUSE;
case "SUBTRACT": return OccBBOPTypes.CUT;
default: throw 'unsupported boolean kind: ' + kind;
}
}

View file

@ -6,7 +6,14 @@ export const OCI: OCCCommandInterface = new Proxy({}, {
get: function (target, prop: string, receiver) {
return prop in target ? target[prop] : function() {
prop = prop.replace(/^_/, '');
const args = Array.from(arguments).map(a => JSON.stringify(a));
const args = Array.from(arguments).map(arg => {
const type = typeof arg;
if (type === 'object') {
return JSON.stringify(arg);
} else {
return arg + "";
}
});
console.log("ARGUMENTS:", args);
const returnCode = CallCommand(prop, [prop, ...args]);
// if (returnCode !== 0) {

View file

@ -11,7 +11,7 @@ export function createOCCEngineInterface(oci: OCCCommandInterface) {
io: {
pushModel: (params: {
name: string, operand: number,
}) => oci.EngineCommand(params)
}) => oci.EngineCommand('io.pushModel', params)
}
}

View file

@ -25,10 +25,15 @@ export function createOCCIO(ctx: CoreContext): OCCIO {
}
function pushModel(model: MObject, name: string) {
ctx.occService.engineInterface.pushModel({
const ptr = model.brepShell?.data?.externals?.ptr;
if (!ptr) {
return false;
}
ctx.occService.engineInterface.io.pushModel({
name,
operand: model.brepShell.data.externals.ptr
operand: ptr
});
return true;
}
function cleanupRegistry() {

View file

@ -1,5 +1,6 @@
import {FACE, SHELL} from '../../model/entities';
import {memoize} from "lodash/function";
import {Types} from "cad/craft/schema/types";
export function activate(ctx) {
ctx.streams.wizard.wizardContext.attach(wizCtx => {
@ -14,7 +15,7 @@ export function activate(ctx) {
Object.keys(schema).forEach(param => {
let md = schema[param];
if (md.type !== 'entity') {
if (md.type !== 'entity' && !(md.type === 'array' && md.items.type === 'entity')) {
return;
}
@ -68,7 +69,8 @@ function createPickHandlerFromSchema(wizCtx) {
let {workingSchema: schema} = wizCtx.operation;
const activeMd = state.activeParam && schema[state.activeParam];
const activeCanTakeIt = kind => activeMd.allowedKinds && activeMd.allowedKinds.includes(kind);
const unwrappedActiveMd = activeMd.type === Types.array ? activeMd.items : activeMd;
const activeCanTakeIt = kind => unwrappedActiveMd.allowedKinds && unwrappedActiveMd.allowedKinds.includes(kind);
function select(param, md, id) {
const valueGetter = md.type === 'array' ? arrayValue : singleValue;

View file

@ -69,8 +69,8 @@ BooleanWidget.propsToSchema = (consumer: OperationSchema, props: BooleanWidgetPr
targets: {
label: 'targets',
type: Types.array,
item: {
type: Types.boolean,
items: {
type: Types.entity,
allowedKinds: ENTITY_CAPTURE,
},
optional: true,