@shards-design/core
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -17,2 +17,4 @@ import { Mesh, MeshBuilder, Vector3 } from '@babylonjs/core'; | ||
set position(position: Vector3); | ||
get material(): import("@babylonjs/core").Nullable<import("@babylonjs/core").Material>; | ||
set material(material: import("@babylonjs/core").Nullable<import("@babylonjs/core").Material>); | ||
/** | ||
@@ -66,7 +68,38 @@ * Move the object to the left by a delta, not an absolute position | ||
alignLeft(object: BaseObject): this; | ||
alignRight(object: BaseObject): this; | ||
alignFront(object: BaseObject): this; | ||
alignBack(object: BaseObject): this; | ||
alignBottom(object: BaseObject): this; | ||
alignTop(object: BaseObject): this; | ||
/** | ||
* Rotate the object around an axis | ||
* | ||
* Example: | ||
* object.rotate(Vector3.Up(), 90) | ||
* | ||
* @param axis The axis to rotate the object around | ||
* @param angle The angle in degrees | ||
* @returns | ||
*/ | ||
rotate(axis: Vector3, angle: number): this; | ||
/** | ||
* Subtract an object from the current object in a boolean operation | ||
* | ||
* @param object The object to subtract from the current object | ||
* @returns | ||
*/ | ||
subtract(object: BaseObject): this; | ||
/** | ||
* Intersect the current object with another object in a boolean operation | ||
* | ||
* @param object The object to intersect with the current object | ||
* @returns | ||
*/ | ||
intersect(object: BaseObject): this; | ||
/** | ||
* Combine the current object with another object in a boolean operation | ||
* | ||
* @param object The object to combine with the current object | ||
* @returns | ||
*/ | ||
union(object: BaseObject): this; | ||
@@ -93,2 +126,22 @@ repeatLinear(n: number, step: number, direction: Vector3): Mesh[]; | ||
} | ||
/** | ||
* Extrude a shape along a path | ||
* | ||
* @param options | ||
* @param options.shape The shape to extrude, a list of Vector3 points that | ||
* define the shape in the horizontal plane, i.e. the last coordinate should | ||
* be 0. | ||
* @param options.path The path to extrude the shape along, a list of Vector3 | ||
* points that define the extrusion path. | ||
* | ||
* @example | ||
* new Extrude({ | ||
* shape: [ | ||
* new Vector3(0, 0, 0), | ||
* new Vector3(depth / 2, 0, 0), | ||
* new Vector3(depth / 2, depth / 2, 0), | ||
* ], | ||
* path: [Vector3.Zero(), Vector3.Up().scale(height)], | ||
* }) | ||
*/ | ||
export declare class Extrude extends BaseObject { | ||
@@ -95,0 +148,0 @@ constructor(options: Parameters<typeof MeshBuilder.ExtrudeShape>[1] & { |
@@ -43,2 +43,8 @@ "use strict"; | ||
} | ||
get material() { | ||
return this.mesh.material; | ||
} | ||
set material(material) { | ||
this.mesh.material = material; | ||
} | ||
/** | ||
@@ -132,2 +138,8 @@ * Move the object to the left by a delta, not an absolute position | ||
} | ||
alignRight(object) { | ||
const objectRightBoundary = object.mesh.getBoundingInfo().boundingBox.maximum.x + | ||
object.getBasePosition().x; | ||
this.mesh.position.x = objectRightBoundary; | ||
return this; | ||
} | ||
alignFront(object) { | ||
@@ -145,28 +157,71 @@ const objectFrontBoundary = object.mesh.getBoundingInfo().boundingBox.maximum.z + | ||
} | ||
alignBottom(object) { | ||
const objectBottomBoundary = object.mesh.getBoundingInfo().boundingBox.minimum.y + | ||
object.getBasePosition().y; | ||
this.mesh.position.y = objectBottomBoundary; | ||
return this; | ||
} | ||
alignTop(object) { | ||
const objectTopBoundary = object.mesh.getBoundingInfo().boundingBox.maximum.y + | ||
object.getBasePosition().y; | ||
this.mesh.position.y = objectTopBoundary; | ||
return this; | ||
} | ||
/** | ||
* Rotate the object around an axis | ||
* | ||
* Example: | ||
* object.rotate(Vector3.Up(), 90) | ||
* | ||
* @param axis The axis to rotate the object around | ||
* @param angle The angle in degrees | ||
* @returns | ||
*/ | ||
rotate(axis, angle) { | ||
this.mesh.rotate(axis, angle); | ||
this.mesh.rotate(axis, (0, helpers_1.degToRad)(angle)); | ||
return this; | ||
} | ||
/** | ||
* Subtract an object from the current object in a boolean operation | ||
* | ||
* @param object The object to subtract from the current object | ||
* @returns | ||
*/ | ||
subtract(object) { | ||
const result = core_1.CSG.FromMesh(this.mesh).subtract(core_1.CSG.FromMesh(object.mesh)); | ||
// Remove the 2 starting meshes from the scene | ||
const material = this.mesh.material; | ||
this.mesh.dispose(); | ||
object.mesh.dispose(); | ||
this.mesh = result.toMesh(this.name); | ||
this.mesh = result.toMesh(this.name, material); | ||
return this; | ||
} | ||
/** | ||
* Intersect the current object with another object in a boolean operation | ||
* | ||
* @param object The object to intersect with the current object | ||
* @returns | ||
*/ | ||
intersect(object) { | ||
const result = core_1.CSG.FromMesh(this.mesh).intersect(core_1.CSG.FromMesh(object.mesh)); | ||
// Remove the 2 starting meshes from the scene | ||
const material = this.mesh.material; | ||
this.mesh.dispose(); | ||
object.mesh.dispose(); | ||
this.mesh = result.toMesh(this.name); | ||
this.mesh = result.toMesh(this.name, material); | ||
return this; | ||
} | ||
/** | ||
* Combine the current object with another object in a boolean operation | ||
* | ||
* @param object The object to combine with the current object | ||
* @returns | ||
*/ | ||
union(object) { | ||
const result = core_1.CSG.FromMesh(this.mesh).union(core_1.CSG.FromMesh(object.mesh)); | ||
// Remove the 2 starting meshes from the scene | ||
const material = this.mesh.material; | ||
this.mesh.dispose(); | ||
object.mesh.dispose(); | ||
this.mesh = result.toMesh(this.name); | ||
this.mesh = result.toMesh(this.name, material); | ||
return this; | ||
@@ -213,6 +268,31 @@ } | ||
exports.Sphere = Sphere; | ||
const defaultExtrusionOptions = { | ||
closeShape: true, | ||
cap: core_1.Mesh.CAP_ALL, | ||
sideOrientation: core_1.Mesh.DOUBLESIDE, | ||
}; | ||
/** | ||
* Extrude a shape along a path | ||
* | ||
* @param options | ||
* @param options.shape The shape to extrude, a list of Vector3 points that | ||
* define the shape in the horizontal plane, i.e. the last coordinate should | ||
* be 0. | ||
* @param options.path The path to extrude the shape along, a list of Vector3 | ||
* points that define the extrusion path. | ||
* | ||
* @example | ||
* new Extrude({ | ||
* shape: [ | ||
* new Vector3(0, 0, 0), | ||
* new Vector3(depth / 2, 0, 0), | ||
* new Vector3(depth / 2, depth / 2, 0), | ||
* ], | ||
* path: [Vector3.Zero(), Vector3.Up().scale(height)], | ||
* }) | ||
*/ | ||
class Extrude extends BaseObject { | ||
constructor(options) { | ||
const { name = 'extrusion', anchor } = options, rest = __rest(options, ["name", "anchor"]); | ||
const mesh = core_1.MeshBuilder.ExtrudeShape(name, rest); | ||
const mesh = core_1.MeshBuilder.ExtrudeShape(name, Object.assign(Object.assign({}, defaultExtrusionOptions), rest)); | ||
super(name, mesh); | ||
@@ -219,0 +299,0 @@ this.anchor = anchor || core_1.Vector3.Zero(); |
110
index.ts
import { CSG, Mesh, MeshBuilder, Vector3 } from '@babylonjs/core' | ||
import { repeatLinear } from './helpers' | ||
import { degToRad, repeatLinear } from './helpers' | ||
@@ -38,2 +38,10 @@ // Anchors | ||
get material() { | ||
return this.mesh.material | ||
} | ||
set material(material) { | ||
this.mesh.material = material | ||
} | ||
/** | ||
@@ -145,2 +153,12 @@ * Move the object to the left by a delta, not an absolute position | ||
alignRight(object: BaseObject) { | ||
const objectRightBoundary = | ||
object.mesh.getBoundingInfo().boundingBox.maximum.x + | ||
object.getBasePosition().x | ||
this.mesh.position.x = objectRightBoundary | ||
return this | ||
} | ||
alignFront(object: BaseObject) { | ||
@@ -166,7 +184,43 @@ const objectFrontBoundary = | ||
alignBottom(object: BaseObject) { | ||
const objectBottomBoundary = | ||
object.mesh.getBoundingInfo().boundingBox.minimum.y + | ||
object.getBasePosition().y | ||
this.mesh.position.y = objectBottomBoundary | ||
return this | ||
} | ||
alignTop(object: BaseObject) { | ||
const objectTopBoundary = | ||
object.mesh.getBoundingInfo().boundingBox.maximum.y + | ||
object.getBasePosition().y | ||
this.mesh.position.y = objectTopBoundary | ||
return this | ||
} | ||
/** | ||
* Rotate the object around an axis | ||
* | ||
* Example: | ||
* object.rotate(Vector3.Up(), 90) | ||
* | ||
* @param axis The axis to rotate the object around | ||
* @param angle The angle in degrees | ||
* @returns | ||
*/ | ||
rotate(axis: Vector3, angle: number) { | ||
this.mesh.rotate(axis, angle) | ||
this.mesh.rotate(axis, degToRad(angle)) | ||
return this | ||
} | ||
/** | ||
* Subtract an object from the current object in a boolean operation | ||
* | ||
* @param object The object to subtract from the current object | ||
* @returns | ||
*/ | ||
subtract(object: BaseObject) { | ||
@@ -176,6 +230,7 @@ const result = CSG.FromMesh(this.mesh).subtract(CSG.FromMesh(object.mesh)) | ||
// Remove the 2 starting meshes from the scene | ||
const material = this.mesh.material | ||
this.mesh.dispose() | ||
object.mesh.dispose() | ||
this.mesh = result.toMesh(this.name) | ||
this.mesh = result.toMesh(this.name, material) | ||
@@ -185,2 +240,8 @@ return this | ||
/** | ||
* Intersect the current object with another object in a boolean operation | ||
* | ||
* @param object The object to intersect with the current object | ||
* @returns | ||
*/ | ||
intersect(object: BaseObject) { | ||
@@ -190,6 +251,7 @@ const result = CSG.FromMesh(this.mesh).intersect(CSG.FromMesh(object.mesh)) | ||
// Remove the 2 starting meshes from the scene | ||
const material = this.mesh.material | ||
this.mesh.dispose() | ||
object.mesh.dispose() | ||
this.mesh = result.toMesh(this.name) | ||
this.mesh = result.toMesh(this.name, material) | ||
@@ -199,2 +261,8 @@ return this | ||
/** | ||
* Combine the current object with another object in a boolean operation | ||
* | ||
* @param object The object to combine with the current object | ||
* @returns | ||
*/ | ||
union(object: BaseObject) { | ||
@@ -204,6 +272,7 @@ const result = CSG.FromMesh(this.mesh).union(CSG.FromMesh(object.mesh)) | ||
// Remove the 2 starting meshes from the scene | ||
const material = this.mesh.material | ||
this.mesh.dispose() | ||
object.mesh.dispose() | ||
this.mesh = result.toMesh(this.name) | ||
this.mesh = result.toMesh(this.name, material) | ||
@@ -274,2 +343,28 @@ return this | ||
const defaultExtrusionOptions = { | ||
closeShape: true, | ||
cap: Mesh.CAP_ALL, | ||
sideOrientation: Mesh.DOUBLESIDE, | ||
} | ||
/** | ||
* Extrude a shape along a path | ||
* | ||
* @param options | ||
* @param options.shape The shape to extrude, a list of Vector3 points that | ||
* define the shape in the horizontal plane, i.e. the last coordinate should | ||
* be 0. | ||
* @param options.path The path to extrude the shape along, a list of Vector3 | ||
* points that define the extrusion path. | ||
* | ||
* @example | ||
* new Extrude({ | ||
* shape: [ | ||
* new Vector3(0, 0, 0), | ||
* new Vector3(depth / 2, 0, 0), | ||
* new Vector3(depth / 2, depth / 2, 0), | ||
* ], | ||
* path: [Vector3.Zero(), Vector3.Up().scale(height)], | ||
* }) | ||
*/ | ||
export class Extrude extends BaseObject { | ||
@@ -283,3 +378,6 @@ constructor( | ||
const { name = 'extrusion', anchor, ...rest } = options | ||
const mesh = MeshBuilder.ExtrudeShape(name, rest) | ||
const mesh = MeshBuilder.ExtrudeShape(name, { | ||
...defaultExtrusionOptions, | ||
...rest, | ||
}) | ||
@@ -286,0 +384,0 @@ super(name, mesh) |
{ | ||
"name": "@shards-design/core", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24477
776