Skip to content

Commit 1372f71

Browse files
committed
Improve createRandomTree leaf node attachments
1 parent 92428e1 commit 1372f71

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/utils/createRandomTree.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ const LEAVES = {
194194
[SpeciesHash.Walnut]: WALNUT_LEAVES
195195
};
196196

197+
const LEAF_SCALE = {
198+
[SpeciesHash.Ash]: 4,
199+
[SpeciesHash.Birch]: 4,
200+
[SpeciesHash.Oak]: 4,
201+
[SpeciesHash.Redwood]: 0.5,
202+
[SpeciesHash.Standard]: 4,
203+
[SpeciesHash.Walnut]: 4
204+
};
205+
197206
const compositionMap: CompositionMap = {
198207
Woodcut_B0_B0: { Top_8056: BRANCHES },
199208
Woodcut_B0_B0_S15: { Top_53706: BRANCHES, Stick_53710: STICKS },
@@ -297,17 +306,18 @@ const populateSegment = (
297306
const createChildPrefab = (speciesHash: SpeciesHash, segment: Segment, parentHash: number = 0): ChildPrefab => {
298307
const [segmentName, connectionMap] = Object.entries(segment)[0] as [SegmentName, Connections];
299308
const connections = Object.entries(connectionMap);
309+
const rotation = randomRotation();
300310

301311
return {
302312
parentHash,
303313
prefab: {
304314
prefabObject: {
305315
hash: Prefab[segmentName].hash,
306-
rotation: randomRotation()
316+
rotation
307317
},
308318
childPrefabs:
309319
connections.length === 0
310-
? attachLeafNode(speciesHash)
320+
? attachLeafNode(speciesHash, rotation)
311321
: connections.map(([embeddedEntity, childSegment]) =>
312322
// After several hours I can't figure out the proper way to access this object and I cbf anymore.
313323
createChildPrefab(
@@ -320,7 +330,10 @@ const createChildPrefab = (speciesHash: SpeciesHash, segment: Segment, parentHas
320330
};
321331
};
322332

323-
const attachLeafNode = (speciesHash: SpeciesHash): ChildPrefab[] => {
333+
const attachLeafNode = (
334+
speciesHash: SpeciesHash,
335+
rotation: { x: number; y: number; z: number; w: number }
336+
): ChildPrefab[] => {
324337
const prefab = pickRandom(LEAVES[speciesHash]);
325338

326339
return [
@@ -329,12 +342,13 @@ const attachLeafNode = (speciesHash: SpeciesHash): ChildPrefab[] => {
329342
prefab: {
330343
prefabObject: {
331344
hash: Prefab[prefab].hash,
332-
position: {
333-
x: 0,
334-
y: 0.25,
335-
z: 0
345+
rotation: {
346+
x: -rotation.x,
347+
y: -rotation.y,
348+
z: -rotation.z,
349+
w: -rotation.w
336350
},
337-
scale: 1 + Math.random() * 0.4
351+
scale: LEAF_SCALE[speciesHash] + Math.random() * 0.4
338352
}
339353
}
340354
}

0 commit comments

Comments
 (0)