Skip to content

Commit fcd1f1c

Browse files
committed
feat: load custom emitter instance model
1 parent 934193c commit fcd1f1c

27 files changed

Lines changed: 818 additions & 25 deletions

File tree

contributes/meta3d-action-mod-unit-publish-to-game/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "meta3d-action-mod-unit-publish-to-game",
3-
"version": "1.3.42",
3+
"version": "1.3.49",
44
"publisher": "meta3d",
55
"protocol": {
66
"name": "meta3d-action-mod-unit-publish-to-game-protocol"

contributes/meta3d-action-mod-unit-quicktest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "meta3d-action-mod-unit-quicktest",
3-
"version": "1.3.28",
3+
"version": "1.3.29",
44
"publisher": "meta3d",
55
"protocol": {
66
"name": "meta3d-action-mod-unit-quicktest-protocol"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.DS_Store
2+
.merlin
3+
.log
4+
.ninja_log
5+
.cmi
6+
.ast
7+
.cmt
8+
.bsdeps
9+
.compiler.log
10+
11+
.idea/
12+
.vscode/
13+
jest_0/
14+
reference/
15+
node_modules/
16+
mine/
17+
dist/
18+
lib/bs/
19+
.bs.js
20+
.gen.tsx
21+
lib/js/
22+
lib/es6_global/
23+
24+
coverage
25+
26+
dist/
27+
28+
npm-debug
29+
30+
.bsb.lock
31+
32+
yarn.lock
33+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var gulp = require("gulp");
2+
var path = require("path");
3+
var fs = require("fs");
4+
var publish = require("meta3d-tool-publish")
5+
var bundle = require("meta3d-tool-bundle-to-custom")
6+
var clipboard = require('clipboardy')
7+
8+
gulp.task("publish_local_env_bundle", function (done) {
9+
let filePath = "./src/Main.ts"
10+
11+
let bundleContent = bundle.bundle(
12+
bundle.getLocalModulePath(
13+
filePath
14+
),
15+
fs.readFileSync(filePath, "utf-8")
16+
)
17+
18+
let clipedBundleContent = `import { api } from "meta3d-type"
19+
import { service as editorWholeService } from "meta3d-editor-whole-protocol/src/service/ServiceType"
20+
` + bundleContent
21+
clipedBundleContent = clipedBundleContent.replace(/getContribute\s\=\s\(api\)/g, "getContribute = (api:api)")
22+
23+
clipboard.default.writeSync(
24+
clipedBundleContent
25+
)
26+
27+
28+
29+
publish.publishBundledContribute(
30+
"local",
31+
path.join(__dirname, "package.json"),
32+
bundleContent
33+
).then(() => {
34+
done()
35+
})
36+
});
37+
38+
39+
40+
// gulp.task("publish_local_env", function (done) {
41+
// publish.publishContribute(
42+
// "local",
43+
// path.join(__dirname, "package.json"),
44+
// path.join(__dirname, "dist/static/js", "main.js")
45+
// ).then(() => {
46+
// done()
47+
// })
48+
// });
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// declare module 'asset-loader!*' {
2+
// // const contents: { default: string }
3+
// const contents: string
4+
// // const contents: ArrayBuffer
5+
// export = contents
6+
// }
7+
8+
declare module '*' {
9+
// const contents: { default: string }
10+
const contents: string
11+
// const contents: ArrayBuffer
12+
export = contents
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "meta3d-action-mod-unit-upload-particle-instance",
3+
"version": "1.3.2",
4+
"publisher": "meta3d",
5+
"protocol": {
6+
"name": "meta3d-action-mod-unit-upload-particle-instance-protocol"
7+
},
8+
"license": "MIT",
9+
"scripts": {
10+
"watch": "tsc -w -noEmit",
11+
"webpack": "webpack --config webpack.config.js",
12+
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
13+
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env_bundle"
14+
},
15+
"keywords": [],
16+
"dependencies": {
17+
"meta3d-action-mod-unit-upload-particle-instance-protocol": "^1.3.0",
18+
"meta3d-editor-whole-protocol": "^1.3.0",
19+
"meta3d-type": "^1.3.0"
20+
},
21+
"devDependencies": {
22+
"clean-webpack-plugin": "^4.0.0",
23+
"clipboardy": "^5.0.2",
24+
"cross-env": "^7.0.3",
25+
"cz-customizable": "^6.3.0",
26+
"gulp": "^4.0.2",
27+
"meta3d-tool-publish": "^1.3.0",
28+
"source-map-loader": "^3.0.0",
29+
"ts-loader": "^9.2.6",
30+
"typescript": "^5.1.0",
31+
"webpack": "^5.62.1",
32+
"webpack-cli": "^4.9.1"
33+
}
34+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { state as meta3dState, getContribute as getContributeMeta3D, api } from "meta3d-type"
2+
import { actionContribute, service as editorWholeService } from "meta3d-editor-whole-protocol/src/service/ServiceType"
3+
import { actionName, state, uiData } from "meta3d-action-mod-unit-upload-particle-instance-protocol"
4+
import { eventName, glbName, glbData, inputData } from "meta3d-action-mod-unit-upload-particle-instance-protocol/src/EventType"
5+
import { actionName as initActionName, state as initState } from "meta3d-action-mod-unit-init-protocol"
6+
import { nullable } from "meta3d-commonlib-ts/src/nullable"
7+
import { importFile } from "meta3d-file-ts-utils/src/ImportFileUtils"
8+
import { getLanguageTextData, getLanguageTextVariableData } from "meta3d-language-utils/src/Main"
9+
import { languageKey, languageVariableKey } from "meta3d-language-utils/src/Type"
10+
11+
let _loadGLB = (api: api): Promise<[boolean, nullable<glbName>, nullable<glbData>]> => {
12+
return new Promise((resolve, reject) => {
13+
importFile((file: any, result: any) => {
14+
if (!file.name.includes(".glb")) {
15+
reject(new Error("文件后缀名应该是.glb"))
16+
}
17+
18+
// resolve([true, api.nullable.return(file.name.slice(0, -3)), api.nullable.return(result as ArrayBuffer)])
19+
resolve([true, api.nullable.return(file.name), api.nullable.return(result as ArrayBuffer)])
20+
}, (event: Event, file: any) => {
21+
reject(new Error(`读取${file.name}错误`))
22+
}, (loaded: number, total: number) => {
23+
// TODO show progress message
24+
console.log(`loading ${loaded / total} %`)
25+
}, () => {
26+
resolve([false, api.nullable.getEmpty(), api.nullable.getEmpty()])
27+
})
28+
})
29+
}
30+
31+
export let getContribute: getContributeMeta3D<actionContribute<uiData, state>> = (api) => {
32+
return {
33+
actionName: actionName,
34+
init: (meta3dState) => {
35+
let eventSourcingService = api.nullable.getExn(api.getPackageService<editorWholeService>(meta3dState, "meta3d-editor-whole-protocol")).event(meta3dState).eventSourcing(meta3dState)
36+
37+
return new Promise((resolve, reject) => {
38+
resolve(eventSourcingService.on<inputData>(meta3dState, eventName, 0, (meta3dState, uiData, glbName, glbData, [selectedSkillObjectEmitterInstanceIndexFieldName]) => {
39+
let initState = api.action.getActionState<initState>(meta3dState, initActionName)
40+
41+
if (glbData.byteLength > 0.5 * 1024 * 1024) {
42+
api.message.warn(getLanguageTextVariableData(api, meta3dState, initState.languageTextDataByVariable, languageVariableKey.LimitFileSize)(0.5))
43+
return Promise.resolve(meta3dState)
44+
}
45+
46+
47+
api.message.success(getLanguageTextData(api, meta3dState, initState.languageTextData, languageKey.Success))
48+
49+
50+
let state = api.action.getActionState<state>(meta3dState, actionName)
51+
meta3dState = api.action.setActionState<state>(meta3dState, actionName, {
52+
...state,
53+
instances: state.instances.set(selectedSkillObjectEmitterInstanceIndexFieldName, api.nullable.return([glbName, glbData]))
54+
})
55+
56+
meta3dState = api.action.setActionState<initState>(meta3dState, initActionName, {
57+
...initState,
58+
[selectedSkillObjectEmitterInstanceIndexFieldName]: api.nullable.getEmpty()
59+
})
60+
61+
62+
return Promise.resolve(meta3dState)
63+
}, (meta3dState) => {
64+
return Promise.resolve(meta3dState)
65+
}))
66+
})
67+
},
68+
handler: (meta3dState, uiData, actionParams) => {
69+
return _loadGLB(api).then(([isSuccess, glbName, glbData]) => {
70+
if (!isSuccess) {
71+
return meta3dState
72+
}
73+
74+
return new Promise<meta3dState>((resolve, reject) => {
75+
let eventSourcingService = api.nullable.getExn(api.getPackageService<editorWholeService>(meta3dState, "meta3d-editor-whole-protocol")).event(meta3dState).eventSourcing(meta3dState)
76+
77+
78+
resolve(eventSourcingService.addEvent<inputData>(meta3dState, {
79+
name: eventName,
80+
isOnlyRead: true,
81+
inputData: [
82+
uiData,
83+
glbName,
84+
glbData,
85+
actionParams
86+
]
87+
}))
88+
})
89+
}).catch((error) => {
90+
api.message.error(error)
91+
return meta3dState
92+
})
93+
94+
},
95+
createState: () => {
96+
return {
97+
instances: api.immutable.createMap()
98+
}
99+
}
100+
}
101+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"module": "ES6",
5+
"moduleResolution": "node",
6+
"sourceMap": true,
7+
"resolveJsonModule": true,
8+
"esModuleInterop": true,
9+
"jsx": "react",
10+
// "noEmit": true,
11+
// "noUnusedLocals": true,
12+
// "noUnusedParameters": true,
13+
"noImplicitReturns": true,
14+
"lib": [
15+
"DOM",
16+
"ESNext",
17+
],
18+
"types": [
19+
"node"
20+
],
21+
// "strict": true
22+
},
23+
"include": [
24+
"./src",
25+
"./loader.d.ts"
26+
]
27+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
const path = require('path');
2+
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
3+
4+
module.exports = {
5+
entry: "./src/Main.ts",
6+
mode: process.env.NODE_ENV.trim() == 'production' ? 'production' : 'development',
7+
output: {
8+
path: path.resolve(__dirname, 'dist'),
9+
filename: 'static/js/[name].js',
10+
library: {
11+
name: 'Contribute',
12+
type: 'window',
13+
},
14+
},
15+
16+
// Enable sourcemaps for debugging webpack's output.
17+
// devtool: "source-map",
18+
19+
resolve: {
20+
extensions: ['.ts', '.tsx', '.js', '.jsx', '.scss'],
21+
modules: ['node_modules']
22+
},
23+
24+
module: {
25+
rules: [
26+
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
27+
{
28+
test: /\.tsx?$/,
29+
exclude: /node_modules/,
30+
use: "ts-loader"
31+
},
32+
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
33+
{
34+
enforce: 'pre',
35+
test: /\.js$/,
36+
loader: "source-map-loader"
37+
},
38+
{
39+
test: /index.html|meta3d.js|basis_transcoder.js|draco_decoder.js|draco_encoder.js/,
40+
type: 'asset/inline',
41+
generator: {
42+
dataUrl: content => {
43+
return content.toString()
44+
}
45+
}
46+
},
47+
// {
48+
// test: /meta3d.js/,
49+
// type: 'asset/inline',
50+
// generator: {
51+
// dataUrl: content => {
52+
// return content.toString()
53+
// }
54+
// }
55+
// },
56+
// {
57+
// test: /basis_transcoder.js/,
58+
// type: 'asset/inline',
59+
// generator: {
60+
// dataUrl: content => {
61+
// return content.toString()
62+
// }
63+
// }
64+
// },
65+
// {
66+
// test: /draco_decoder.js/,
67+
// type: 'asset/inline',
68+
// generator: {
69+
// dataUrl: content => {
70+
// return content.toString()
71+
// }
72+
// }
73+
// },
74+
// {
75+
// test: /draco_encoder.js/,
76+
// type: 'asset/inline',
77+
// generator: {
78+
// dataUrl: content => {
79+
// return content.toString()
80+
// }
81+
// }
82+
// },
83+
]
84+
},
85+
plugins: [
86+
/**
87+
* All files inside webpack's output.path directory will be removed once, but the
88+
* directory itself will not be. If using webpack 4+'s default configuration,
89+
* everything under <PROJECT_DIR>/dist/ will be removed.
90+
* Use cleanOnceBeforeBuildPatterns to override this behavior.
91+
*
92+
* During rebuilds, all webpack assets that are not used anymore
93+
* will be removed automatically.
94+
*
95+
* See `Options and Defaults` for information
96+
*/
97+
new CleanWebpackPlugin(),
98+
// new HtmlWebpackPlugin({
99+
// template: './user.html',
100+
// filename: 'user.html',
101+
// }),
102+
],
103+
// When importing a module whose path matches one of the following, just
104+
// assume a corresponding global variable exists and use that instead.
105+
// This is important because it allows us to avoid bundling all of our
106+
// dependencies, which allows browsers to cache those libraries between builds.
107+
externals: {
108+
}
109+
};

0 commit comments

Comments
 (0)