mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-06-05 10:34:09 +02:00
Update randomBooks.ts
This commit is contained in:
@@ -7,8 +7,6 @@ import * as BABYLON from '@babylonjs/core';
|
|||||||
import seedrandom from 'seedrandom';
|
import seedrandom from 'seedrandom';
|
||||||
import { defineObject, WORLD_SCALE } from '../engine.js';
|
import { defineObject, WORLD_SCALE } from '../engine.js';
|
||||||
|
|
||||||
const randomRange = (min: number, max: number) => Math.random() * (max - min) + min;
|
|
||||||
|
|
||||||
const remap = (value: number, fromMin: number, fromMax: number, toMin: number, toMax: number) => {
|
const remap = (value: number, fromMin: number, fromMax: number, toMin: number, toMax: number) => {
|
||||||
return toMin + ((value - fromMin) / (fromMax - fromMin)) * (toMax - toMin);
|
return toMin + ((value - fromMin) / (fromMax - fromMin)) * (toMax - toMin);
|
||||||
};
|
};
|
||||||
@@ -22,6 +20,13 @@ export const randomBooks = defineObject({
|
|||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
label: 'Plain cover',
|
label: 'Plain cover',
|
||||||
},
|
},
|
||||||
|
count: {
|
||||||
|
type: 'range',
|
||||||
|
label: 'Count',
|
||||||
|
min: 1,
|
||||||
|
max: 30,
|
||||||
|
step: 1,
|
||||||
|
},
|
||||||
seed: {
|
seed: {
|
||||||
type: 'range',
|
type: 'range',
|
||||||
label: 'Seed',
|
label: 'Seed',
|
||||||
@@ -32,6 +37,7 @@ export const randomBooks = defineObject({
|
|||||||
},
|
},
|
||||||
default: {
|
default: {
|
||||||
plainCover: false,
|
plainCover: false,
|
||||||
|
count: 10,
|
||||||
seed: 0,
|
seed: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -45,7 +51,6 @@ export const randomBooks = defineObject({
|
|||||||
bodyMesh.material.albedoTexture = tex;
|
bodyMesh.material.albedoTexture = tex;
|
||||||
|
|
||||||
const TEXTURE_DIVISION = 8;
|
const TEXTURE_DIVISION = 8;
|
||||||
const count = 10;
|
|
||||||
let bookMeshes: BABYLON.Mesh[] = [];
|
let bookMeshes: BABYLON.Mesh[] = [];
|
||||||
|
|
||||||
const gen = () => {
|
const gen = () => {
|
||||||
@@ -55,10 +60,11 @@ export const randomBooks = defineObject({
|
|||||||
bookMeshes = [];
|
bookMeshes = [];
|
||||||
|
|
||||||
const rng = seedrandom(options.seed === 0 ? id : options.seed.toString());
|
const rng = seedrandom(options.seed === 0 ? id : options.seed.toString());
|
||||||
|
const randomRange = (min: number, max: number) => rng() * (max - min) + min;
|
||||||
|
|
||||||
let accumulatedPos = 0;
|
let accumulatedPos = 0;
|
||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < options.count; i++) {
|
||||||
const mesh = bodyMesh.clone();
|
const mesh = bodyMesh.clone();
|
||||||
mesh.isVisible = true;
|
mesh.isVisible = true;
|
||||||
mesh.setEnabled(true);
|
mesh.setEnabled(true);
|
||||||
@@ -90,12 +96,14 @@ export const randomBooks = defineObject({
|
|||||||
const gap = 0.25;
|
const gap = 0.25;
|
||||||
mesh.position.x = (accumulatedPos + (thicknessCm / 2)) / WORLD_SCALE;
|
mesh.position.x = (accumulatedPos + (thicknessCm / 2)) / WORLD_SCALE;
|
||||||
mesh.position.z = widthCm / 2 / WORLD_SCALE;
|
mesh.position.z = widthCm / 2 / WORLD_SCALE;
|
||||||
|
mesh.refreshBoundingInfo();
|
||||||
|
mesh.computeWorldMatrix(true);
|
||||||
accumulatedPos += thicknessCm + gap;
|
accumulatedPos += thicknessCm + gap;
|
||||||
bookMeshes.push(mesh);
|
bookMeshes.push(mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
// centering
|
// centering
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < options.count; i++) {
|
||||||
bookMeshes[i].position.x -= accumulatedPos / 2 / WORLD_SCALE;
|
bookMeshes[i].position.x -= accumulatedPos / 2 / WORLD_SCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +121,7 @@ export const randomBooks = defineObject({
|
|||||||
onOptionsUpdated: ([k, v]) => {
|
onOptionsUpdated: ([k, v]) => {
|
||||||
switch (k) {
|
switch (k) {
|
||||||
case 'seed': gen(); break;
|
case 'seed': gen(); break;
|
||||||
|
case 'count': gen(); break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
interactions: {},
|
interactions: {},
|
||||||
|
|||||||
Reference in New Issue
Block a user