Solid
A Solid represents closed space containing one or more shells. It provides access to underlying shels, faces, edges, wires and vertices. Two solids can be combined using boolean operators to produce new solid. Transformation can be applied to a solid to change its orientation in space.
Constructor
Creates an empty instance.
Syntax
let s = cadlib.solid()
Returns
Methods
isNull()
Checks if the solid is empty.
Syntax
let isEmpty = cadlib.isNull()
Returns
equals()
Checks if this solid is same as other
Syntax
solid.equals(solid);
Parameters:
Name | Type | Description |
---|---|---|
solid | Solid | Another Solid to test against |
Returns
-numFaces
Returns number of faces in the solid
Syntax
numFaces()
Returns
(Int) Number of Faces
numSolids
Compound solids can containe one or more sub-solids. This method returns number of solids. For a single solid, it returns 1.
Syntax
solid.numSolids()
Returns
(Int) Number of Solids
numShells
Returns number of shells within this solid.
Syntax
numShells()
Returns
Number - Number of [Shells](../shell)faces
Returns array of faces in this solid
Example
let solid = cadapi.box(...);
var faces = solid.faces();
for(var i=0, len = faces.length;i < len; ++i) {
let face = faces[i];
...
}
Returns
Array of Face
wires
Returns wires of a face
let s = cadlib.solid();
//obtain 'face' object from iterating over faces or clicking on a face of the shape in the scene.
let wires = s.wires(face);
Parameters:
Name | Type | Description |
---|---|---|
face | Face | A Face object of which wires are desired |
Returns
Array of Wire
getShapeName
Returns name of the type of the shape contained in this solid. Shape could be face, edge or a vertex.
Syntax
getShapeName(shape)
Parameters:
Name | Type | Description |
---|---|---|
shape | Object | A Face, Edge or Vertex |
Returns
String
volume
let s = cadlib.solid();
let sVolume = s.volume();
Returns
_(Number):Solid's volume_area
let s = cadlib.solid();
let sArea = s.area();
Returns
(Number):Area of a solid
shapeType
let s = cadlib.solid();
let shell = s.shapeType();
Returns
(String):SOLID or COMPSOLID
copyFrom
Copies a solid from another solid. This is a shallow copy. Modifies current solid.
let source = cadlib.solid();
let target = cadlib.solid();
//Some operations on target
source.copyFrom(target);
resetLocation
let s = cadlib.solid();
s.resetLocation();
iterator
Returns an iterator over specified shape.
Arguments
Name | Type | Description |
---|---|---|
shapeType | string | SOLID, SHELL, FACE, WIRE, EDGE, VERTEX |
Returns
````javascript
let ite = aSolid.iterator("FACE");
while( ite.more) {
ite.next();
let offsetShape = ite.current;
}
findFaceById
Finds a face by its Id (Although recomended method is to use face name).
Typically, this is need arises when you are creating a shape that takes a face name or id as an input from user.
In script development mode, use isDevMode() function to declare a local test shape.
In non-dev mode, define a parameter of type ‘FACE’ and extract face information from user selections.
Syntax
solid.findFaceById(faceId)Arguments
Name | Type | Description |
---|---|---|
faceId | string | Click on a face to obtain face Id |
Returns
[Face](../face)findEdgeByID
Finds an edge by ID
Syntax
solid.findEdgeByID(edgeId)Arguments
Name | Type | Description |
---|---|---|
edgeId | string | Click on an edge to obtain edge Id |
Returns
[Edge](../)selectFaces
Selects one or more faces by IDs.
Syntax
solid.selectFaces( [faceId [,...] ] )Arguments
Name | Type | Description |
---|---|---|
faceId | array | Click on faces to obtain face Id |
Returns
Solid (Returns this solid)
selectEdges
Selects one or more edges by IDs.
Syntax
solid.selectEdges( [edgeId [,...] ] )Arguments
Name | Type | Description |
---|---|---|
edgeId | array | Click on edges to obtain edge Id |
Returns
Solid (Returns this solid)
selectCommonEdges
Syntax
solid.selectCommonEdges(faceIDList)
Arguments
Name | Type | Description |
---|---|---|
edgeIDs | array | Array of face Ids. Click on a face to obtain its Id |
Returns
Solid (Returns this solid)
clone
Syntax
solid.clone(shallow)
Arguments
Name | Type | Description |
---|---|---|
shallow | Boolean | If false, creates a deep copy |
Returns
Solid: Cloned solid
translate
Translates this solid to specified location.
Note: If you create a single shape in your script and translate it then you will not see any movement. Reason being, the translated shape, which is the only one in the ‘resulting’ solid, is reset to the center, as scripted solid by default is always at the center.
On the other hand, if solid contains more than one shape then the translation of that shape within the solid will be apperent.
solid.translate( x, y, z, clone);
Name | Type | Description |
---|---|---|
x | Number | translation on X axis |
y | Number | translation on Y axis |
z | Number | translation on Z axis |
copy | Boolean | If true, return a translated copy of the origianl solid |
Returns
Solid Translated solid
rotate
Syntax
solid.rotate(center, axis, angle, copy)Arguments
Name | Type | Description |
---|---|---|
center | Vector3] | A vector on the axis rotation |
axis | Vector3 | Axis of rotation |
angle | Vector3 | Rotation angle in degrees |
copy | Boolean | If true, return a copy of the origianl solid |
Returns
Solid - Rotated solid
Exanple
let center = {x:0, y:0, z:0}, axis = {x:0, y:1, z:0}; //rotation around Y axis
solid.rotate( center, axix, 45, true);
scale
Syntax
solid.scale(factor, center, copy)
Parameters
Name | Type | Description |
---|---|---|
factor | Number | Scaling factor |
center | Vector3 | Center of the scaling |
copy | Boolean | If true, return a copy of the origianl solid |
Returns
(Solid) - Rotated solid
Exanple
solid.scale(2.0, {x:0, y:0, z:0},true)
transform
Transforms a solid using given transformation
Syntax
solid.transform(trans, copy)
Arguments
Name | Type | Description |
---|---|---|
transform | Transformation | Transform to apply |
copy | Boolean | If true, return a copy of the origianl solid |
resetLocation | Boolean | optional, resets location of both objects if copy = true |
Returns
Solid - Transformed solid
Example
let t = cadlib.translationTransform(10, 0, 0)
solid.transform(t, true)
mirrorPlane
Applies a mirror transform around a plane
Syntax
mirrorPlane(center, axis, copy)
Arguments
Name | Type | Description |
---|---|---|
center | Point | Planes center |
axis | Vector3 | Planes direction |
copy | Boolean | if true, copy of the solid is returned |
Returns
mirrorAxis
Applies a mirror transform around an axis
Syntax
solid.mirrorAxis(center, axis, copy)
Arguments
Name | Type | Description |
---|---|---|
center | Point | Planes center |
axis | Vector3 | Planes direction |
copy | Boolean | if true, copy of the solid is returned |
Returns
orient
Orients the solid along specified direction.
Syntax
orient(center, up, forward)
Arguments
Name | Type | Description |
---|---|---|
center | Point | Planes center |
up | Vector3 | Unit vector in the desired direction |
forward | Vector3 | Unit vector in the desired forward direction |
Returns
Solid - This solid
Primitives
box
Creates a box with its bottom lying on X-Z plan with its center at the origin.
Syntax
cadlib.box(options)Arguments
- options (Object):
- width (number): Width of the box
- height (umber): Height of the box
- depth (Number): Depth of the box
Returns
(Solid): This instance.cylinder
Creates a cylinder with its bottom lying on X-Z plan with a given center.
Syntax
cadlib.cylinder(options)Arguments
- options (Object):
- center (Point): Specifies center of the bottom face of the cynlinder.
- up (Vector): Unit vector in the direction of cylinder axis
- radius (Number): Radius of the cylinder
- height (Number): Height of the cynlinder
Returns
(Solid): This instance.sphere
Creates a capped sphere with its bottom lying on X-Z plan with a given center.
Syntax
cadlib.cylinder(options)Arguments
- options (Object):
- center (Point): Specifies center of the sphere.
- radius (Number): Radius of the sphere
- angle1 (Number, Optional): Angle of the top cap in degrees.
- angle2 (Number, Optional): Angle of the bottom cap in degrees
Returns
(Solid): This instance.torus
Creates a torus.
Syntax
cadlib.torus(options)Arguments
- options (Object):
- center (Point): Specifies center of the sphere.
- axis (Vector): Unit vector in the direction of torus.
- innerRadius (Number): Inner radius of the sphere
- outerRadius (Number): Outer radius of the sphere
Returns
(Solid): This instance.Example
cone
Creates a cone with center of the origin and axis in up (positive Y) direction.
Syntax
solid.cone(options)Arguments
- options (Object):
- Capped Cone - variation 1
- height (Number): Height of the cone.
- r1 (Number): Radius of the bottom face
- r2 (Number): Radius of the top face
- Capped Cone - variation 2
- p1 (Point): Center of the base face of the cone
- p2 (Point): Center of the top face of the cone
- r1 (Number): Radius of the bottom face
- r2 (Number): Radius of the top face
- Oriented cone
- axis (Vector): Direction of the cone’s axis
- height (Number): Height of the cone
- angle (Number): Angle of the cone’s side
Returns
(Solid): This instance