357 lines
		
	
	
		
			451 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			357 lines
		
	
	
		
			451 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
---
 | 
						||
title: "patternTransform"
 | 
						||
excerpt: "A linear pattern on a 3D solid."
 | 
						||
layout: manual
 | 
						||
---
 | 
						||
 | 
						||
A linear pattern on a 3D solid.
 | 
						||
 | 
						||
Each repetition of the pattern can be transformed (e.g. scaled, translated, hidden, etc).
 | 
						||
 | 
						||
```js
 | 
						||
patternTransform(num_repetitions: u32, transform_function: FunctionParam, extrude_group_set: ExtrudeGroupSet) -> [ExtrudeGroup]
 | 
						||
```
 | 
						||
 | 
						||
### Examples
 | 
						||
 | 
						||
```js
 | 
						||
// Parameters
 | 
						||
const r = 50 // base radius
 | 
						||
const h = 10 // layer height
 | 
						||
const t = 0.005 // taper factor [0-1)
 | 
						||
// Defines how to modify each layer of the vase.
 | 
						||
// Each replica is shifted up the Z axis, and has a smoothly-varying radius
 | 
						||
fn transform = (replicaId) => {
 | 
						||
  let scale = r * abs(1 - (t * replicaId)) * (5 + cos(replicaId / 8))
 | 
						||
  return {
 | 
						||
  translate: [0, 0, replicaId * 10],
 | 
						||
  scale: [scale, scale, 0]
 | 
						||
}
 | 
						||
}
 | 
						||
// Each layer is just a pretty thin cylinder.
 | 
						||
fn layer = () => {
 | 
						||
  return startSketchOn("XY")
 | 
						||
  // or some other plane idk
 | 
						||
  |> circle([0, 0], 1, %, $tag1)
 | 
						||
  |> extrude(h, %)
 | 
						||
}
 | 
						||
// The vase is 100 layers tall.
 | 
						||
// The 100 layers are replica of each other, with a slight transformation applied to each.
 | 
						||
let vase = layer()
 | 
						||
  |> patternTransform(100, transform, %)
 | 
						||
```
 | 
						||
 | 
						||

 | 
						||
 | 
						||
### Arguments
 | 
						||
 | 
						||
* `num_repetitions`: `u32` (REQUIRED)
 | 
						||
* `transform_function`: `FunctionParam` (REQUIRED)
 | 
						||
* `extrude_group_set`: `ExtrudeGroupSet` - A extrude group or a group of extrude groups. (REQUIRED)
 | 
						||
