Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions Apps/Playground/Scripts/experience.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,53 @@ if (logPerf) {
setTimeout(() => BABYLON.Tools.EndPerformanceCounter("test counter"), 500);
}

function CreateBoxAsync(scene) {
BABYLON.Mesh.CreateBox("box1", 0.2, scene);
function CreateGSAsync(scene) {
var gs = new BABYLON.GaussianSplattingMesh("GS", undefined, scene, true);

var generateGS = function (time) {
// size of a single splat, int bytes
const rowLength = 3 * 4 + 3 * 4 + 4 + 4;

// chunck size of splats
const b = 100;
const splatCount = b * b;

const uBuffer = new Uint8Array(splatCount * rowLength);
const fBuffer = new Float32Array(uBuffer.buffer);

for (let j = 0; j < b; j++) {
for (let ji = 0; ji < b; ji++) {
const i = ji + j * b;
// position
x = j * 0.1 - 5;
y = -Math.sin(time + ji * 0.04 + j * 0.02) * 1 - 1;

fBuffer[8 * i + 0] = Math.cos(time) * x + Math.sin(time) * y;
fBuffer[8 * i + 1] = Math.sin(time) * x - Math.cos(time) * y;
fBuffer[8 * i + 2] = ji * 0.1 - 5;

// size
fBuffer[8 * i + 3 + 0] = 0.1;
fBuffer[8 * i + 3 + 1] = 0.1;
fBuffer[8 * i + 3 + 2] = 0.1;

// orientation
uBuffer[32 * i + 28 + 1] = 128;
uBuffer[32 * i + 28 + 2] = 128;
uBuffer[32 * i + 28 + 3] = 128;
uBuffer[32 * i + 28 + 0] = 255;

// color
uBuffer[32 * i + 24 + 0] = Math.cos((ji + time * 3) * 0.2) * 127 + 128;
uBuffer[32 * i + 24 + 1] = Math.cos((j + time * 4) * 0.3) * 127 + 128;
uBuffer[32 * i + 24 + 2] = Math.sin((j + ji + time * 2) * 0.3) * 127 + 128;
uBuffer[32 * i + 24 + 3] = 255;
}
}
gs.updateData(uBuffer);
};
generateGS(0);

return Promise.resolve();
}

Expand All @@ -51,7 +96,7 @@ function CreateSpheresAsync(scene) {
const engine = new BABYLON.NativeEngine();
const scene = new BABYLON.Scene(engine);

CreateBoxAsync(scene).then(function () {
CreateGSAsync(scene).then(function () {
//CreateSpheresAsync(scene).then(function () {
//BABYLON.AppendSceneAsync("https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Box/glTF/Box.gltf").then(function () {
//BABYLON.AppendSceneAsync("https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BoxTextured/glTF/BoxTextured.gltf").then(function () {
Expand Down
Loading