Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

World System and Basic Physics #968

Merged
merged 21 commits into from
Mar 20, 2024
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Format Validation (ESLint)
name: Fission

on:
workflow_dispatch: {}
Expand All @@ -9,7 +9,7 @@ on:

jobs:
runFormatValidationScript:
name: Run ESLint Format Validation
name: ESLint Format Validation
runs-on: ubuntu-latest
steps:
- name: Checkout Code
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/FissionPackage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Fission

on:
workflow_dispatch: {}
push:
branches: [ master ]

jobs:
runUnitTests:
name: Package
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: JavaScript Setup
uses: actions/setup-node@v2
with:
node-version: 20

- name: Get date
id: date # this is used on variable path
run: |
echo "timestamp=$(date +'%Y-%m-%dT%H-%M-%S')" >> $GITHUB_OUTPUT

- name: Install Dependencies
run: |
cd fission
npm install

- name: Get package info
id: info
uses: codex-team/[email protected]
with:
path: fission/

- name: Build
id: build
run: |
cd fission
npm run build

- name: Upload Artifact
uses: actions/upload-artifact@v4
id: upload-artifact
with:
name: "${{ steps.info.outputs.name }}@${{ steps.info.outputs.version }}[${{ steps.date.outputs.timestamp }}]"
path: fission/dist/
38 changes: 38 additions & 0 deletions .github/workflows/FissionUnitTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Fission

on:
workflow_dispatch: {}
push:
branches: [ master, dev ]
pull_request:
branches: [ master, dev ]

jobs:
runUnitTests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: JavaScript Setup
uses: actions/setup-node@v2
with:
node-version: 20
- name: Install Dependencies
run: |
cd fission
npm install
- name: Unit Tests
id: unit-tests
run: |
cd fission
npm run test
continue-on-error: true
- name: Check Success
run: |
if [ ${{ steps.unit-tests.outcome }} == "success" ]; then
echo "Format Validation Passed"
else
echo "Format Validation Failed"
exit 1
fi
6 changes: 3 additions & 3 deletions fission/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-proj",
"private": true,
"version": "0.0.0",
"name": "synthesis-fission",
"private": false,
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
38 changes: 0 additions & 38 deletions fission/src/App.css

This file was deleted.

9 changes: 0 additions & 9 deletions fission/src/App.tsx

This file was deleted.

36 changes: 21 additions & 15 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Scene from './components/Scene.tsx';
import GetSceneRenderer from './systems/scene/SceneRenderer.ts';
import MirabufSceneObject from './mirabuf/MirabufSceneObject.ts';
import { LoadMirabufRemote } from './mirabuf/MirabufLoader.ts';
import { mirabuf } from './proto/mirabuf';
Expand Down Expand Up @@ -54,8 +53,10 @@ import ZoneConfigPanel from "./panels/configuring/scoring/ZoneConfigPanel"
import ScoreboardPanel from "./panels/information/ScoreboardPanel"
import DriverStationPanel from "./panels/simulation/DriverStationPanel"
import ManageAssembliesModal from './modals/spawning/ManageAssembliesModal.tsx';
import World from './systems/World.ts';

const DEFAULT_MIRA_PATH = 'test_mira/Team_2471_(2018)_v7.mira';
// const DEFAULT_MIRA_PATH = 'test_mira/Dozer_v2.mira';

