generated from BarthPaleologue/babylonjs-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9671c5
commit 2453022
Showing
4 changed files
with
56 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// remap a value comprised between low1 and high1 to a value between low2 and high2 | ||
float remap(float value, float low1, float high1, float low2, float high2) { | ||
return low2 + (value - low1) * (high2 - low2) / (high1 - low1); | ||
} | ||
|
||
#pragma glslify: export(remap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {Vector3} from "@babylonjs/core/Maths/math.vector"; | ||
import {Mesh} from "@babylonjs/core/Meshes/mesh"; | ||
|
||
export function makeInstancePatch(instance: Mesh, patchPosition: Vector3, patchSize: number, patchResolution: number) { | ||
const cellSize = patchSize / patchResolution; | ||
for(let x = 0; x < patchResolution; x++) { | ||
for(let z = 0; z < patchResolution; z++) { | ||
const blade = instance.createInstance(`blade${x}${z}`); | ||
const randomCellPositionX = Math.random() * cellSize; | ||
const randomCellPositionZ = Math.random() * cellSize; | ||
blade.position.x = patchPosition.x + (x / patchResolution) * patchSize - patchSize / 2 + randomCellPositionX; | ||
blade.position.z = patchPosition.z + (z / patchResolution) * patchSize - patchSize / 2 + randomCellPositionZ; | ||
blade.rotation.y = Math.random() * 2 * Math.PI; | ||
} | ||
} | ||
} |