Skip to content

Commit

Permalink
Limits rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomycj committed Jan 16, 2024
1 parent 7fd654c commit 946c00f
Show file tree
Hide file tree
Showing 14 changed files with 1,256 additions and 575 deletions.
75 changes: 68 additions & 7 deletions WebGPU/Cells_3D.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html lang="es">
<head>
<title id="title">Cells 3D - v0.8 Alfa</title>
<title id="title">Cells 3D - v0.8.5 Alfa</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../styles/CellsGPU.css">
<link rel="icon" href="../images/logoBLR.png" type="image/icon type">
Expand Down Expand Up @@ -81,6 +81,62 @@ <h2 hidden style ="text-align: center; margin: 6px;" >

</div>

<div style="position: relative;">
<span id="3doptionstitle" class="categoryspan">3D</span>
<div id="marker4" hidden class="marker"></div>
</div>

<div id="3doptions" hidden>

<div class="options-row hastooltip">
<label for="camspeed" id="camspeedlabel" class="clickable">Rapidez: </label>
<input type="range" id="camspeed" value="20" class="rangeinput" min ="0" max="100" step="0.001"><br>
<!--
<span class="tooltiptext short">
Rapidez de la cámara
</span>
-->
</div>

<div class="options-row hastooltip">
<label for="fov" id="fovlabel" class="clickable">FOV: </label>
<input type="range" id="fov" value="1" class="rangeinput" min ="0" max="3.14" step="0.001"><br>
<!--
<span class="tooltiptext short">
Rapidez de la cámara
</span>
-->
</div>

<div class="options-row">
<label for="xlim">X:</label>
<input type="number" id="xlim" class="numberinput" min="0">

<button id="bordersbutton" class="button">Bordes

</button>

</div>

<div class="options-row">
<label for="ylim">Y:</label>
<input type="number" id="ylim" class="numberinput" min="0">
</div>

<div class="options-row">
<label for="zlim">Z:</label>
<input type="number" id="zlim" class="numberinput" min="0">
</div>

<div class="options-row">
<button class="button disabled hastooltip" id="sceneapply">Aplicar
<span class="tooltiptext">
Aplica configuración 3D
</span>
</button>
</div>
</div>

<div style="position: relative;">
<span id ="ambientoptionstitle" class="categoryspan">Entorno</span>
<div id="marker1" hidden class="marker"></div>
Expand Down Expand Up @@ -115,7 +171,7 @@ <h2 hidden style ="text-align: center; margin: 6px;" >
</div>

<div class="options-row">
<button class="button hastooltip" id="ambientupdate">Aplicar
<button class="button disabled hastooltip" id="ambientupdate">Aplicar
<span class="tooltiptext">
Aplica configuración de entorno
</span>
Expand Down Expand Up @@ -167,6 +223,11 @@ <h2 hidden style ="text-align: center; margin: 6px;" >
<label for="c.cant">Cantidad: </label>
<input type="number" id="c.cant" class="numberinput" min="0" max="100000" step="1">
</div>

<div class="options-row grayed-out">
<span>Cant. actual: </span>
<span id="c.cantnow"> 300</span>
</div>

<div class="options-row hastooltip">
<label for="c.radius">Radio: </label>
Expand Down Expand Up @@ -295,11 +356,11 @@ <h2 hidden style ="text-align: center; margin: 6px;" >
</div>

<div id="debuginfo" hidden>
<p id="canvasinfo" style="margin-top: 8px; margin-bottom: 0;"></p>
<p id="positioninfo" style="margin: 0;"></p>
<p id="performanceinfo" style="margin: 0;"></p>
<p id="canvasinfo" class="info-text"></p>
<p id="positioninfo" class="info-text" ></p>
<p id="performanceinfo" class ="info-text"></p>
<p style="font-size: small; color:rgba(255, 255, 255, 0.5); max-width: 25ch; margin:0; line-height: 2ch;">
Space, Q, E, R, M, I, H, T <br> 3D: LShift, WASDZX, J, L </p>
Space, Q, E, R, M, I, H, T <br> 3D: LShift, WASDZX, J, L, C </p>
</div>
</div>
</div>
Expand All @@ -311,7 +372,7 @@ <h2 hidden style ="text-align: center; margin: 6px;" >