function Synthesis() {
const { openModal, closeModal, getActiveModalElement } =
Expand Down Expand Up @@ -145,6 +146,8 @@ function Synthesis() {

useEffect(() => {

World.InitWorld();

let mira_path = DEFAULT_MIRA_PATH;

const urlParams = new URLSearchParams(document.location.search);
Expand All @@ -161,33 +164,36 @@ function Synthesis() {
_ => LoadMirabufRemote(DEFAULT_MIRA_PATH)
).catch(console.error);

if (!miraAssembly || !(miraAssembly instanceof mirabuf.Assembly)) {
return;
}

const parser = new MirabufParser(miraAssembly);
if (parser.maxErrorSeverity >= ParseErrorSeverity.Unimportable) {
console.error(`Assembly Parser produced significant errors for '${miraAssembly.info!.name!}'`);
return;
}

const mirabufSceneObject = new MirabufSceneObject(new MirabufInstance(parser));
GetSceneRenderer().RegisterSceneObject(mirabufSceneObject);
await (async () => {
if (!miraAssembly || !(miraAssembly instanceof mirabuf.Assembly)) {
return;
}

const parser = new MirabufParser(miraAssembly);
if (parser.maxErrorSeverity >= ParseErrorSeverity.Unimportable) {
console.error(`Assembly Parser produced significant errors for '${miraAssembly.info!.name!}'`);
return;
}

const mirabufSceneObject = new MirabufSceneObject(new MirabufInstance(parser));
World.SceneRenderer.RegisterSceneObject(mirabufSceneObject);
})();
};
setup();

let mainLoopHandle = 0;
const mainLoop = () => {
mainLoopHandle = requestAnimationFrame(mainLoop);

GetSceneRenderer().Update();
World.UpdateWorld();
};
mainLoop();
// Cleanup
return () => {
// TODO: Teardown literally everything
cancelAnimationFrame(mainLoopHandle);
GetSceneRenderer().RemoveAllSceneObjects();
World.DestroyWorld();
// World.SceneRenderer.RemoveAllSceneObjects();
};
}, []);

Expand Down
6 changes: 4 additions & 2 deletions fission/src/components/Scene.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import './Scene.css';
import { useEffect, useRef } from "react";
import GetSceneRenderer from "../systems/scene/SceneRenderer";
import Stats from 'stats.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import SceneObject from "../systems/scene/SceneObject";
import World from '@/systems/World';

let stats: Stats | null;

Expand All @@ -17,10 +17,12 @@ function Scene({ useStats }: SceneProps) {
const refContainer = useRef<HTMLDivElement>(null);

useEffect(() => {
World.InitWorld();

if (refContainer.current) {
console.debug('Adding ThreeJs to DOM');

const sr = GetSceneRenderer();
const sr = World.SceneRenderer;
sr.renderer.domElement.style.width = '100%';
sr.renderer.domElement.style.height = '100%';

Expand Down
1 change: 0 additions & 1 deletion fission/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react"
import ReactDOM from "react-dom/client"
import { Theme, ThemeProvider } from "./ThemeContext"
import Synthesis from "./Synthesis"
Expand Down
40 changes: 27 additions & 13 deletions fission/src/mirabuf/MirabufInstance.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as THREE from 'three';
import { mirabuf } from "../proto/mirabuf"
import MirabufParser, { ParseErrorSeverity } from './MirabufParser.ts';
import { MirabufTransform_ThreeMatrix4 } from '../util/TypeConversions.ts';
import World from '@/systems/World.ts';

const NORMAL_MATERIALS = false;
export enum MaterialStyle {
Regular = 0,
Normals = 1,
Toon = 2
}

export const matToString = (mat: THREE.Matrix4) => {
const arr = mat.toArray();
Expand Down Expand Up @@ -78,7 +82,7 @@ class MirabufInstance {
public get materials() { return this._materials; }
public get meshes() { return this._meshes; }

public constructor(parser: MirabufParser) {
public constructor(parser: MirabufParser, materialStyle?: MaterialStyle) {
if (parser.errors.some(x => x[0] >= ParseErrorSeverity.Unimportable)) {
throw new Error('Parser has significant errors...');
}
Expand All @@ -87,14 +91,14 @@ class MirabufInstance {
this._materials = new Map();
this._meshes = new Map();

this.LoadMaterials();
this.LoadMaterials(materialStyle ?? MaterialStyle.Regular);
this.CreateMeshes();
}

/**
* Parses all mirabuf appearances into ThreeJs materials.
*/
private LoadMaterials() {
private LoadMaterials(materialStyle: MaterialStyle) {
Object.entries(this._mirabufParser.assembly.data!.materials!.appearances!).forEach(([appearanceId, appearance]) => {
let hex = 0xe32b50;
if (appearance.albedo) {
Expand All @@ -103,12 +107,22 @@ class MirabufInstance {
hex = A << 24 | R << 16 | G << 8 | B;
}

this._materials.set(
appearanceId,
new THREE.MeshPhongMaterial({
let material: THREE.Material;
if (materialStyle == MaterialStyle.Regular) {
material = new THREE.MeshPhongMaterial({
color: hex,
shininess: 0.0,
})
});
} else if (materialStyle == MaterialStyle.Normals) {
material = new THREE.MeshNormalMaterial();
} else if (materialStyle == MaterialStyle.Toon) {
material = World.SceneRenderer.CreateToonMaterial(hex, 5);
console.debug('Toon Material');
}

this._materials.set(
appearanceId,
material!
);
});
}
Expand All @@ -135,14 +149,14 @@ class MirabufInstance {
transformGeometry(geometry, mesh.mesh!);

const appearanceOverride = body.appearanceOverride;
let material: THREE.Material =
const material: THREE.Material =
appearanceOverride && this._materials.has(appearanceOverride)
? this._materials.get(appearanceOverride)!
: fillerMaterials[nextFillerMaterial++ % fillerMaterials.length];

if (NORMAL_MATERIALS) {
material = new THREE.MeshNormalMaterial();
}
// if (NORMAL_MATERIALS) {
// material = new THREE.MeshNormalMaterial();
// }

const threeMesh = new THREE.Mesh( geometry, material );
threeMesh.receiveShadow = true;
Expand Down
Loading
Loading