зеркало из https://github.com/mozilla/Spoke.git
Merge branch 'master' of github.com:mozillareality/hubs-editor
This commit is contained in:
Коммит
a5e9672d0d
|
@ -12795,7 +12795,7 @@
|
|||
}
|
||||
},
|
||||
"three": {
|
||||
"version": "github:mozillareality/three.js#e86afa5bb698350c2ebddcda70b3e7929143444f",
|
||||
"version": "github:mozillareality/three.js#6216b8bfc42ac21fbdecfb69405d657f45685370",
|
||||
"from": "github:mozillareality/three.js#hubs-editor/dev"
|
||||
},
|
||||
"three-pathfinding": {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
],
|
||||
"scripts": {
|
||||
"dev": "cross-env NODE_ENV=development node ./bin/hubs-editor ./example",
|
||||
"dev:nopath": "cross-env NODE_ENV=development node ./bin/hubs-editor",
|
||||
"build": "concurrently \"npm run build:server\" \"npm run build:client\"",
|
||||
"build:server": "babel src/server/ -d lib/server/",
|
||||
"build:client": "webpack --mode production",
|
||||
|
@ -27,6 +28,7 @@
|
|||
"fast-deep-equal": "^2.0.1",
|
||||
"fs-extra": "^6.0.1",
|
||||
"gltf-bundle": "^0.10.0",
|
||||
"gltf-unlit-generator": "^0.3.0",
|
||||
"koa": "^2.5.1",
|
||||
"koa-body": "^4.0.3",
|
||||
"koa-mount": "^3.0.0",
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
import path from "path";
|
||||
import crypto from "crypto";
|
||||
import fs from "fs-extra";
|
||||
|
||||
export default function hashFileName(resourcePath, content) {
|
||||
const { name, ext } = path.parse(resourcePath);
|
||||
const hash = crypto.createHash("md5");
|
||||
const digest = hash
|
||||
.update(content)
|
||||
.digest("hex")
|
||||
.substr(0, 10);
|
||||
|
||||
if (ext === ".gltf") {
|
||||
return name + "-" + digest + ext;
|
||||
}
|
||||
|
||||
return digest + ext;
|
||||
}
|
||||
|
||||
export async function contentHashAndCopy(resourceArray, srcDir, destDir, move) {
|
||||
if (Array.isArray(resourceArray)) {
|
||||
for (const resource of resourceArray) {
|
||||
if (resource.uri) {
|
||||
const resourcePath = path.resolve(srcDir, resource.uri);
|
||||
const content = await fs.readFile(resourcePath);
|
||||
const fileName = hashFileName(resourcePath, content);
|
||||
const destResourcePath = path.join(destDir, fileName);
|
||||
|
||||
if (move) {
|
||||
await fs.move(resourcePath, destResourcePath, {
|
||||
overwrite: true
|
||||
});
|
||||
} else {
|
||||
await fs.copy(resourcePath, destResourcePath, {
|
||||
overwrite: true
|
||||
});
|
||||
}
|
||||
|
||||
resource.uri = fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resourceArray;
|
||||
}
|
|
@ -11,6 +11,8 @@ import fs from "fs-extra";
|
|||
import chokidar from "chokidar";
|
||||
import debounce from "lodash.debounce";
|
||||
import opn from "opn";
|
||||
import generateUnlitTextures from "gltf-unlit-generator";
|
||||
import { contentHashAndCopy } from "./gltf";
|
||||
|
||||
async function getProjectHierarchy(projectPath) {
|
||||
async function buildProjectNode(filePath, name, ext, isDirectory, uri) {
|
||||
|
@ -228,9 +230,18 @@ export default async function startServer(options) {
|
|||
const { sceneURI, outputURI } = ctx.request.body;
|
||||
|
||||
const scenePath = path.resolve(projectPath, sceneURI.replace("/api/files/", ""));
|
||||
const sceneDirPath = path.dirname(scenePath);
|
||||
const outputPath = path.resolve(projectPath, outputURI.replace("/api/files/", ""));
|
||||
const outputDirPath = path.dirname(outputPath);
|
||||
|
||||
console.log(`Optimize ${scenePath} and output to: ${outputPath}`);
|
||||
await generateUnlitTextures(scenePath, outputDirPath);
|
||||
|
||||
const json = await fs.readJSON(outputPath);
|
||||
|
||||
json.images = await contentHashAndCopy(json.images, sceneDirPath, outputDirPath);
|
||||
json.buffers = await contentHashAndCopy(json.buffers, sceneDirPath, outputDirPath, true);
|
||||
|
||||
await fs.writeJSON(outputPath, json);
|
||||
|
||||
ctx.body = {
|
||||
success: true
|
||||
|
|
Загрузка…
Ссылка в новой задаче