<div id="dialogs">
<dialog id="helpdialog" class="dialogo">
<p style="margin: 0;">Controles: <br>Space, Q, E, R, M, I, H, T, <br>3D: LShift, WASDZX, J, L<br><br></p>
<p style="margin: 0;">Controles: <br>Space, Q, E, R, M, I, H, T, <br>3D: LShift, WASDZX, J, L, C<br><br></p>
<button id="dialogok" class="button">Ok</button>
&nbsp&nbsp&nbsp
<button id="dialognvm" class="button">No volver a mostrar</button>
Expand Down
Empty file added WebGPU/meshes/boxMaker.js
Empty file.
90 changes: 89 additions & 1 deletion WebGPU/modules/misClases.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class Elementary {
this.nombre = nombre;
this.color = color;
this.cantidad = cantidad;
this.cantidadOriginal = cantidad;
this.radio = radio;
this.posiciones = posiciones;
this.velocidades = velocidades;
Expand Down Expand Up @@ -107,7 +108,7 @@ export class Rule {
}
}

export class Setup {
export class SetupOld {
constructor(name, seed, ambient, elementaries, rules) {

this.#validateCanvasDims(ambient.canvasDims);
Expand Down Expand Up @@ -165,6 +166,69 @@ export class Setup {
}
}

export class Setup {
constructor(name, seed, ambient, elementaries, rules, scene) {

this.#validateCanvasDims(ambient.canvasDims);
this.#validateObjectArray(elementaries, Elementary);
this.#validateObjectArray(rules, Rule);

this.name = name;
this.seed = seed;
this.ambient = ambient;
this.elementaries = elementaries;
this.rules = rules;
this.scene = scene;
}
static fromJsonObjectLit(obj) {
return new Setup(
obj.name,
obj.seed,
obj.ambient,
obj.elementaries.map(elem => Elementary.fromJsonObjectLit(elem)),
obj.rules.map(rule => Rule.fromJsonObjectLit(rule)),
obj.scene,
);
}

#validateCanvasDims(dims) {
if (!Number.isInteger(dims[0]) && dims[0] !== "auto" && dims[0] !== "previous") {
throw new Error("Invalid canvas width.");
}
if (!Number.isInteger(dims[1]) && dims[1] !== "auto" && dims[1] !== "previous") {
throw new Error("Invalid canvas height.");
}
}
#validateObjectArray(array, _class) {
for (let obj of array) {
if (!(obj instanceof _class)) throw new Error(`${obj} is not instance of ${_class.name}.`);
}
}
#validateRules(rules) {
for (let rule of rules) {
if (!(rule instanceof Rule)) { throw new Error(`${rule?.ruleName} is not instance of Elementary.`); }
}
}

get asJsonObjectLit() {
return {
name: this.name,
seed: this.seed,
ambient: this.ambient,
elementaries: this.elementaries.map(elem => elem.asJsonObjectLit),
rules: this.rules,
scene: this.scene
}
}
get asJsonObjectLitFull() {
const output = this.asJsonObjectLit;
output.elementaries = this.elementaries.map(elem => elem.asJsonObjectLitFull);
return output;
}
}



/**
* Represents a 4x4 matrix (column-major)
*/
Expand Down Expand Up @@ -452,8 +516,32 @@ export class Mat4 extends Float32Array {
export class Vec3 extends Float32Array {
constructor(v) {
v && v.length == 3 ? super(v) : super(3);

this.default = new Float32Array(this);
//console.log("New object created")
}

set(v) {
this[0] = v[0];
this[1] = v[1];
this[2] = v[2];
return this;
}

setDefault(v) {
this.default[0] = v[0];
this.default[1] = v[1];
this.default[2] = v[2];
return this;
}

toDefault() {
this[0] = this.default[0];
this[1] = this.default[1];
this[2] = this.default[2];
return this;
}

magnitude() {
return Math.hypot(this[0], this[1], this[2]);
}
Expand Down
5 changes: 3 additions & 2 deletions WebGPU/modules/misFunciones.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function inicializarCells(showTitle=true){
context.configure({
device: device,
format: canvasFormat, //es el texture format que el context debería usar
alphaMode: "premultiplied", // no estoy seguro si hace falta
alphaMode: "premultiplied", // "opaque" by default, which ignores alpha
});

return [device, canvas, canvasFormat, context, timer];
Expand All @@ -106,4 +106,5 @@ export function autoCanvasDims(container, dims="widthheight") {
default:
throw new Error("dims must be 'width', 'height', or their concatenation");
}
}
}

Loading

0 comments on commit 946c00f

Please sign in to comment.