Compare commits
3 Commits
9bb162e7d5
...
ee7f5e9595
Author | SHA1 | Date | |
---|---|---|---|
ee7f5e9595 | |||
6966c5d45f | |||
33733c6fe4 |
24
Dockerfile
Normal file
24
Dockerfile
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
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
Normal file
31
Makefile
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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
|
8
common/package.json
Normal file
8
common/package.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "wmc-common",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"esbuild": "^0.14.2"
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { makeFace } from '../geometry';
|
import { makeFace } from 'wmc-common/geometry';
|
||||||
import * as linalg from './linalg';
|
import * as linalg from './linalg';
|
||||||
import {memoize} from '../memoize';
|
import {memoize} from 'wmc-common/memoize';
|
||||||
|
|
||||||
type direction = ('-x' | '+x' | '-y' | '+y' | '-z' | '+z');
|
type direction = ('-x' | '+x' | '-y' | '+y' | '-z' | '+z');
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {makeBufferFromFaces } from '../geometry';
|
import {makeBufferFromFaces } from 'wmc-common/geometry';
|
||||||
import { loadTexture, makeProgram } from '../gl';
|
import { loadTexture, makeProgram } from 'wmc-common/gl';
|
||||||
import * as linalg from './linalg';
|
import * as linalg from './linalg';
|
||||||
import * as se3 from '../se3';
|
import * as se3 from 'wmc-common/se3';
|
||||||
import { makeOrbitObject } from './orbit';
|
import { makeOrbitObject } from './orbit';
|
||||||
|
|
||||||
const VSHADER = `
|
const VSHADER = `
|
||||||
@ -15,12 +15,14 @@ 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];
|
||||||
@ -50,6 +52,7 @@ 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;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -61,6 +64,7 @@ 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);
|
||||||
@ -69,7 +73,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 = 0.8 * specularAmount * vec3(1.0, 1.0, 0.8);
|
lowp vec3 specular = specularAmount * vSpecularColor;
|
||||||
gl_FragColor = vec4(vLighting * color.rgb + specular, color.a);
|
gl_FragColor = vec4(vLighting * color.rgb + specular, color.a);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -86,6 +90,7 @@ 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');
|
||||||
@ -123,12 +128,14 @@ 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);
|
||||||
|
|
||||||
@ -240,7 +247,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} = body;
|
const {position, orientation, glowColor, specularColor} = body;
|
||||||
|
|
||||||
if (body.glBuffer === undefined) {
|
if (body.glBuffer === undefined) {
|
||||||
body.glBuffer = makeBufferFromFaces(gl, body.geometry);
|
body.glBuffer = makeBufferFromFaces(gl, body.geometry);
|
||||||
@ -252,6 +259,7 @@ 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);
|
||||||
@ -268,6 +276,7 @@ function getObjects(context, body, parentPosition = undefined) {
|
|||||||
orientation: shipOrientation,
|
orientation: shipOrientation,
|
||||||
position: shipPos,
|
position: shipPos,
|
||||||
glContext,
|
glContext,
|
||||||
|
specularColor: [0.8, 0.8, 0.8],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +320,7 @@ export function draw(context) {
|
|||||||
].reduce(se3.product));
|
].reduce(se3.product));
|
||||||
let lastGlContext;
|
let lastGlContext;
|
||||||
|
|
||||||
for (const {position, orientation, geometry, glContext, glowColor} of objects) {
|
for (const {position, orientation, geometry, glContext, glowColor, specularColor} of objects) {
|
||||||
if (glContext !== lastGlContext) {
|
if (glContext !== lastGlContext) {
|
||||||
glContext.setupScene({
|
glContext.setupScene({
|
||||||
projectionMatrix: projMatrix,
|
projectionMatrix: projMatrix,
|
||||||
@ -330,6 +339,7 @@ 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 '../geometry';
|
import { makeFace } from 'wmc-common/geometry';
|
||||||
|
|
||||||
import * as linalg from './linalg';
|
import * as linalg from './linalg';
|
||||||
import { loadObjModel } from './obj';
|
import { loadObjModel } from './obj';
|
||||||
import * as se3 from '../se3';
|
import * as se3 from 'wmc-common/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';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as se3 from '../se3';
|
import * as se3 from 'wmc-common/se3';
|
||||||
import * as linalg from './linalg';
|
import * as linalg from './linalg';
|
||||||
import {Vec3} from './linalg';
|
import {Vec3} from './linalg';
|
||||||
|
|
||||||
|
@ -4,11 +4,12 @@
|
|||||||
"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=app.js index.ts --bundle --sourcemap=inline --watch",
|
"watch": "esbuild --outfile=static/app.js index.ts --bundle --sourcemap=inline --watch",
|
||||||
"serve": "esbuild --outfile=app.js index.ts --bundle --sourcemap=inline --servedir=.",
|
"serve": "esbuild --outfile=static/app.js index.ts --bundle --sourcemap=inline --servedir=static",
|
||||||
"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 '../se3';
|
import * as se3 from 'wmc-common/se3';
|
||||||
|
|
||||||
export interface Quat {
|
export interface Quat {
|
||||||
x: number,
|
x: number,
|
||||||
|
BIN
skycraft/static/texture.png
Normal file
BIN
skycraft/static/texture.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
@ -1 +0,0 @@
|
|||||||
../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.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.14.54.tgz#de5fdba1c95666cf72369f52b40b03be71226652"
|
resolved "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.54.tgz"
|
||||||
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.yarnpkg.com/esbuild/-/esbuild-0.14.54.tgz#8b44dcf2b0f1a66fc22459943dccf477535e9aa2"
|
resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.14.54.tgz"
|
||||||
integrity sha512-Cy9llcy8DvET5uznocPyqL3BFRrFXSVqbgpMJ9Wz8oVjZlh/zUSNbPRbov0VX7VxN2JH1Oa0uNxZ7eLRb62pJA==
|
integrity sha512-Cy9llcy8DvET5uznocPyqL3BFRrFXSVqbgpMJ9Wz8oVjZlh/zUSNbPRbov0VX7VxN2JH1Oa0uNxZ7eLRb62pJA==
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
"@esbuild/linux-loong64" "0.14.54"
|
"@esbuild/linux-loong64" "0.14.54"
|
||||||
@ -133,3 +133,7 @@ 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