Skip to content

Commit

Permalink
feat(editor): use "add gameobject" instead of "add cube" in scenetree
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Mar 15, 2024
1 parent fa626cb commit 127795d
Show file tree
Hide file tree
Showing 22 changed files with 285 additions and 32 deletions.
34 changes: 34 additions & 0 deletions contributes/meta3d-action-add-gameobject/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "meta3d-action-add-gameobject",
"version": "1.3.3",
"publisher": "meta3d",
"protocol": {
"name": "meta3d-action-add-gameobject-protocol"
},
"license": "MIT",
"scripts": {
"watch": "tsc -w -noEmit",
"webpack": "webpack --config webpack.config.js",
"meta3d:publish_dev_auto": "yarn version --patch --no-git-tag-version && yarn meta3d:publish_dev",
"meta3d:publish_dev": "cross-env NODE_ENV=development npm run webpack && gulp publish_local_env_bundle",
"meta3d:publish_pro": "cross-env NODE_ENV=production npm run webpack && gulp publish_production_env_bundle"
},
"keywords": [],
"dependencies": {
"meta3d-action-add-gameobject-protocol": "^1.2.0",
"meta3d-editor-whole-protocol": "^1.3.0",
"meta3d-type": "^1.3.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": "^1.3.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"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
import { state as meta3dState, getContribute as getContributeMeta3D, api } from "meta3d-type"
import { actionContribute, service as editorWholeService } from "meta3d-editor-whole-protocol/src/service/ServiceType"
import { actionName, state, uiData } from "meta3d-action-add-cube-protocol"
import { eventName, inputData } from "meta3d-action-add-cube-protocol/src/EventType"
import { actionName, state, uiData, gameObjectType } from "meta3d-action-add-gameobject-protocol"
import { eventName, inputData } from "meta3d-action-add-gameobject-protocol/src/EventType"
import { disposeGameObjectAndAllChildren } from "meta3d-dispose-utils/src/DisposeGameObjectUtils"
import { createCubeGameObject } from "meta3d-primitive-utils/src/CubeUtils"
import { runGameViewRenderOnlyOnce } from "meta3d-gameview-render-utils/src/GameViewRenderUtils"

let _getGameObjectType = (selectedIndex: number): gameObjectType => {
switch (selectedIndex) {
case 0:
return gameObjectType.EmptyGameObject
case 1:
default:
return gameObjectType.Cube
}
}

let _createEmptyGameObject = (meta3dState: meta3dState, api: api) => {
let engineSceneService = api.nullable.getExn(api.getPackageService<editorWholeService>(meta3dState, "meta3d-editor-whole-protocol")).scene(meta3dState)

let data = engineSceneService.gameObject.createGameObject(meta3dState)
meta3dState = data[0]
let gameObject = data[1]

meta3dState = engineSceneService.gameObject.setGameObjectName(meta3dState, gameObject, "GameObject")

data = engineSceneService.transform.createTransform(meta3dState)
meta3dState = data[0]
let transform = data[1]

meta3dState = engineSceneService.gameObject.addTransform(meta3dState, gameObject, transform)

return [meta3dState, gameObject]
}

let _createCube = (meta3dState: meta3dState, api: api) => {
let engineSceneService = api.nullable.getExn(api.getPackageService<editorWholeService>(meta3dState, "meta3d-editor-whole-protocol")).scene(meta3dState)

Expand All @@ -22,8 +50,22 @@ export let getContribute: getContributeMeta3D<actionContribute<uiData, state>> =
let eventSourcingService = api.nullable.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) => {
let data = _createCube(meta3dState, api)
resolve(eventSourcingService.on<inputData>(meta3dState, eventName, 0, (meta3dState, selectedIndex) => {
let data = null

let type = _getGameObjectType(selectedIndex)

switch (type) {
case gameObjectType.EmptyGameObject:
data = _createEmptyGameObject(meta3dState, api)
break
case gameObjectType.Cube:
default:
data = _createCube(meta3dState, api)
break
}


meta3dState = data[0]
let addedGameObject = data[1]

Expand All @@ -34,16 +76,16 @@ export let getContribute: getContributeMeta3D<actionContribute<uiData, state>> =
meta3dState = api.action.setActionState(meta3dState, actionName, {
...state,
addedGameObjects:
state.addedGameObjects.push(addedGameObject)
state.addedGameObjects.push([type, addedGameObject])
})

return Promise.resolve(runGameViewRenderOnlyOnce(meta3dState,api, api.nullable.getExn(api.getPackageService<editorWholeService>(meta3dState, "meta3d-editor-whole-protocol"))))
return Promise.resolve(runGameViewRenderOnlyOnce(meta3dState, api, api.nullable.getExn(api.getPackageService<editorWholeService>(meta3dState, "meta3d-editor-whole-protocol"))))
}, (meta3dState) => {
let {
addedGameObjects,
} = api.nullable.getExn(api.action.getActionState<state>(meta3dState, actionName))

let disposedGameObject = api.nullable.getExn(addedGameObjects.last())
let [_, disposedGameObject] = api.nullable.getExn(addedGameObjects.last())

let state = api.nullable.getExn(api.action.getActionState<state>(meta3dState, actionName))

Expand All @@ -63,9 +105,11 @@ export let getContribute: getContributeMeta3D<actionContribute<uiData, state>> =
return new Promise<meta3dState>((resolve, reject) => {
let eventSourcingService = api.nullable.getExn(api.getPackageService<editorWholeService>(meta3dState, "meta3d-editor-whole-protocol")).event(meta3dState).eventSourcing(meta3dState)

let selectedIndex = uiData

resolve(eventSourcingService.addEvent<inputData>(meta3dState, {
name: eventName,
inputData: []
inputData: [selectedIndex]
}))
})
},
Expand Down
39 changes: 39 additions & 0 deletions contributes/meta3d-input-add-gameobject/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var gulp = require("gulp");
var path = require("path");
var fs = require("fs");
var publish = require("meta3d-tool-publish")
var bundle = require("meta3d-tool-bundle-to-custom")

gulp.task("publish_local_env_bundle", function (done) {
let filePath = "./src/Main.ts"

publish.publishBundledContribute(
"local",
path.join(__dirname, "package.json"),
bundle.bundle(
bundle.getLocalModulePath(
filePath
),
fs.readFileSync(filePath, "utf-8")
)
).then(() => {
done()
})
});

gulp.task("publish_production_env_bundle", function (done) {
let filePath = "./src/Main.ts"

publish.publishBundledContribute(
"production",
path.join(__dirname, "package.json"),
bundle.bundle(
bundle.getLocalModulePath(
filePath
),
fs.readFileSync(filePath, "utf-8")
)
).then(() => {
done()
})
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"name": "meta3d-action-add-cube",
"name": "meta3d-input-add-gameobject",
"version": "1.3.2",
"publisher": "meta3d",
"displayName": "add-cube",
"repoLink": "https://github.com/Meta3D-Technology/Meta3D/tree/master/contributes/meta3d-action-add-cube",
"description": "add cube action",
"description": "",
"protocol": {
"name": "meta3d-action-add-cube-protocol"
"name": "meta3d-input-popup-protocol"
},
"license": "MIT",
"scripts": {
Expand All @@ -18,8 +16,8 @@
},
"keywords": [],
"dependencies": {
"meta3d-action-add-cube-protocol": "^1.2.0",
"meta3d-editor-whole-protocol": "^1.3.0",
"meta3d-input-popup-protocol": "^1.3.0",
"meta3d-type": "^1.3.0"
},
"devDependencies": {
Expand Down
17 changes: 17 additions & 0 deletions contributes/meta3d-input-add-gameobject/src/Main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { state as meta3dState, getContribute as getContributeMeta3D } from "meta3d-type"
import { data } from "meta3d-input-popup-protocol"
import { inputContribute } from "meta3d-editor-whole-protocol/src/service/ServiceType"

export let getContribute: getContributeMeta3D<inputContribute<data>> = (api) => {
return {
inputName: "AddGameObjectInput",
func: (meta3dState) => {
return Promise.resolve(
[
"Empty GameObject",
"Cube"
]
)
}
}
}
24 changes: 24 additions & 0 deletions contributes/meta3d-input-add-gameobject/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"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"
]
}
64 changes: 64 additions & 0 deletions contributes/meta3d-input-add-gameobject/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
entry: "./src/Main.ts",
mode: process.env.NODE_ENV.trim() == 'production' ? 'production' : 'development',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'static/js/[name].js',
library: {
name: 'Contribute',
type: 'window',
},
},

// Enable sourcemaps for debugging webpack's output.
// devtool: "source-map",

resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.scss'],
modules: ['node_modules']
},

module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: "ts-loader"
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: 'pre',
test: /\.js$/,
loader: "source-map-loader"
},
]
},
plugins: [
/**
* All files inside webpack's output.path directory will be removed once, but the
* directory itself will not be. If using webpack 4+'s default configuration,
* everything under <PROJECT_DIR>/dist/ will be removed.
* Use cleanOnceBeforeBuildPatterns to override this behavior.
*
* During rebuilds, all webpack assets that are not used anymore
* will be removed automatically.
*
* See `Options and Defaults` for information
*/
new CleanWebpackPlugin(),
// new HtmlWebpackPlugin({
// template: './user.html',
// filename: 'user.html',
// }),
],
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
}
};
2 changes: 1 addition & 1 deletion doc/jiehuo.org
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ https://www.grapecity.com.cn/blogs/wyn-3dmodel-bi-analize-data-visualization-sol
# not draw the wall towards camera


** TODO feat: add empty gameObject to scenetree
** DONE feat: add empty gameObject to scenetree

** TODO fix Cube's normal

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.DS_Store
.merlin
.idea/
.vscode/
jest_0/
reference/
node_modules/
mine/
dist/
lib/bs/
.bs.js
.gen.tsx
lib/js/
lib/es6_global/

coverage

dist/

npm-debug

.bsb.lock

yarn.lock

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meta3d-action-add-cube-protocol",
"version": "1.3.1",
"name": "meta3d-action-add-gameobject-protocol",
"version": "1.3.2",
"description": "",
"publisher": "meta3d",
"author": "Meta3D",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const eventName = "AddGameObjectEvent"

export type selectedIndex = number

export type inputData = [selectedIndex]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { gameObject } from "meta3d-gameobject-protocol"
import * as EventType from "./EventType";
import type { List } from "immutable"

export const actionName = "AddGameObject"

export type uiData = EventType.selectedIndex

export enum gameObjectType {
EmptyGameObject,
Cube
}

export type state = {
addedGameObjects: List<[gameObjectType, gameObject]>,
}


0 comments on commit 127795d

Please sign in to comment.