Skip to content

Commit

Permalink
Fix bug where correct hyperdrive pitch/roll/yaw movement was dependen…
Browse files Browse the repository at this point in the history
…t on the angle at which the ship was facing in the exported GLTF.
  • Loading branch information
aggregate1166877 committed Apr 30, 2021
1 parent fe575d5 commit 300652f
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 49 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -29,7 +29,8 @@ no loading screens.
#### Excellent modding support
You can make a fully interactable space ship yourself **with zero programming
experience**. All you need is a copy of Blender 2.8 and to follow the guide on
mesh codes. Blender does not even need any add-ons for this to work.
mesh codes. Blender does not even need any special add-ons for this to work,
though a future add-on is on the roadmap to make some tedious tasks faster.

If you are a coder, coded modding support is planned but currently low priority
due to the fact the game is still rapidly changing. Adding such support in
Expand Down
22 changes: 17 additions & 5 deletions TODO
@@ -1,11 +1,24 @@
Fix bug where switching to mouse steering uses old now-invalid analog numbers.

Move cam[0] logic into ship loader.
- Create notion of a standard arrow.
- Ship orientation cam.
- Initial cam.
- Bridge cam.
- Ship outside cam.

Make the ship loader load gltf lights.

Make planets respect local star light.
* Implement a mechanism to differentiate between stars, light emitting
planets, and regular planets.
* Make stars light emitters.
* Give celestial bodies the materials needed to facilitate lighting.

shipPilot.onShipLoaded:
Many changes have been made since this was implemented; check if the cam
rotation code in that function even does anything. Remove if not.

Cam controllers currently have the option to be notified when they are loaded.
They do however not have a direct mechanism to be notified if a different
controller is being loaded, making checking verbose copy-pasta. Implement
Expand All @@ -25,20 +38,19 @@ Implement physics in a universally easy to use way.

Implement a ramp based spedometer and make sure distances measured with m/s check out.

Add core controls top right below FPS:
Add core controls top left below FPS:
- F1: show all controls.
- Middle click: or Num5 to lock mouse.
- J: jump into (and out of) hyperspace.
- WASD and EF: move ship.
- F2: show / hide this text.
- Right click in-ship menu for quick assign.

-- Set up a spacecube field and make the ship travel through it (just via brute
force, no need for physics right now). Then ensure the player stays on the ship
and doesn't get left behind, in all modes. Maybe give to option to let one
detach from ship in free cam mode.

Implement full warp drive controls.

Implement an analog logarithmic speedometer (or at least a relative one).
Show all speeds underneath, but make the font smallers as the numbers grow.
Move position and rotation to left bottom.
Expand All @@ -52,8 +64,8 @@ Make the border be in the direction of the switch highlighted.
Maybe place an actual arrow next the border closer the the interactable, but
this last one is optional.