```js
 | 
						||
{
 | 
						||
	// The id of the extrusion end cap
 | 
						||
	endCapId: uuid,
 | 
						||
	// Chamfers or fillets on this extrude group.
 | 
						||
	filletOrChamfers: [{
 | 
						||
	// The engine id of the edge to fillet.
 | 
						||
	edge_id: uuid,
 | 
						||
	// The id of the engine command that called this fillet.
 | 
						||
	id: uuid,
 | 
						||
	radius: number,
 | 
						||
	type: "fillet",
 | 
						||
} |
 | 
						||
{
 | 
						||
	// The engine id of the edge to chamfer.
 | 
						||
	edge_id: uuid,
 | 
						||
	// The id of the engine command that called this chamfer.
 | 
						||
	id: uuid,
 | 
						||
	length: number,
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	type: "chamfer",
 | 
						||
}],
 | 
						||
	// The height of the extrude group.
 | 
						||
	height: number,
 | 
						||
	// The id of the extrude group.
 | 
						||
	id: uuid,
 | 
						||
	// The sketch group.
 | 
						||
	sketchGroup: {
 | 
						||
	// The id of the sketch group.
 | 
						||
	id: uuid,
 | 
						||
	// What the sketch is on (can be a plane or a face).
 | 
						||
	on: {
 | 
						||
	// The id of the plane.
 | 
						||
	id: uuid,
 | 
						||
	// Origin of the plane.
 | 
						||
	origin: {
 | 
						||
	x: number,
 | 
						||
	y: number,
 | 
						||
	z: number,
 | 
						||
},
 | 
						||
	type: "plane",
 | 
						||
	// Type for a plane.
 | 
						||
	value: "XY" | "XZ" | "YZ" | "Custom",
 | 
						||
	// What should the plane’s X axis be?
 | 
						||
	xAxis: {
 | 
						||
	x: number,
 | 
						||
	y: number,
 | 
						||
	z: number,
 | 
						||
},
 | 
						||
	// What should the plane’s Y axis be?
 | 
						||
	yAxis: {
 | 
						||
	x: number,
 | 
						||
	y: number,
 | 
						||
	z: number,
 | 
						||
},
 | 
						||
	// The z-axis (normal).
 | 
						||
	zAxis: {
 | 
						||
	x: number,
 | 
						||
	y: number,
 | 
						||
	z: number,
 | 
						||
},
 | 
						||
} |
 | 
						||
{
 | 
						||
	// The extrude group the face is on.
 | 
						||
	extrudeGroup: {
 | 
						||
	// The id of the extrusion end cap
 | 
						||
	endCapId: uuid,
 | 
						||
	// Chamfers or fillets on this extrude group.
 | 
						||
	filletOrChamfers: [{
 | 
						||
	// The engine id of the edge to fillet.
 | 
						||
	edge_id: uuid,
 | 
						||
	// The id of the engine command that called this fillet.
 | 
						||
	id: uuid,
 | 
						||
	radius: number,
 | 
						||
	type: "fillet",
 | 
						||
} |
 | 
						||
{
 | 
						||
	// The engine id of the edge to chamfer.
 | 
						||
	edge_id: uuid,
 | 
						||
	// The id of the engine command that called this chamfer.
 | 
						||
	id: uuid,
 | 
						||
	length: number,
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	type: "chamfer",
 | 
						||
}],
 | 
						||
	// The height of the extrude group.
 | 
						||
	height: number,
 | 
						||
	// The id of the extrude group.
 | 
						||
	id: uuid,
 | 
						||
	// The sketch group.
 | 
						||
	sketchGroup: SketchGroup,
 | 
						||
	// The id of the extrusion start cap
 | 
						||
	startCapId: uuid,
 | 
						||
	// The extrude surfaces.
 | 
						||
	value: [{
 | 
						||
	// The face id for the extrude plane.
 | 
						||
	faceId: uuid,
 | 
						||
	// The id of the geometry.
 | 
						||
	id: uuid,
 | 
						||
	// The source range.
 | 
						||
	sourceRange: [number, number],
 | 
						||
	// The tag.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	type: "extrudePlane",
 | 
						||
} |
 | 
						||
{
 | 
						||
	// The face id for the extrude plane.
 | 
						||
	faceId: uuid,
 | 
						||
	// The id of the geometry.
 | 
						||
	id: uuid,
 | 
						||
	// The source range.
 | 
						||
	sourceRange: [number, number],
 | 
						||
	// The tag.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	type: "extrudeArc",
 | 
						||
}],
 | 
						||
},
 | 
						||
	// The id of the face.
 | 
						||
	id: uuid,
 | 
						||
	type: "face",
 | 
						||
	// The tag of the face.
 | 
						||
	value: string,
 | 
						||
	// What should the face’s X axis be?
 | 
						||
	xAxis: {
 | 
						||
	x: number,
 | 
						||
	y: number,
 | 
						||
	z: number,
 | 
						||
},
 | 
						||
	// What should the face’s Y axis be?
 | 
						||
	yAxis: {
 | 
						||
	x: number,
 | 
						||
	y: number,
 | 
						||
	z: number,
 | 
						||
},
 | 
						||
	// The z-axis (normal).
 | 
						||
	zAxis: {
 | 
						||
	x: number,
 | 
						||
	y: number,
 | 
						||
	z: number,
 | 
						||
},
 | 
						||
},
 | 
						||
	// The starting path.
 | 
						||
	start: {
 | 
						||
	// The from point.
 | 
						||
	from: [number, number],
 | 
						||
	// The tag of the path.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	// The to point.
 | 
						||
	to: [number, number],
 | 
						||
},
 | 
						||
	// The paths in the sketch group.
 | 
						||
	value: [{
 | 
						||
	// The from point.
 | 
						||
	from: [number, number],
 | 
						||
	// The tag of the path.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	// The to point.
 | 
						||
	to: [number, number],
 | 
						||
	type: "ToPoint",
 | 
						||
} |
 | 
						||
{
 | 
						||
	// arc's direction
 | 
						||
	ccw: string,
 | 
						||
	// the arc's center
 | 
						||
	center: [number, number],
 | 
						||
	// The from point.
 | 
						||
	from: [number, number],
 | 
						||
	// The tag of the path.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	// The to point.
 | 
						||
	to: [number, number],
 | 
						||
	type: "TangentialArcTo",
 | 
						||
} |
 | 
						||
{
 | 
						||
	// The from point.
 | 
						||
	from: [number, number],
 | 
						||
	// The tag of the path.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	// The to point.
 | 
						||
	to: [number, number],
 | 
						||
	type: "TangentialArc",
 | 
						||
} |
 | 
						||
{
 | 
						||
	// The from point.
 | 
						||
	from: [number, number],
 | 
						||
	// The tag of the path.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	// The to point.
 | 
						||
	to: [number, number],
 | 
						||
	type: "Horizontal",
 | 
						||
	// The x coordinate.
 | 
						||
	x: number,
 | 
						||
} |
 | 
						||
{
 | 
						||
	// The from point.
 | 
						||
	from: [number, number],
 | 
						||
	// The tag of the path.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	// The to point.
 | 
						||
	to: [number, number],
 | 
						||
	type: "AngledLineTo",
 | 
						||
	// The x coordinate.
 | 
						||
	x: number,
 | 
						||
	// The y coordinate.
 | 
						||
	y: number,
 | 
						||
} |
 | 
						||
{
 | 
						||
	// The from point.
 | 
						||
	from: [number, number],
 | 
						||
	// The tag of the path.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	// The to point.
 | 
						||
	to: [number, number],
 | 
						||
	type: "Base",
 | 
						||
}],
 | 
						||
},
 | 
						||
	// The id of the extrusion start cap
 | 
						||
	startCapId: uuid,
 | 
						||
	type: "extrudeGroup",
 | 
						||
	// The extrude surfaces.
 | 
						||
	value: [{
 | 
						||
	// The face id for the extrude plane.
 | 
						||
	faceId: uuid,
 | 
						||
	// The id of the geometry.
 | 
						||
	id: uuid,
 | 
						||
	// The source range.
 | 
						||
	sourceRange: [number, number],
 | 
						||
	// The tag.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	type: "extrudePlane",
 | 
						||
} |
 | 
						||
{
 | 
						||
	// The face id for the extrude plane.
 | 
						||
	faceId: uuid,
 | 
						||
	// The id of the geometry.
 | 
						||
	id: uuid,
 | 
						||
	// The source range.
 | 
						||
	sourceRange: [number, number],
 | 
						||
	// The tag.
 | 
						||
	tag: {
 | 
						||
	end: number,
 | 
						||
	start: number,
 | 
						||
	value: string,
 | 
						||
},
 | 
						||
	type: "extrudeArc",
 | 
						||
}],
 | 
						||
} |
 | 
						||
{
 | 
						||
	type: "extrudeGroups",
 | 
						||
}
 | 
						||
```
 | 
						||
 | 
						||
### Returns
 | 
						||
 | 
						||
`[ExtrudeGroup]`
 | 
						||
 | 
						||
 | 
						||
 |