Skip to content

Commit

Permalink
feat: add publish action, engine whole package
Browse files Browse the repository at this point in the history
pass run test;
  • Loading branch information
yyc-git committed Nov 13, 2023
1 parent e2efe9a commit cf8d929
Show file tree
Hide file tree
Showing 253 changed files with 18,391 additions and 104 deletions.
13 changes: 13 additions & 0 deletions contributes/meta3d-action-publish/loader.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// declare module 'asset-loader!*' {
// // const contents: { default: string }
// const contents: string
// // const contents: ArrayBuffer
// export = contents
// }

declare module '*' {
// const contents: { default: string }
const contents: string
// const contents: ArrayBuffer
export = contents
}
40 changes: 40 additions & 0 deletions contributes/meta3d-action-publish/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "meta3d-action-publish",
"version": "0.20.2",
"publisher": "0xf63e1991A343814EdE505D7cfC368615EAe75307",
"protocol": {
"name": "meta3d-action-publish-protocol"
},
"license": "MIT",
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env"
},
"keywords": [],
"packageDependencies": {
"meta3d-engine-whole-protocol": "^0.20.0"
},
"dependencies": {
"@types/file-saver": "^2.0.5",
"file-saver": "^2.0.5",
"jszip": "^3.10.1",
"meta3d-action-publish-protocol": "^0.20.0",
"meta3d-action-run-protocol": "^0.20.0",
"meta3d-editor-whole-protocol": "^0.20.0",
"meta3d-type": "^0.20.0"
},
"devDependencies": {
"clean-webpack-plugin": "^4.0.0",
"cross-env": "^7.0.3",
"cz-customizable": "^6.3.0",
"gulp": "^4.0.2",
"meta3d-tool-publish": "^0.20.0",
"source-map-loader": "^3.0.0",
"ts-loader": "^9.2.6",
"typescript": "^4.2.3",
"webpack": "^5.62.1",
"webpack-cli": "^4.9.1"
}
}
125 changes: 125 additions & 0 deletions contributes/meta3d-action-publish/publish/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8" />
<title>Meta3D</title>

<style>
#loading {
display: block;
/* color: #e7981f; */
/* margin-top: 10px; */
font-size: 85px;
font-weight: bold;
}
</style>
</head>

<body>
<section>
<span id="loading">
loading...
</span>
</section>

<!-- TODO full screen -->
<canvas id="canvas" width=800 height=800></canvas>

<script src="./meta3d.js"></script>

<script>
window.onload = () => {
let _removeLoadingUI = () => {
document.querySelector("#loading").remove()
}

let _loop = (
[

update, render,
],
meta3dState,
) => {
return update(meta3dState).then((meta3dState) => {
render(meta3dState).then((meta3dState) => {
requestAnimationFrame(() => {
_loop(
[
update, render,
],
meta3dState
)
})
})
})
}

let _main = () => {
let isDebug = true

let float9Array1 = new Float32Array(9)
let float32Array1 = new Float32Array(32)
let transformCount = 100000
let geometryCount = 100000
let geometryPointCount = 10000000
let pbrMaterialCount = 100000

let canvas = document.querySelector("#canvas")

fetch("./Engine.arraybuffer")
.then(response => response.arrayBuffer())
.then(enginePackageBinaryFile => {
return fetch("./Scene.glb")
.then(response => response.arrayBuffer())
.then(sceneGlb => {
_removeLoadingUI()

return [enginePackageBinaryFile, sceneGlb]
})
})
.then(([enginePackageBinaryFile, sceneGlb]) => {
let [meta3dState, _, entryExtensionProtocolName] = Meta3d.loadPackage(enginePackageBinaryFile)

if (entryExtensionProtocolName !== "meta3d-engine-whole-protocol") {
throw new Error(
`entryExtensionProtocolName: ${entryExtensionProtocolName} should be meta3d-engine-whole-protocol`
)
}


let { loadScene, prepare, init, update, render, scene } = Meta3d.getExtensionService(meta3dState, entryExtensionProtocolName)

meta3dState = prepare(
meta3dState,
isDebug,
{
float9Array1,
float32Array1,
transformCount,
geometryCount,
geometryPointCount,
pbrMaterialCount
}
)

return loadScene(meta3dState, sceneGlb).then(meta3dState => {
return init(meta3dState, canvas).then(meta3dState => {
console.log("init success", meta3dState)

_loop([update, render], meta3dState)
})
})
})
.catch(error => {
console.error(error)
})
}

_main()
}
</script>
</body>


