Compare commits
No commits in common. "ee7f5e9595c06edb52a5d8fd5577613c41e52d62" and "9bb162e7d539374d45781b90ba713a9859c1e719" have entirely different histories.
ee7f5e9595
...
9bb162e7d5
24
Dockerfile
24
Dockerfile
@ -1,24 +0,0 @@
|
|||||||
FROM node:23-alpine as skycraft-deps
|
|
||||||
|
|
||||||
WORKDIR /workspace/skycraft
|
|
||||||
ADD ./skycraft/package.json ./
|
|
||||||
ADD ./skycraft/yarn.lock ./
|
|
||||||
RUN yarn install
|
|
||||||
|
|
||||||
|
|
||||||
FROM skycraft-deps as skycraft-build
|
|
||||||
|
|
||||||
ADD . /workspace
|
|
||||||
RUN yarn build
|
|
||||||
|
|
||||||
|
|
||||||
FROM skycraft-deps as skycraft-dev
|
|
||||||
|
|
||||||
ENTRYPOINT ["yarn"]
|
|
||||||
CMD ["run", "serve"]
|
|
||||||
|
|
||||||
|
|
||||||
FROM scratch as skycraft-export
|
|
||||||
|
|
||||||
COPY --from=skycraft-build /workspace/skycraft/app.js /
|
|
||||||
COPY --from=skycraft-build /workspace/skycraft/static/* /
|
|
31
Makefile
31
Makefile
@ -1,31 +0,0 @@
|
|||||||
export DOCKER_BUILDKIT=1
|
|
||||||
|
|
||||||
skycraft-dev-image := skycraft-dev
|
|
||||||
|
|
||||||
.PHONY: skycraft
|
|
||||||
skycraft: ## build skycraft
|
|
||||||
docker build \
|
|
||||||
--output=out/skycraft \
|
|
||||||
--target=skycraft-export \
|
|
||||||
.
|
|
||||||
|
|
||||||
.PHONY: skycraft-dev-image
|
|
||||||
skycraft-dev-image:
|
|
||||||
docker build \
|
|
||||||
-t $(skycraft-dev-image) \
|
|
||||||
--target=skycraft-dev \
|
|
||||||
.
|
|
||||||
|
|
||||||
.PHONY: skycraft-dev
|
|
||||||
skycraft-dev: skycraft-dev-image
|
|
||||||
docker run -it --rm \
|
|
||||||
-v .:/workspace \
|
|
||||||
-v /workspace/skycraft/node_modules \
|
|
||||||
-p 8000:8000 \
|
|
||||||
$(skycraft-dev-image)
|
|
||||||
|
|
||||||
.PHONY: help
|
|
||||||
help: ## Show this help
|
|
||||||
@echo Noteworthy targets:
|
|
||||||
@egrep '^[a-zA-Z_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
|
||||||
.DEFAULT_GOAL := help
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "wmc-common",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"esbuild": "^0.14.2"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
import { makeFace } from 'wmc-common/geometry';
|
import { makeFace } from '../geometry';
|
||||||
import * as linalg from './linalg';
|
import * as linalg from './linalg';
|
||||||
import {memoize} from 'wmc-common/memoize';
|
import {memoize} from '../memoize';
|
||||||
|
|
||||||
type direction = ('-x' | '+x' | '-y' | '+y' | '-z' | '+z');
|
type direction = ('-x' | '+x' | '-y' | '+y' | '-z' | '+z');
|
||||||
|
|
||||||
@ -310,4 +310,4 @@ export function getBodyGeometry(seed: number) {
|
|||||||
.map(chunk => [...makeChunkFaces(chunk)]);
|
.map(chunk => [...makeChunkFaces(chunk)]);
|
||||||
|
|
||||||
return faces.reduce((a, b) => a.concat(b));
|
return faces.reduce((a, b) => a.concat(b));
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import {makeBufferFromFaces } from 'wmc-common/geometry';
|
import {makeBufferFromFaces } from '../geometry';
|
||||||
import { loadTexture, makeProgram } from 'wmc-common/gl';
|
import { loadTexture, makeProgram } from '../gl';
|
||||||
import * as linalg from './linalg';
|
import * as linalg from './linalg';
|
||||||
import * as se3 from 'wmc-common/se3';
|
import * as se3 from '../se3';
|
||||||
import { makeOrbitObject } from './orbit';
|
import { makeOrbitObject } from './orbit';
|
||||||
|
|
||||||
const VSHADER = `
|
const VSHADER = `
|
||||||
@ -15,14 +15,12 @@ uniform mat4 uView;
|
|||||||
uniform vec3 uLightDirection;
|
uniform vec3 uLightDirection;
|
||||||
uniform float uAmbiantLight;
|
uniform float uAmbiantLight;
|
||||||
uniform vec3 uGlowColor;
|
uniform vec3 uGlowColor;
|
||||||
uniform vec3 uSpecularColor;
|
|
||||||
|
|
||||||
varying highp vec2 vTextureCoord;
|
varying highp vec2 vTextureCoord;
|
||||||
varying lowp vec3 vLighting;
|
varying lowp vec3 vLighting;
|
||||||
varying lowp vec3 vRay;
|
varying lowp vec3 vRay;
|
||||||
varying lowp vec3 vLightDir;
|
varying lowp vec3 vLightDir;
|
||||||
varying lowp vec3 vNormal;
|
varying lowp vec3 vNormal;
|
||||||
varying lowp vec3 vSpecularColor;
|
|
||||||
|
|
||||||
highp mat3 transpose(in highp mat3 inmat) {
|
highp mat3 transpose(in highp mat3 inmat) {
|
||||||
highp vec3 x = inmat[0];
|
highp vec3 x = inmat[0];
|
||||||
@ -52,7 +50,6 @@ void main() {
|
|||||||
vRay = -normalize((uModel * vec4(aPosition, 1.0)).xyz - camPos);
|
vRay = -normalize((uModel * vec4(aPosition, 1.0)).xyz - camPos);
|
||||||
vLightDir = -uLightDirection;
|
vLightDir = -uLightDirection;
|
||||||
vNormal = normal;
|
vNormal = normal;
|
||||||
vSpecularColor = uSpecularColor;
|
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -64,7 +61,6 @@ varying lowp vec3 vLighting;
|
|||||||
varying lowp vec3 vRay;
|
varying lowp vec3 vRay;
|
||||||
varying lowp vec3 vLightDir;
|
varying lowp vec3 vLightDir;
|
||||||
varying lowp vec3 vNormal;
|
varying lowp vec3 vNormal;
|
||||||
varying lowp vec3 vSpecularColor;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
highp vec4 color = texture2D(uSampler, vTextureCoord);
|
highp vec4 color = texture2D(uSampler, vTextureCoord);
|
||||||
@ -73,7 +69,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
lowp vec3 specularDir = 2.0 * dot(vLightDir, vNormal) * vNormal - vLightDir;
|
lowp vec3 specularDir = 2.0 * dot(vLightDir, vNormal) * vNormal - vLightDir;
|
||||||
lowp float specularAmount = smoothstep(0.92, 1.0, dot(vRay, specularDir));
|
lowp float specularAmount = smoothstep(0.92, 1.0, dot(vRay, specularDir));
|
||||||
lowp vec3 specular = specularAmount * vSpecularColor;
|
lowp vec3 specular = 0.8 * specularAmount * vec3(1.0, 1.0, 0.8);
|
||||||
gl_FragColor = vec4(vLighting * color.rgb + specular, color.a);
|
gl_FragColor = vec4(vLighting * color.rgb + specular, color.a);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -90,7 +86,6 @@ export async function initWorldGl(gl: WebGLRenderingContext) {
|
|||||||
const lightDirectionLoc = gl.getUniformLocation(program, 'uLightDirection');
|
const lightDirectionLoc = gl.getUniformLocation(program, 'uLightDirection');
|
||||||
const ambiantLoc = gl.getUniformLocation(program, 'uAmbiantLight');
|
const ambiantLoc = gl.getUniformLocation(program, 'uAmbiantLight');
|
||||||
const glowColorLoc = gl.getUniformLocation(program, 'uGlowColor');
|
const glowColorLoc = gl.getUniformLocation(program, 'uGlowColor');
|
||||||
const specularColorLoc = gl.getUniformLocation(program, 'uSpecularColor');
|
|
||||||
|
|
||||||
const positionLoc = gl.getAttribLocation(program, 'aPosition');
|
const positionLoc = gl.getAttribLocation(program, 'aPosition');
|
||||||
const normalLoc = gl.getAttribLocation(program, 'aNormal');
|
const normalLoc = gl.getAttribLocation(program, 'aNormal');
|
||||||
@ -128,14 +123,12 @@ export async function initWorldGl(gl: WebGLRenderingContext) {
|
|||||||
numVertices,
|
numVertices,
|
||||||
lightDirection,
|
lightDirection,
|
||||||
glowColor,
|
glowColor,
|
||||||
specularColor,
|
|
||||||
} = objectParams;
|
} = objectParams;
|
||||||
|
|
||||||
gl.uniformMatrix4fv(modelLoc, false, new Float32Array(se3.product(
|
gl.uniformMatrix4fv(modelLoc, false, new Float32Array(se3.product(
|
||||||
se3.translation(...position), orientation)));
|
se3.translation(...position), orientation)));
|
||||||
gl.uniform3fv(lightDirectionLoc, lightDirection);
|
gl.uniform3fv(lightDirectionLoc, lightDirection);
|
||||||
gl.uniform3fv(glowColorLoc, glowColor);
|
gl.uniform3fv(glowColorLoc, glowColor);
|
||||||
gl.uniform3fv(specularColorLoc, specularColor);
|
|
||||||
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, glBuffer);
|
gl.bindBuffer(gl.ARRAY_BUFFER, glBuffer);
|
||||||
|
|
||||||
@ -247,7 +240,7 @@ export function getOrbitDrawContext(gl: WebGLRenderingContext) {
|
|||||||
function getObjects(context, body, parentPosition = undefined) {
|
function getObjects(context, body, parentPosition = undefined) {
|
||||||
const objects = [];
|
const objects = [];
|
||||||
const {gl, glContext, player} = context;
|
const {gl, glContext, player} = context;
|
||||||
const {position, orientation, glowColor, specularColor} = body;
|
const {position, orientation, glowColor} = body;
|
||||||
|
|
||||||
if (body.glBuffer === undefined) {
|
if (body.glBuffer === undefined) {
|
||||||
body.glBuffer = makeBufferFromFaces(gl, body.geometry);
|
body.glBuffer = makeBufferFromFaces(gl, body.geometry);
|
||||||
@ -259,7 +252,6 @@ function getObjects(context, body, parentPosition = undefined) {
|
|||||||
position,
|
position,
|
||||||
glContext,
|
glContext,
|
||||||
glowColor,
|
glowColor,
|
||||||
specularColor,
|
|
||||||
});
|
});
|
||||||
if (parentPosition !== undefined) {
|
if (parentPosition !== undefined) {
|
||||||
const orbitObject = makeOrbitObject(gl, context.orbitGlContext, body.orbit, parentPosition);
|
const orbitObject = makeOrbitObject(gl, context.orbitGlContext, body.orbit, parentPosition);
|
||||||
@ -276,7 +268,6 @@ function getObjects(context, body, parentPosition = undefined) {
|
|||||||
orientation: shipOrientation,
|
orientation: shipOrientation,
|
||||||
position: shipPos,
|
position: shipPos,
|
||||||
glContext,
|
glContext,
|
||||||
specularColor: [0.8, 0.8, 0.8],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +311,7 @@ export function draw(context) {
|
|||||||
].reduce(se3.product));
|
].reduce(se3.product));
|
||||||
let lastGlContext;
|
let lastGlContext;
|
||||||
|
|
||||||
for (const {position, orientation, geometry, glContext, glowColor, specularColor} of objects) {
|
for (const {position, orientation, geometry, glContext, glowColor} of objects) {
|
||||||
if (glContext !== lastGlContext) {
|
if (glContext !== lastGlContext) {
|
||||||
glContext.setupScene({
|
glContext.setupScene({
|
||||||
projectionMatrix: projMatrix,
|
projectionMatrix: projMatrix,
|
||||||
@ -339,7 +330,6 @@ export function draw(context) {
|
|||||||
numVertices: geometry.numVertices,
|
numVertices: geometry.numVertices,
|
||||||
lightDirection,
|
lightDirection,
|
||||||
glowColor: glowColor || [0, 0, 0],
|
glowColor: glowColor || [0, 0, 0],
|
||||||
specularColor: specularColor || [0, 0, 0],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
import { makeFace } from 'wmc-common/geometry';
|
import { makeFace } from '../geometry';
|
||||||
|
|
||||||
import * as linalg from './linalg';
|
import * as linalg from './linalg';
|
||||||
import { loadObjModel } from './obj';
|
import { loadObjModel } from './obj';
|
||||||
import * as se3 from 'wmc-common/se3';
|
import * as se3 from '../se3';
|
||||||
import { computeOrbit, findSoi, getCartesianState, updateBodyPhysics } from './orbit';
|
import { computeOrbit, findSoi, getCartesianState, updateBodyPhysics } from './orbit';
|
||||||
import { getBodyGeometry } from './chunk';
|
import { getBodyGeometry } from './chunk';
|
||||||
import { draw, getOrbitDrawContext, initWorldGl } from './draw';
|
import { draw, getOrbitDrawContext, initWorldGl } from './draw';
|
||||||
@ -406,4 +406,4 @@ async function main() {
|
|||||||
requestAnimationFrame(time => tick(time, context));
|
requestAnimationFrame(time => tick(time, context));
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = main;
|
window.onload = main;
|
@ -1,4 +1,4 @@
|
|||||||
import * as se3 from 'wmc-common/se3';
|
import * as se3 from '../se3';
|
||||||
import * as linalg from './linalg';
|
import * as linalg from './linalg';
|
||||||
import {Vec3} from './linalg';
|
import {Vec3} from './linalg';
|
||||||
|
|
||||||
@ -277,4 +277,4 @@ export function makeOrbitObject(gl: WebGLRenderingContext, glContext: any, orbit
|
|||||||
position,
|
position,
|
||||||
glContext,
|
glContext,
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -4,12 +4,11 @@
|
|||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "^0.14.2",
|
"esbuild": "^0.14.2"
|
||||||
"wmc-common": "link:../common"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"watch": "esbuild --outfile=static/app.js index.ts --bundle --sourcemap=inline --watch",
|
"watch": "esbuild --outfile=app.js index.ts --bundle --sourcemap=inline --watch",
|
||||||
"serve": "esbuild --outfile=static/app.js index.ts --bundle --sourcemap=inline --servedir=static",
|
"serve": "esbuild --outfile=app.js index.ts --bundle --sourcemap=inline --servedir=.",
|
||||||
"build": "esbuild --outfile=app.js index.ts --bundle --minify"
|
"build": "esbuild --outfile=app.js index.ts --bundle --minify"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {Mat4} from './linalg';
|
import {Mat4} from './linalg';
|
||||||
import * as se3 from 'wmc-common/se3';
|
import * as se3 from '../se3';
|
||||||
|
|
||||||
export interface Quat {
|
export interface Quat {
|
||||||
x: number,
|
x: number,
|
||||||
@ -121,4 +121,4 @@ export function scale(q: Quat, a: number): Quat {
|
|||||||
z: a * q.z,
|
z: a * q.z,
|
||||||
w: a * q.w,
|
w: a * q.w,
|
||||||
};
|
};
|
||||||
}
|
}
|
Binary file not shown.
Before Width: | Height: | Size: 40 KiB |
1
skycraft/texture.png
Symbolic link
1
skycraft/texture.png
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../texture.png
|
@ -44,7 +44,7 @@ esbuild-linux-32@0.14.54:
|
|||||||
|
|
||||||
esbuild-linux-64@0.14.54:
|
esbuild-linux-64@0.14.54:
|
||||||
version "0.14.54"
|
version "0.14.54"
|
||||||
resolved "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.54.tgz"
|
resolved "https://registry.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.14.54.tgz#de5fdba1c95666cf72369f52b40b03be71226652"
|
||||||
integrity sha512-EgjAgH5HwTbtNsTqQOXWApBaPVdDn7XcK+/PtJwZLT1UmpLoznPd8c5CxqsH2dQK3j05YsB3L17T8vE7cp4cCg==
|
integrity sha512-EgjAgH5HwTbtNsTqQOXWApBaPVdDn7XcK+/PtJwZLT1UmpLoznPd8c5CxqsH2dQK3j05YsB3L17T8vE7cp4cCg==
|
||||||
|
|
||||||
esbuild-linux-arm64@0.14.54:
|
esbuild-linux-arm64@0.14.54:
|
||||||
@ -109,7 +109,7 @@ esbuild-windows-arm64@0.14.54:
|
|||||||
|
|
||||||
esbuild@^0.14.2:
|
esbuild@^0.14.2:
|
||||||
version "0.14.54"
|
version "0.14.54"
|
||||||
resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.14.54.tgz"
|
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.14.54.tgz#8b44dcf2b0f1a66fc22459943dccf477535e9aa2"
|
||||||
integrity sha512-Cy9llcy8DvET5uznocPyqL3BFRrFXSVqbgpMJ9Wz8oVjZlh/zUSNbPRbov0VX7VxN2JH1Oa0uNxZ7eLRb62pJA==
|
integrity sha512-Cy9llcy8DvET5uznocPyqL3BFRrFXSVqbgpMJ9Wz8oVjZlh/zUSNbPRbov0VX7VxN2JH1Oa0uNxZ7eLRb62pJA==
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
"@esbuild/linux-loong64" "0.14.54"
|
"@esbuild/linux-loong64" "0.14.54"
|
||||||
@ -133,7 +133,3 @@ esbuild@^0.14.2:
|
|||||||
esbuild-windows-32 "0.14.54"
|
esbuild-windows-32 "0.14.54"
|
||||||
esbuild-windows-64 "0.14.54"
|
esbuild-windows-64 "0.14.54"
|
||||||
esbuild-windows-arm64 "0.14.54"
|
esbuild-windows-arm64 "0.14.54"
|
||||||
|
|
||||||
"wmc-common@link:../common":
|
|
||||||
version "0.0.0"
|
|
||||||
uid ""
|
|
||||||
|
Loading…
Reference in New Issue
Block a user