-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshapes.js
More file actions
183 lines (159 loc) · 5.98 KB
/
Copy pathshapes.js
File metadata and controls
183 lines (159 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import * as THREE from 'three'
function createMaterials (colors) {
return [
new THREE.MeshBasicMaterial({ color: colors[0] }), // right
new THREE.MeshBasicMaterial({ color: colors[1] }), // left
new THREE.MeshBasicMaterial({ color: colors[2] }), // top
new THREE.MeshBasicMaterial({ color: colors[0] }), // bottom
new THREE.MeshBasicMaterial({ color: colors[1] }), // front
new THREE.MeshBasicMaterial({ color: colors[2] }) // back
]
}
function createCube (
group,
materials,
x,
y,
z,
scaleX = 1,
scaleY = 1,
scaleZ = 1,
rotationY = 0
) {
const geometry = new THREE.BoxGeometry(1, 1, 1)
const cube = new THREE.Mesh(geometry, materials)
cube.position.set(x, y, z)
cube.scale.set(scaleX, scaleY, scaleZ)
cube.rotation.y = rotationY
group.add(cube)
return cube
}
export function generateGrid (group, colors, config) {
const materials = createMaterials(colors)
const width = (config.cols - 1) * config.spacing
const depth = (config.rows - 1) * config.spacing
const startX = -width / 2
const startZ = -depth / 2
for (let row = 0; row < config.rows; row++) {
for (let col = 0; col < config.cols; col++) {
const x = startX + col * config.spacing
const z = startZ + row * config.spacing
createCube(group, materials, x, 0, z, config.blockWidth, config.blockHeight, config.blockDepth)
}
}
}
export function generateRotor (group, colors, config) {
// Rotor like a cog:
// - Outer tips (right/left faces): colors[0]
// - Inside of wedges (front/back sides): colors[1]
// - Top/bottom: colors[2]
const materials = [
new THREE.MeshBasicMaterial({ color: colors[0] }), // right - outer tip
new THREE.MeshBasicMaterial({ color: colors[0] }), // left - inner tip
new THREE.MeshBasicMaterial({ color: colors[2] }), // top
new THREE.MeshBasicMaterial({ color: colors[2] }), // bottom
new THREE.MeshBasicMaterial({ color: colors[1] }), // front - side of wedge
new THREE.MeshBasicMaterial({ color: colors[1] }) // back - side of wedge
]
for (let i = 0; i < config.count / 2; i++) {
const angle = (i / config.count) * Math.PI * 2
createCube(
group,
materials,
Math.cos(angle) * config.radius,
0,
Math.sin(angle) * config.radius,
config.blockWidth,
config.blockHeight,
config.blockDepth,
-angle + Math.PI / 2
)
}
}
export function generateZiggurat (group, colors, config) {
const materials = createMaterials(colors)
let totalHeight = 0
for (let i = 0; i < config.tiers; i++) {
totalHeight += config.blockHeight
}
const startY = -totalHeight / 2
let currentY = startY
for (let i = 0; i < config.tiers; i++) {
const ratio = config.tiers > 1 ? (config.tiers - 1 - i) / (config.tiers - 1) : 0
const size = 1 + (config.baseSize - 1) * ratio
const finalWidth = size * config.blockWidth
const finalDepth = size * config.blockDepth
const yPos = currentY + config.blockHeight / 2
createCube(group, materials, 0, yPos, 0, finalWidth, config.blockHeight, finalDepth)
currentY += config.blockHeight
}
}
export function generateStack (group, colors, config) {
const materials = createMaterials(colors)
const totalHeight = config.count * (config.blockHeight + config.spacing)
for (let i = 0; i < config.count; i++) {
const y = i * (config.blockHeight + config.spacing) - totalHeight / 2
const rotation = 0
createCube(group, materials, 0, y, 0, config.blockWidth, config.blockHeight, config.blockDepth, rotation)
}
}
export function generateSpire (group, colors, config) {
// Spire rotates so all 4 sides are visible - make sure they have good color variation
const materials = [
new THREE.MeshBasicMaterial({ color: colors[0] }), // right
new THREE.MeshBasicMaterial({ color: colors[1] }), // left
new THREE.MeshBasicMaterial({ color: colors[2] }), // top
new THREE.MeshBasicMaterial({ color: colors[2] }), // bottom (same as top)
new THREE.MeshBasicMaterial({ color: colors[0] }), // front (same as right)
new THREE.MeshBasicMaterial({ color: colors[1] }) // back (same as left)
]
const totalHeight = config.count * (config.blockHeight + config.spacing)
for (let i = 0; i < config.count; i++) {
const y = i * (config.blockHeight + config.spacing) - totalHeight / 2
const rotation = i * config.twistPerBlock
createCube(group, materials, 0, y, 0, config.blockWidth, config.blockHeight, config.blockDepth, rotation)
}
}
export function generateHelix (group, colors, config) {
// Helix rotates so all 4 sides are visible - make sure they have good color variation
const materials = [
new THREE.MeshBasicMaterial({ color: colors[0] }), // right
new THREE.MeshBasicMaterial({ color: colors[1] }), // left
new THREE.MeshBasicMaterial({ color: colors[2] }), // top
new THREE.MeshBasicMaterial({ color: colors[2] }), // bottom (same as top)
new THREE.MeshBasicMaterial({ color: colors[0] }), // front (same as right)
new THREE.MeshBasicMaterial({ color: colors[1] }) // back (same as left)
]
const totalHeight = config.count * (config.blockHeight + config.spacing)
for (let i = 0; i < config.count; i++) {
const y = i * (config.blockHeight + config.spacing) - totalHeight / 2
const rotation = i * config.twistPerBlock
createCube(group, materials, 0, y, 0, config.blockWidth, config.blockHeight, config.blockDepth, rotation)
}
}
export function generateShape (shapeConfig) {
const group = new THREE.Group()
const config = shapeConfig.config
const colors = shapeConfig.palette.colors
switch (config.shape) {
case 'grid':
generateGrid(group, colors, config)
break
case 'rotor':
generateRotor(group, colors, config)
break
case 'ziggurat':
generateZiggurat(group, colors, config)
break
case 'stack':
generateStack(group, colors, config)
break
case 'spire':
generateSpire(group, colors, config)
break
case 'helix':
generateHelix(group, colors, config)
break
}
return group
}