reconcile new three modules, create a bundle
This commit is contained in:
parent
e26e57e193
commit
9adfe33cfb
19 changed files with 82 additions and 60 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -6,4 +6,5 @@ tmp
|
|||
logs/*
|
||||
data/*
|
||||
package-lock.json
|
||||
src/ext/three.js
|
||||
app.json
|
||||
|
|
|
|||
1
app.js
1
app.js
|
|
@ -475,7 +475,6 @@ const script = {
|
|||
"&kiri/lang-en"
|
||||
],
|
||||
kiri_work : [
|
||||
// "#ext/manifold2",
|
||||
"kiri-run/worker",
|
||||
"&main/kiri",
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,31 +1,7 @@
|
|||
const os = require('os');
|
||||
const fs = require('fs-extra');
|
||||
const fetchr = import('node-fetch');
|
||||
const path = require('path');
|
||||
|
||||
async function download(url, filePath) {
|
||||
const fetch = (await fetchr).default;
|
||||
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
fs.ensureDir(path.dirname(filePath));
|
||||
const fileStream = fs.createWriteStream(filePath);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
response.body.pipe(fileStream);
|
||||
response.body.on('error', reject);
|
||||
fileStream.on('error', error => {
|
||||
console.log({ error });
|
||||
});
|
||||
fileStream.on('finish', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('npm pre running');
|
||||
|
||||
|
|
|
|||
5
bin/webpack-three-bundle.js
Normal file
5
bin/webpack-three-bundle.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import * as THREE from "../node_modules/three/build/three.module.js";
|
||||
import * as SVGLoader from "../node_modules/three/examples/jsm/loaders/SVGLoader.js";
|
||||
import * as BufferGeometryUtils from "../node_modules/three/examples/jsm/utils/BufferGeometryUtils.js";
|
||||
|
||||
export { THREE, SVGLoader, BufferGeometryUtils };
|
||||
45
bin/webpack-three.js
Normal file
45
bin/webpack-three.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
mode: 'production',
|
||||
entry: "./bin/webpack-three-bundle.js",
|
||||
output: {
|
||||
path: path.resolve('src/ext'),
|
||||
filename: 'three.js',
|
||||
library: 'ThreeBundle',
|
||||
libraryTarget: 'umd',
|
||||
globalObject: 'this'
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.mjs', '.js'],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.m?js$/,
|
||||
resolve: {
|
||||
fullySpecified: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
extractComments: false,
|
||||
terserOptions: {
|
||||
format: {
|
||||
comments: false,
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
performance: {
|
||||
hints: false,
|
||||
maxAssetSize: 2 * 1024 * 1024,
|
||||
maxEntrypointSize: 2 * 1024 * 1024,
|
||||
},
|
||||
};
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
"manifold-3d": "^2.5.1",
|
||||
"moment": "^2.29.4",
|
||||
"serve-static": "^1.14.1",
|
||||
"three": "^0.147.0",
|
||||
"three": "^0.166.0",
|
||||
"three-mesh-bvh": "^0.5.21",
|
||||
"uglify-js": "3.14.5",
|
||||
"validator": ">=13.7.0",
|
||||
|
|
@ -51,7 +51,10 @@
|
|||
"electron": "latest",
|
||||
"electron-builder": "latest",
|
||||
"fs-extra": "^11.2.0",
|
||||
"node-fetch": "^3.3.2"
|
||||
"node-fetch": "^3.3.2",
|
||||
"terser-webpack-plugin": "^5.3.10",
|
||||
"webpack": "^5.92.1",
|
||||
"webpack-cli": "^5.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "npm run prebuild && electron .",
|
||||
|
|
@ -70,7 +73,7 @@
|
|||
"mac-verify": "spctl --assess -vv --type install dist/*/*.app",
|
||||
"prebuild": "node bin/electron-pre.js",
|
||||
"postbuild": "node bin/electron-post.js",
|
||||
"preinstall": "node bin/install-pre.js"
|
||||
"preinstall": "node bin/install-pre.js; npx webpack --config bin/webpack-three.js"
|
||||
},
|
||||
"main": "app-el.js",
|
||||
"build": {
|
||||
|
|
|
|||
|
|
@ -3,11 +3,14 @@
|
|||
"use strict";
|
||||
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
// dep: ext.three-svg
|
||||
// dep: ext.three-bvh
|
||||
gapp.register("add.three", [], (root, exports) => {
|
||||
|
||||
const { THREE, SVGLoader, BufferGeometryUtils } = ThreeBundle;
|
||||
|
||||
root.THREE = THREE;
|
||||
THREE.BufferGeometryUtils = BufferGeometryUtils;
|
||||
THREE.SVGLoader = SVGLoader.SVGLoader;
|
||||
|
||||
let MP = THREE.Mesh.prototype,
|
||||
XP = THREE.Box3.prototype,
|
||||
BP = THREE.BufferGeometry.prototype;
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
../../node_modules/three/examples/js/utils/BufferGeometryUtils.js
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../node_modules/three-mesh-bvh/build/index.umd.cjs
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../node_modules/three/examples/js/loaders/SVGLoader.js
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../node_modules/three/build/three.min.js
|
||||
|
|
@ -28,7 +28,7 @@ gapp.register("kiri.ui", [], (root, exports) => {
|
|||
lastTxt = null,
|
||||
lastPop = null;
|
||||
|
||||
self.$ = (self.$ || function (id) { return DOC.getElementById(id) } );
|
||||
self.$ = function (id) { return DOC.getElementById(id) };
|
||||
|
||||
kiri.ui = {
|
||||
prefix: function(pre) { prefix = pre; return kiri.ui },
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
(function() {
|
||||
|
||||
let load = self.load = self.load || {};
|
||||
if (load.TMF) return;
|
||||
|
||||
// dep: add.three
|
||||
// dep: ext.jszip
|
||||
gapp.register('load.3mf');
|
||||
gapp.register('load.3mf', [], (root, exports) => {
|
||||
|
||||
let load = self.load = self.load || {};
|
||||
|
||||
if (load.TMF) return;
|
||||
|
||||
load.TMF = {
|
||||
parseAsync
|
||||
|
|
@ -174,4 +173,4 @@ function parseAsync(data) {
|
|||
});
|
||||
}
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
@ -72,10 +72,13 @@ function exargs(args) {
|
|||
|
||||
// register module without a load function
|
||||
gapp.register = function() {
|
||||
// console.log(1, { mods });
|
||||
const args = exargs([...arguments]);
|
||||
const name = args.strings[0];
|
||||
const fn = args.funcs[0];
|
||||
const mod = { fn, name };
|
||||
// console.log(2, { mods });
|
||||
// console.log('reg', { mod, mods });
|
||||
mods.push(mod);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
// dep: moto.broker
|
||||
// dep: moto.space
|
||||
// dep: mesh.util
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
// dep: add.three
|
||||
// use: add.array
|
||||
gapp.register("mesh.api", [], (root, exports) => {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
// dep: moto.license
|
||||
// dep: add.array
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
// dep: add.three
|
||||
gapp.register("mesh.geom", [], (root, exports) => {
|
||||
|
||||
const { Matrix4, Matrix3, Vector3, Box3 } = THREE;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
// dep: moto.license
|
||||
// dep: add.array
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
// dep: add.three
|
||||
gapp.register("mesh.util", [], (root, exports) => {
|
||||
|
||||
const { Matrix4, Matrix3, Vector3, Box3 } = THREE;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
// dep: moto.license
|
||||
// dep: ext.clip2
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
// dep: add.three
|
||||
// dep: add.array
|
||||
// dep: moto.client
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
gapp.register("moto.space", [], (root, exports) => {
|
||||
|
||||
const { moto } = root;
|
||||
const { WebGLRenderer, WebGL1Renderer } = THREE;
|
||||
const { WebGLRenderer } = THREE;
|
||||
const nav = navigator;
|
||||
|
||||
let WIN = window,
|
||||
|
|
@ -254,7 +254,7 @@ gapp.register("moto.space", [], (root, exports) => {
|
|||
}
|
||||
|
||||
function addLight(x, y, z, i, color = 0xffffff) {
|
||||
let l = new THREE.DirectionalLight(color, i, 0);
|
||||
let l = new THREE.DirectionalLight(color, i * 4);
|
||||
l.position.set(x,z,y);
|
||||
if (lightInfo.debug) {
|
||||
let b; l.add(b = new THREE.Mesh(
|
||||
|
|
@ -1332,18 +1332,15 @@ gapp.register("moto.space", [], (root, exports) => {
|
|||
domelement.style.width = width();
|
||||
domelement.style.height = height();
|
||||
|
||||
// workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=1321452
|
||||
// and android requires older rendered to avoid visual Z order artifacts
|
||||
let Renderer =
|
||||
(nav.platform.indexOf('Linux') >= 0) ||
|
||||
(nav.platform === 'MacIntel' && nav.vendor.indexOf('Google') >= 0) ?
|
||||
WebGL1Renderer : WebGLRenderer;
|
||||
|
||||
renderer = new Renderer({
|
||||
renderer = new WebGLRenderer({
|
||||
antialias: antiAlias,
|
||||
preserveDrawingBuffer: true,
|
||||
logarithmicDepthBuffer: true
|
||||
});
|
||||
|
||||
// THREE.ColorManagement.enabled = false;
|
||||
// renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
|
||||
|
||||
renderer.localClippingEnabled = true;
|
||||
camera = ortho ?
|
||||
new THREE.OrthographicCamera(-100 * aspect(), 100 * aspect(), 100, -100, 0.1, 100000) :
|
||||
|
|
|
|||
Loading…
Reference in a new issue