100km/h -> 3000c -> 3 billion c
[messes up past about 50% galaxy width, but it's consistent and can likely be worked around]
spaceShipLoader.modelPostSetup:
Implement mechanism to load player ship at specific world position.

Some technical problems to consider:
Moving at 3000c causes the camera to jump around *slightly*. \[Note that this was
Expand Down
6 changes: 3 additions & 3 deletions app/cameraControllers/freeCam.js
Expand Up @@ -2,9 +2,9 @@ import * as THREE from "three";

import AssetLoader from '../local/AssetLoader';
import { controls } from '../local/controls';
import core from "../local/core";
import speedTracker from "./utils/speedTracker";
import { lockModes } from "../local/PointerLockControls";
import core from '../local/core';
import speedTracker from './utils/speedTracker';
import { lockModes } from '../local/PointerLockControls';

const mode = core.modes.freeCam;
const camControls = controls.freeCam;
Expand Down
23 changes: 13 additions & 10 deletions app/cameraControllers/shipPilot.js
Expand Up @@ -117,10 +117,10 @@ function register() {
$game.ptrLockControls.setLockMode(lockModes.headLook);
});
core.onLoadProgress(core.progressActions.playerShipLoaded, () => {

// TODO: move this into the level loader. It needs to be dynamic based on
// the level itself (in this case we attach the player to the main cam).
$game.playerShip.cameras[0].attach($game.camera);
// $game.playerShip.scene.children[2].attach($game.camera);
$game.camera.position.x = 0;
$game.camera.position.y = 0;
$game.camera.position.z = 0;
Expand All @@ -138,6 +138,9 @@ function register() {
}

function onShipLoaded(mesh) {
// TODO: many changes have been made since this was implemented; check if the
// below still does anything at all.

// console.log('shipPilot got mesh:', mesh);
// attachCamera(mesh);
// $game.camera.rotation.setFromVector3(new THREE.Vector3(-3.1, 0.03, 3.13));
Expand Down Expand Up @@ -260,14 +263,14 @@ function scaleHyperSpeed(amount) {
return Math.exp(amount / 10);
}

function handleHyper(delta, scene, playerShip) {
function handleHyper(delta, scene, playerShip, warpBubble) {
if (steer.leftRight) {
const lr = (steer.leftRight * delta) * 65.2;
playerShip.scene.rotateY(lr * rotationSpeed);
warpBubble.rotateY(lr * rotationSpeed);
}
if (steer.upDown) {
const ud = (steer.upDown * delta) * 65.2;
playerShip.scene.rotateX(ud * rotationSpeed);
warpBubble.rotateX(ud * rotationSpeed);
}

const effectiveSpin = (spinSpeed * delta) * 65.2;
Expand All @@ -283,7 +286,7 @@ function handleHyper(delta, scene, playerShip) {
spinBuildup = effectiveSpin;
}
}
playerShip.scene.rotateZ(spinBuildup);
warpBubble.rotateZ(spinBuildup);
if (Math.abs(spinBuildup) < 0.0001) {
spinBuildup = 0;
}
Expand Down Expand Up @@ -340,9 +343,9 @@ function handleHyper(delta, scene, playerShip) {

// Move the world around the ship.
let direction = new THREE.Vector3();
$game.playerShip.cameras[0].getWorldDirection(direction);
$game.scene.position.addScaledVector(direction, -hyperSpeed);
$game.playerShip.scene.position.addScaledVector(direction, hyperSpeed);
playerShip.cameras[0].getWorldDirection(direction);
scene.position.addScaledVector(direction, -hyperSpeed);
warpBubble.position.addScaledVector(direction, hyperSpeed);
}

/** Returns the number, or 100 (sign preserved) if it's more than 100. */
Expand All @@ -365,7 +368,7 @@ function handleLocal(delta) {

let updateCount_DELETEME = 0;
function render(delta) {
const { playerShip } = $game;
const { playerShip, playerShipBubble } = $game;
if (!playerShip) {
return;
}
Expand Down Expand Up @@ -399,7 +402,7 @@ function render(delta) {
// Hyper-movement is similar to freecam, but has a concept of inertia. The
// ship cannot strafe in this mode. The ship should have no physics in this
// mode, and the universe moves instead of the ship.
handleHyper(delta, scene, playerShip);
handleHyper(delta, scene, playerShip, playerShipBubble);
}
else {
// PLEASE GIVE ME PHYSICS
Expand Down
4 changes: 2 additions & 2 deletions app/cameraControllers/utils/speedTracker.js
Expand Up @@ -47,8 +47,8 @@ function trackCameraSpeed() {
}
showStats();

const camPs = $game.playerShip.scene.position;
const camRt = $game.playerShip.scene.rotation;
const camPs = $game.playerShipBubble.position;
const camRt = $game.playerShipBubble.rotation;

let dist = camPs.distanceTo(prevPosition);
dist = dist / (freq / perUnit);
Expand Down
2 changes: 1 addition & 1 deletion app/index.js
@@ -1,7 +1,7 @@
import React from 'react';

import core from './local/core';
import { loadAllCrosshairImages } from "./local/crosshairs";
import { loadAllCrosshairImages } from './local/crosshairs';
import powerOnSelfTest from './test';
import build from '../build.json';

Expand Down
40 changes: 31 additions & 9 deletions app/levelLogic/spaceShipLoader.js
Expand Up @@ -104,8 +104,35 @@ function loadModel(name, callback) {

function modelPostSetup(modelName, gltf, pos, scene, world, onReady) {
getMesh(modelName, (mesh) => {
mesh.scene.position.copy($game.camera.position);
//
// TODO: improve the way this is decided. The space ship designer should be
// choosing what the standard arrow is.
const standardArrow = mesh.cameras[0];

// Space ship container.
const bubble = new THREE.Group();
bubble.add(mesh.scene);
scene.add(bubble);

// Get warp bubble world direction:
let bubbleDirection = new THREE.Vector3();
bubble.getWorldDirection(bubbleDirection);

// Get standard arrow world direction:
let camDirection = new THREE.Vector3();
standardArrow.getWorldDirection(camDirection);

// Define a rotation from their unit-length vectors:
let quaternion = new THREE.Quaternion();
quaternion.setFromUnitVectors(camDirection.normalize(), bubbleDirection.normalize());
// ^^ note: term order is important.

// Apply rotation to ship (ship rotates inside bubble, bubble stays
// stationary for this operation). This allows the artist to model the ship
// in any orientation.
let matrix = new THREE.Matrix4();
matrix.makeRotationFromQuaternion(quaternion);
mesh.scene.applyMatrix4(matrix);

// TODO: remove this light. This is only here until lights become dynamic.
// const warmWhite = 0xefebd8;
// const warmWhite = 0xfff5b6;
Expand All @@ -121,10 +148,8 @@ function modelPostSetup(modelName, gltf, pos, scene, world, onReady) {
// light.position.set(pos.x, pos.y + 2, pos.z);
light2.position.set(0, 2, 3);
mesh.scene.add(light2);
//
scene.add(mesh.scene);

// TODO: continue from here.
// TODO: implement the physics things.
// const body = makePhysical({
// mesh: mesh.scene,
// // TODO: for now we use a simple cube shape just to get the framework up.
Expand All @@ -134,10 +159,7 @@ function modelPostSetup(modelName, gltf, pos, scene, world, onReady) {
// options: { mass: 1 },
// world,
// });

const { x, y, z } = mesh.scene.position;
// console.log(`=> Physical ship ${modelName} created at ${x},${y},${z};`, mesh);
onReady(mesh);
onReady(mesh, bubble);
});
}

Expand Down
3 changes: 2 additions & 1 deletion app/local/PointerLockControls.js
Expand Up @@ -68,15 +68,16 @@ const PointerLockControls = function (camera, domElement, onMouseCb) {
const my = event.movementY || event.mozMovementY || event.webkitMovementY || 0;

if (scope.lockMode === lockModes.headLook) {
// Limit how far the player can turn their necks.
if (Math.abs(scope.mouseX + mx) < scope.headXMax) {
scope.mouseX += mx;
scope.waitingX = mx;
}
if (Math.abs(scope.mouseY + my) < scope.headYMax) {
scope.mouseY += my;
}
}
else {
// Allow fracturing of vertebrae.
scope.mouseX += mx;
scope.mouseY += my;
}
Expand Down
22 changes: 16 additions & 6 deletions app/local/core.js
Expand Up @@ -50,7 +50,13 @@ window.$game = {
renderer: null,
spaceWorld: null,
gravityWorld: null,
// The loaded file. The 'real' space ship is playerShip.scene.
playerShip: null,
// Container for the player ship. Used especially by the warp drive to know
// what the ship's 'forward' direction is. This allows the 3D artist to model
// their ship in any orientation, and then use a standard arrow to tell the
// engine which direction the ship is pointing.
playerShipBubble: null,
ptrLockControls: null,
// The term 'level' here is used very loosely. It's any interactable
// environment. Space ships as well planet sectors count as levels. Note that
Expand Down Expand Up @@ -651,7 +657,7 @@ function init({ sceneName, pos, rot }) {
}

function initView({ scene, pos, rot }) {
const camera = new THREE.PerspectiveCamera(75, SCREEN_WIDTH / SCREEN_HEIGHT, NEAR, FAR);
const camera = new THREE.PerspectiveCamera(56.25, SCREEN_WIDTH / SCREEN_HEIGHT, NEAR, FAR);
camera.position.copy(pos);
camera.rotation.setFromVector3(rot);
scene.add(camera);
Expand Down Expand Up @@ -718,17 +724,21 @@ function initView({ scene, pos, rot }) {

function initPlayer() {
createSpaceShip({
modelName: 'DS69F', onReady: (mesh) => {
// modelName: 'devFlyer', onReady: (mesh) => {
// modelName: 'devFlyer2', onReady: (mesh) => {
// modelName: 'tentacleHull', onReady: (mesh) => {
// modelName: 'DS69F', onReady: (mesh, bubble) => {
modelName: 'scorpion_d', onReady: (mesh, bubble) => {
// modelName: 'devFlyer', onReady: (mesh, bubble) => {
// modelName: 'devFlyer2', onReady: (mesh, bubble) => {
// modelName: 'devFlyer3', onReady: (mesh, bubble) => {
// modelName: 'tentacleHull', onReady: (mesh, bubble) => {
// modelName: 'test', onReady: (mesh, bubble) => {
$game.playerShip = mesh;
$game.playerShipBubble = bubble;
notifyLoadProgress(progressActions.playerShipLoaded);

// TODO: replace all external occurrences of notifyAll with
// onLoadProgress, then delete this.
playerShipReadyListeners.notifyAll((cb) => {
cb(mesh);
cb(mesh, bubble);
});
// console.log('==> ship stored in $game.');
}
Expand Down
11 changes: 10 additions & 1 deletion app/scenes/localCluster.js
Expand Up @@ -146,7 +146,7 @@ function init({ font }) {
// TODO: figure out wtf is going on here.
// So, very simply: 3000 cubes @ 4 verts each = 12,000 verts = 11fps on an RTX 2080TI.
// Or, add a compressed gltf scene from blender with 2 million verts - 60 fps constant. wut..?
// The real confusing part here is the actual resourse usage - CPU 10%, GPU 20%, RAM 50%. I.e system
// The real confusing part here is the actual resource usage - CPU 10%, GPU 20%, RAM 50%. I.e system
// not being utilised.
// core.onLoadProgress(core.progressActions.ready, () => {
// const objects = generateCubeField({
Expand All @@ -156,6 +156,15 @@ function init({ font }) {
// console.log('cube space:', objects);
// });

// core.onLoadProgress(core.progressActions.ready, () => {
// const objects = generateCubeField({
// scene: $game.scene,
// position: $game.camera.position,
// cubeCount: 25,
// distanceMultiplier: 0.5
// });
// });

core.onLoadProgress(core.progressActions.ready, () => {
// const objects = generateCubeField({
// scene: $game.scene,
Expand Down
2 changes: 1 addition & 1 deletion build.json
@@ -1 +1 @@
{ "meta": "hook generated", "buildNumber": 49 }
{ "meta": "hook generated", "buildNumber": 50 }
17 changes: 8 additions & 9 deletions package.json
Expand Up @@ -25,6 +25,14 @@
],
"author": "aggregate1166877",
"license": "MIT",
"dependencies": {
"cannon": "0.6.2",
"drei": "1.5.7",
"nw": "0.50.2-sdk",
"react": "16.13.1",
"react-dom": "16.13.1",
"three": "0.120.1"
},
"devDependencies": {
"@babel/core": "7.2.2",
"@babel/plugin-proposal-class-properties": "7.5.5",
Expand All @@ -40,14 +48,5 @@
"npm-run-all": "4.1.2",
"webpack": "4.28.4",
"webpack-cli": "3.2.1"
},
"dependencies": {
"cannon": "0.6.2",
"drei": "1.5.7",
"nw": "0.50.2-sdk",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-three-fiber": "4.2.21",
"three": "0.120.1"
}
}

0 comments on commit 300652f

Please sign in to comment.