</html>
1,081 changes: 1,081 additions & 0 deletions contributes/meta3d-action-publish/publish/meta3d.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions contributes/meta3d-action-publish/src/Main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { getContribute as getContributeMeta3D } from "meta3d-type"
import { state as meta3dState } from "meta3d-type"
import { actionContribute } from "meta3d-event-protocol/src/contribute/ActionContributeType"
import { service as editorWholeService } from "meta3d-editor-whole-protocol/src/service/ServiceType"
import * as JSZip from "jszip"
import { saveAs } from "file-saver";
import { getExn } from "meta3d-commonlib-ts/src/NullableUtils"
import indexHtml from "../publish/index.html"
import meta3dJs from "../publish/meta3d.js"
import basis_transcoderJs from "../publish/three/basis/basis_transcoder.js"
import draco_decoderJs from "../publish/three/draco/gltf/draco_decoder.js"
import draco_encoderJs from "../publish/three/draco/gltf/draco_encoder.js"
import { clickUIData } from "meta3d-ui-control-button-protocol"
import { actionName, state } from "meta3d-action-publish-protocol"
import { getActionState } from "meta3d-ui-utils/src/ElementStateUtils"
import { actionName as runActionName, state as runState } from "meta3d-action-run-protocol"
import { eventName, inputData } from "meta3d-action-publish-protocol/src/EventType"

let _loadAndWriteIndexHtmlData = (zip: JSZip) => {
zip.file("index.html", indexHtml)
}

let _loadAndWriteIndexJsData = (zip: JSZip) => {
zip.file("meta3d.js", meta3dJs)
}

let _loadAndWriteThreeJsData = (zip: JSZip, folderPath: string, name: string, jsFile: any) => {
zip.file(`static/three/${folderPath}${name}.js`, jsFile)
}


export let getContribute: getContributeMeta3D<actionContribute<clickUIData, state>> = (api) => {
return {
actionName: actionName,
init: (meta3dState) => {
let eventSourcingService = getExn(api.getPackageService<editorWholeService>(meta3dState, "meta3d-editor-whole-protocol")).event(meta3dState).eventSourcing(meta3dState)

return new Promise((resolve, reject) => {
resolve(eventSourcingService.on<inputData>(meta3dState, eventName, 0, (meta3dState) => {
if (getActionState<runState>(meta3dState, api, runActionName).isRun) {
console.warn("can't publish when run")

return (new Promise((resolve) => {
resolve(meta3dState)
}))
}

let enginePackageBinary = getExn(api.getPackage(meta3dState, "meta3d-engine-whole-protocol"))


let zip = new JSZip.default() as JSZip

_loadAndWriteIndexHtmlData(zip)
_loadAndWriteIndexJsData(zip)

_loadAndWriteThreeJsData(zip, "basis/", "basis_transcoder", basis_transcoderJs)
_loadAndWriteThreeJsData(zip, "draco/gltf/", "draco_decoder", draco_decoderJs)
_loadAndWriteThreeJsData(zip, "draco/gltf/", "draco_encoder", draco_encoderJs)

return (new Promise((resolve, reject) => {
return getExn(api.getPackageService<editorWholeService>(meta3dState, "meta3d-editor-whole-protocol")).exportScene([(glb) => {
resolve(glb)
}, (err) => {
throw err
}], meta3dState)
}) as Promise<ArrayBuffer>)
.then(sceneGLB => {
zip.file("Engine.arraybuffer", enginePackageBinary, { binary: true })
zip.file("Scene.glb", sceneGLB, { binary: true })

return zip.generateAsync({ type: "blob" })
}).then(content => {
// TODO get zipname from user
saveAs(content, "publish.zip")

return meta3dState
})
}, (meta3dState) => {
return Promise.resolve(meta3dState)
}))
})

},
handler: (meta3dState, uiData) => {
//console.log("publish")

return new Promise<meta3dState>((resolve, reject) => {
let eventSourcingService = getExn(api.getPackageService<editorWholeService>(meta3dState, "meta3d-editor-whole-protocol")).event(meta3dState).eventSourcing(meta3dState)

resolve(eventSourcingService.addEvent<inputData>(meta3dState, {
name: eventName,
isOnlyRead: true,
inputData: []
}))
})
},
createState: () => null
}
}
25 changes: 25 additions & 0 deletions contributes/meta3d-action-publish/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES6",
"module": "ES6",
"moduleResolution": "node",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"jsx": "react",
// "noEmit": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
"noImplicitReturns": true,
"lib": [
"DOM",
"ESNext",
],
"types": [],
"strict": true
},
"include": [
"./src",
"./loader.d.ts"
]
}
Loading

0 comments on commit cf8d929

Please sign in to comment.