@tscad/modeling
Methods to model your 3d model
Use @tscad/modeling to define your 3d models.
This is probably the most important package of tscad.
Introduction
Usually a model is made up of a function that generates geometry (the "model function") and a set of parameters that control how the model is generated.
import { } from '@tscad/modeling';
export default ({
: () => {},
});A model function usually combines a few primitives from @tscad/modeling/primitives to create a model body.
import { } from '@tscad/modeling';
import { , } from '@tscad/modeling/primitives';
export default ({
: () => {
// create some solids
const = ({ : 10 });
const = ({ : 5, : [5, 5, 10] });
// return the model's solids
return [, ];
},
});If you want to customize how the model appears in the preview, you can colorize it using @tscad/modeling/colors.
export default ({
: () => {
const = ({ : 10 });
const = ({ : 5, : [5, 5, 10] });
return [
,
(
[1, 0, 0], // red
,
),
];
},
});Additionally, models can define parameters to make them more flexible.
export default ({
: {
: { : 'number', : 10, : 1 },
},
: ({ }) => {
const = ({ });
const = ({ : 5, : [5, 5, 10] });
return [, ([1, 0, 0], )];
},
});Methods and properties
import {
,
type ,
type ,
type ,
type ,
type ,
type
} from '@tscad/modeling'function defineModel(model)
Defines a model, including its parameters and model function.
Examples
import { } from '@tscad/modeling';
import { } from '@tscad/modeling/primitives';
({
: () => ({ : 10 }),
});import { } from '@tscad/modeling';
import { } from '@tscad/modeling/primitives';
({
: {
: { : 'number', : 10, : 1 },
},
: ({ }) => ({ }),
});Parameters
Prop
Type
Defined in packages/modeling/src/index.ts
type ModelDefinition
Definitions for a model
export type <> = {
: ;
: (: ) => | [];
};Defined in packages/modeling/src/types.ts
type ParametersInput
export type = {
[: string]: <, boolean>;
};Defined in packages/modeling/src/types.ts
type RenderedModel
export type <> = {
: ;
: [];
};Defined in packages/modeling/src/types.ts
type Solid
A solid object
export type = any;Defined in packages/modeling/src/types.ts
type Vector2
A two-dimensional vector
export type = [number, number];Defined in packages/modeling/src/types.ts
type Vector3
export type = [number, number, number];Defined in packages/modeling/src/types.ts