Skip to content
Merged
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
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ jobs:
- name: Run e2e tests
run: deno task test test/e2e

misc-tests:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8

- name: Cache
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306
with:
path: |
deno_dir
.denoTypes
npm_packages
studio/deps
key: ci-${{ github.run_id }}_${{ github.run_attempt }}
restore-keys: ci-

- name: Setup Deno
uses: denoland/setup-deno@041b854f97b325bd60e53e9dc2de9cb9f9ac0cba
with:
deno-version: ${{ env.DENO_VERSION }}

- name: Run misc tests
run: deno task test test/misc

build:
if: ${{ github.event_name != 'pull_request' }}
uses: ./.github/workflows/build.yml
8 changes: 8 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ if (Deno.args.length > 0 && !Deno.args[0].startsWith("-")) {
const needsUnitTests = !filteredTests || filteredTests.startsWith("test/unit");
const needsMinifiedTests = !filteredTests || filteredTests.startsWith("test/minified");
const needsE2eTests = !filteredTests || filteredTests.startsWith("test/e2e");
const needsMiscTests = !filteredTests || filteredTests.startsWith("test/misc");

await dev({
needsDependencies: needsE2eTests,
Expand Down Expand Up @@ -198,6 +199,13 @@ if (needsE2eTests) {
testCommands.push(cmd);
}

// Misc tests
if (needsMiscTests) {
const cmd = [Deno.execPath(), "test", "--no-check", "--allow-env", "--allow-read", "--allow-net", "--allow-ffi", "--allow-sys"];
cmd.push(filteredTests || "test/misc/");
testCommands.push(cmd);
}

for (const cmd of testCommands) {
console.log(`Running: ${cmd.join(" ")}`);
const [exec, ...args] = cmd;
Expand Down
80 changes: 40 additions & 40 deletions src/assets/assetLoaderTypes/AssetLoaderTypeEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,52 @@ import { StorageType, binaryToObject, binaryToObjectWithAssetLoader, createObjec
* @property {import("../../mod.js").StorageTypeEnum["UUID"]} uuid
* @property {import("../../mod.js").StorageTypeEnum["ARRAY_BUFFER"]} propertyValues
*/

/**
* @typedef EntityBinaryStructureInline
* @property {import("../../mod.js").StorageTypeEnum["STRING"]} name
* @property {[import("../../mod.js").StorageTypeEnum["FLOAT32"]]} matrix
* @property {[EntityBinaryStructure]} children
* @property {[EntityComponentStructure]} components
*/

/** @type {EntityBinaryStructureInline} */
const entityBinaryStructureInline = {
name: StorageType.STRING,
matrix: [StorageType.FLOAT32],
children: /** @type {any} */ ([]),
components: [
{
uuid: StorageType.UUID,
propertyValues: StorageType.ARRAY_BUFFER,
},
],
};

/**
* @typedef EntityBinaryStructureAsset
* @property {import("../../mod.js").StorageTypeEnum["UUID"]} assetUuid
*/

/** @type {EntityBinaryStructureAsset} */
const entityBinaryStructureAsset = {
assetUuid: StorageType.UUID,
};

/**
* @typedef {[import("../../mod.js").StorageTypeEnum["UNION_ARRAY"], EntityBinaryStructureAsset, EntityBinaryStructureInline]} EntityBinaryStructure
*/

/** @type {EntityBinaryStructure} */
const entityBinaryStructure = [
StorageType.UNION_ARRAY,
entityBinaryStructureAsset,
entityBinaryStructureInline,
];

entityBinaryStructureInline.children[0] = entityBinaryStructure;

/** @typedef {import("../../util/binarySerializationTypes.ts").StructureToObject<typeof entityBinaryStructure>} EnityData */
/**
* @typedef EntityBinaryStructureInline
* @property {import("../../mod.js").StorageTypeEnum["STRING"]} name
* @property {[import("../../mod.js").StorageTypeEnum["FLOAT32"]]} matrix
* @property {[EntityBinaryStructure]} children
* @property {[EntityComponentStructure]} components
*/
/** @typedef {import("../../util/binarySerializationTypes.ts").StructureToObject<EntityBinaryStructure>} EnityData */

function createEntityBinaryStructureInline() {
/** @type {EntityBinaryStructureInline} */
const entityBinaryStructureInline = {
name: StorageType.STRING,
matrix: [StorageType.FLOAT32],
children: /** @type {any} */ ([]),
components: [
{
uuid: StorageType.UUID,
propertyValues: StorageType.ARRAY_BUFFER,
},
],
};

/** @type {EntityBinaryStructureAsset} */
const entityBinaryStructureAsset = {
assetUuid: StorageType.UUID,
};

/** @type {EntityBinaryStructure} */
const entityBinaryStructure = [
StorageType.UNION_ARRAY,
entityBinaryStructureAsset,
entityBinaryStructureInline,
];

entityBinaryStructureInline.children[0] = entityBinaryStructure;

return entityBinaryStructureInline;
}

const entityBinaryNameIds = {
name: 1,
Expand Down Expand Up @@ -91,7 +91,7 @@ export class AssetLoaderTypeEntity extends AssetLoaderType {

static get entityBinaryFormat() {
return createObjectToBinaryOptions({
structure: entityBinaryStructureInline,
structure: createEntityBinaryStructureInline(),
nameIds: entityBinaryNameIds,
});
}
Expand Down
16 changes: 8 additions & 8 deletions src/gizmos/gizmos/RotationGizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Vec3 } from "../../math/Vec3.js";
import { Entity } from "../../core/Entity.js";
import { Gizmo } from "./Gizmo.js";
import { MeshComponent } from "../../components/builtIn/MeshComponent.js";
import { blueColor, greenColor, hoverColor, redColor } from "./colors.js";
import { createBlueColor, createGreenColor, createHoverColor, createRedColor } from "./colors.js";
import { Sphere } from "../../math/shapes/Sphere.js";
import { Quat } from "../../math/Quat.js";

Expand All @@ -24,9 +24,9 @@ export class RotationGizmo extends Gizmo {
constructor(...args) {
super(...args);

this.xCircleColor = new Vec3(redColor);
this.yCircleColor = new Vec3(greenColor);
this.zCircleColor = new Vec3(blueColor);
this.xCircleColor = createRedColor();
this.yCircleColor = createGreenColor();
this.zCircleColor = createBlueColor();

/** @type {Set<RotationGizmoDragCallback>} */
this.onDragCbs = new Set();
Expand Down Expand Up @@ -62,21 +62,21 @@ export class RotationGizmo extends Gizmo {
axis: new Vec3(1, 0, 0),
raycastScale: new Vec3(0.1, 1.1, 1.1),
colorInstance: this.xCircleColor,
defaultColor: redColor,
defaultColor: createRedColor(),
});

this.createCircle({
axis: new Vec3(0, 1, 0),
raycastScale: new Vec3(1.1, 0.1, 1.1),
colorInstance: this.yCircleColor,
defaultColor: greenColor,
defaultColor: createGreenColor(),
});

this.createCircle({
axis: new Vec3(0, 0, 1),
raycastScale: new Vec3(1.1, 1.1, 0.1),
colorInstance: this.zCircleColor,
defaultColor: blueColor,
defaultColor: createBlueColor(),
});

this.updateAssets();
Expand Down Expand Up @@ -155,7 +155,7 @@ export class RotationGizmo extends Gizmo {
draggable.addRaycastShape(sphere);
draggable.onIsHoveringChange((isHovering) => {
if (isHovering) {
colorInstance.set(hoverColor);
colorInstance.set(createHoverColor());
} else {
colorInstance.set(defaultColor);
}
Expand Down
22 changes: 11 additions & 11 deletions src/gizmos/gizmos/ScaleGizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Vec3 } from "../../math/Vec3.js";
import { Sphere } from "../../math/shapes/Sphere.js";
import { Gizmo } from "./Gizmo.js";
import { Entity } from "../../core/Entity.js";
import { blueColor, greenColor, hoverColor, redColor, whiteColor } from "./colors.js";
import { createBlueColor, createGreenColor, createHoverColor, createRedColor, createWhiteColor } from "./colors.js";

/**
* @typedef ScaleGizmoDragEvent
Expand All @@ -17,10 +17,10 @@ import { blueColor, greenColor, hoverColor, redColor, whiteColor } from "./color
*/

export class ScaleGizmo extends Gizmo {
#circleMaterialColor = new Vec3(whiteColor);
#xArrowColor = new Vec3(redColor);
#yArrowColor = new Vec3(greenColor);
#zArrowColor = new Vec3(blueColor);
#circleMaterialColor = createWhiteColor();
#xArrowColor = createRedColor();
#yArrowColor = createGreenColor();
#zArrowColor = createBlueColor();

/** @type {Set<ScaleGizmoDragCallback>} */
#onDragCbs = new Set();
Expand Down Expand Up @@ -86,9 +86,9 @@ export class ScaleGizmo extends Gizmo {
this.entity.add(this.#centerDraggable.entity);
this.#centerDraggable.onIsHoveringChange((isHovering) => {
if (isHovering) {
this.#circleMaterialColor.set(hoverColor);
this.#circleMaterialColor.set(createHoverColor());
} else {
this.#circleMaterialColor.set(whiteColor);
this.#circleMaterialColor.set(createWhiteColor());
}
this.gizmoNeedsRender();
});
Expand Down Expand Up @@ -122,17 +122,17 @@ export class ScaleGizmo extends Gizmo {
const meshX = this.#createArrow({
axis: new Vec3(1, 0, 0),
colorInstance: this.#xArrowColor,
defaultColor: redColor,
defaultColor: createRedColor(),
});
const meshY = this.#createArrow({
axis: new Vec3(0, 1, 0),
colorInstance: this.#yArrowColor,
defaultColor: greenColor,
defaultColor: createGreenColor(),
});
const meshZ = this.#createArrow({
axis: new Vec3(0, 0, 1),
colorInstance: this.#zArrowColor,
defaultColor: blueColor,
defaultColor: createBlueColor(),
});
this.#xArrowMesh = meshX;
this.#yArrowMesh = meshY;
Expand Down Expand Up @@ -215,7 +215,7 @@ export class ScaleGizmo extends Gizmo {
draggable.addRaycastShape(sphere);
draggable.onIsHoveringChange((isHovering) => {
if (isHovering) {
colorInstance.set(hoverColor);
colorInstance.set(createHoverColor());
} else {
colorInstance.set(defaultColor);
}
Expand Down
22 changes: 11 additions & 11 deletions src/gizmos/gizmos/TranslationGizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Vec3 } from "../../math/Vec3.js";
import { Sphere } from "../../math/shapes/Sphere.js";
import { Gizmo } from "./Gizmo.js";
import { Entity } from "../../core/Entity.js";
import { blueColor, greenColor, hoverColor, redColor, whiteColor } from "./colors.js";
import { createBlueColor, createGreenColor, createHoverColor, createRedColor, createWhiteColor } from "./colors.js";

/**
* @typedef TranslationGizmoDragEvent
Expand All @@ -18,10 +18,10 @@ import { blueColor, greenColor, hoverColor, redColor, whiteColor } from "./color
*/

export class TranslationGizmo extends Gizmo {
#circleMaterialColor = new Vec3(whiteColor);
#xArrowColor = new Vec3(redColor);
#yArrowColor = new Vec3(greenColor);
#zArrowColor = new Vec3(blueColor);
#circleMaterialColor = createWhiteColor();
#xArrowColor = createRedColor();
#yArrowColor = createGreenColor();
#zArrowColor = createBlueColor();

/** @type {Set<TranslationGizmoDragCallback>} */
#onDragCbs = new Set();
Expand Down Expand Up @@ -87,9 +87,9 @@ export class TranslationGizmo extends Gizmo {
this.entity.add(this.#centerDraggable.entity);
this.#centerDraggable.onIsHoveringChange((isHovering) => {
if (isHovering) {
this.#circleMaterialColor.set(hoverColor);
this.#circleMaterialColor.set(createHoverColor());
} else {
this.#circleMaterialColor.set(whiteColor);
this.#circleMaterialColor.set(createWhiteColor());
}
this.gizmoNeedsRender();
});
Expand Down Expand Up @@ -126,17 +126,17 @@ export class TranslationGizmo extends Gizmo {
const meshX = this.#createArrow({
axis: new Vec3(1, 0, 0),
colorInstance: this.#xArrowColor,
defaultColor: redColor,
defaultColor: createRedColor(),
});
const meshY = this.#createArrow({
axis: new Vec3(0, 1, 0),
colorInstance: this.#yArrowColor,
defaultColor: greenColor,
defaultColor: createGreenColor(),
});
const meshZ = this.#createArrow({
axis: new Vec3(0, 0, 1),
colorInstance: this.#zArrowColor,
defaultColor: blueColor,
defaultColor: createBlueColor(),
});
this.#xArrowMesh = meshX;
this.#yArrowMesh = meshY;
Expand Down Expand Up @@ -219,7 +219,7 @@ export class TranslationGizmo extends Gizmo {
draggable.addRaycastShape(sphere);
draggable.onIsHoveringChange((isHovering) => {
if (isHovering) {
colorInstance.set(hoverColor);
colorInstance.set(createHoverColor());
} else {
colorInstance.set(defaultColor);
}
Expand Down
24 changes: 19 additions & 5 deletions src/gizmos/gizmos/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@

import { Vec3 } from "../../math/Vec3.js";

export const whiteColor = new Vec3(1, 1, 1);
export const redColor = new Vec3(1, 0.15, 0.15);
export const greenColor = new Vec3(0.2, 1, 0.2);
export const blueColor = new Vec3(0.3, 0.3, 1);
export const hoverColor = new Vec3(1, 0.7, 0);
export function createWhiteColor() {
return new Vec3(1, 1, 1);
}

export function createRedColor() {
return new Vec3(1, 0.15, 0.15);
}

export function createGreenColor() {
return new Vec3(0.2, 1, 0.2);
}

export function createBlueColor() {
return new Vec3(0.3, 0.3, 1);
}

export function createHoverColor() {
return new Vec3(1, 0.7, 0);
}
4 changes: 4 additions & 0 deletions test/misc/treeShaking/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { generateUuid } from "../../../src/mod.js";

const uuid = generateUuid();
console.log(uuid);
Loading