From ba26dc82b688d67883f042b8434b5e490257ac40 Mon Sep 17 00:00:00 2001 From: ShuangLiu Date: Wed, 14 Aug 2024 18:52:26 +0800 Subject: [PATCH] refactor: deprecate packages/effect, move Terrain Grass into packages/geometry (#446) --- package.json | 4 +- packages/effect/README.md | 15 --- packages/effect/grass/GrassNode.ts | 5 - packages/effect/index.ts | 5 - packages/effect/package.json | 24 ---- packages/effect/tsconfig.json | 30 ----- packages/effect/vite.config.js | 26 ---- packages/geometry/README.md | 2 +- .../grass}/GrassGeometry.ts | 10 +- .../grass/component/GrassComponent.ts | 7 +- .../grass/material/GrassMaterial.ts | 0 .../grass/shader/GrassBaseShader.ts | 0 .../grass/shader/GrassCastShadowShader.ts | 0 .../grass/shader/GrassShader.ts | 0 .../shader/GrassVertexAttributeShader.ts | 0 packages/geometry/index.ts | 6 +- packages/geometry/package.json | 2 +- .../terrain}/TerrainGeometry.ts | 2 +- packages/geometry/{ => text}/TextGeometry.ts | 8 +- samples/ext/_Sample_Boxes.ts | 117 ------------------ .../Sample_GrassGeometry.ts} | 2 +- .../Sample_TerrainGeometry.ts} | 2 +- 22 files changed, 22 insertions(+), 245 deletions(-) delete mode 100644 packages/effect/README.md delete mode 100644 packages/effect/grass/GrassNode.ts delete mode 100644 packages/effect/index.ts delete mode 100644 packages/effect/package.json delete mode 100644 packages/effect/tsconfig.json delete mode 100644 packages/effect/vite.config.js rename packages/{effect/grass/geometry => geometry/grass}/GrassGeometry.ts (95%) rename packages/{effect => geometry}/grass/component/GrassComponent.ts (83%) rename packages/{effect => geometry}/grass/material/GrassMaterial.ts (100%) rename packages/{effect => geometry}/grass/shader/GrassBaseShader.ts (100%) rename packages/{effect => geometry}/grass/shader/GrassCastShadowShader.ts (100%) rename packages/{effect => geometry}/grass/shader/GrassShader.ts (100%) rename packages/{effect => geometry}/grass/shader/GrassVertexAttributeShader.ts (100%) rename packages/{effect/terrain/geometry => geometry/terrain}/TerrainGeometry.ts (96%) rename packages/geometry/{ => text}/TextGeometry.ts (89%) delete mode 100644 samples/ext/_Sample_Boxes.ts rename samples/{ext/Sample_Grass.ts => geometry/Sample_GrassGeometry.ts} (98%) rename samples/{ext/Sample_Terrain.ts => geometry/Sample_TerrainGeometry.ts} (98%) diff --git a/package.json b/package.json index 3f628424..e5153186 100644 --- a/package.json +++ b/package.json @@ -32,13 +32,13 @@ "dev": "vite", "build": "tsc --p tsconfig.build.json && vite build && npm run build:types && npm run minify", "build:test": "tsc --p tsconfig.build.json && vite build && npm run build:packages", - "build:packages": "npm run build:physics && npm run build:media && npm run build:stats && npm run build:particle && npm run build:graphic && npm run build:effect", + "build:packages": "npm run build:physics && npm run build:media && npm run build:stats && npm run build:particle && npm run build:graphic && npm run build:geometry", "build:physics": "cd packages/physics && npm run build", "build:media": "cd packages/media-extention && npm run build", "build:stats": "cd packages/stats && npm run build", "build:particle": "cd packages/particle && npm run build", "build:graphic": "cd packages/graphic && npm run build", - "build:effect": "cd packages/effect && npm run build", + "build:geometry": "cd packages/geometry && npm run build", "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json && rm -rf dist/packages && mv dist/src dist/types", "minify": "./node_modules/vite/node_modules/.bin/esbuild dist/orillusion.es.max.js --sourcemap --minify --outfile=dist/orillusion.es.js && ./node_modules/vite/node_modules/.bin/esbuild dist/orillusion.umd.max.js --minify --sourcemap --outfile=dist/orillusion.umd.js", "test": "electron test/ci/main.js", diff --git a/packages/effect/README.md b/packages/effect/README.md deleted file mode 100644 index 2dadee67..00000000 --- a/packages/effect/README.md +++ /dev/null @@ -1,15 +0,0 @@ -Add effect components for [Orillusion](https://www.orillusion.com) - -## Install -```bash -npm install @orillusion/core --save -npm install @orillusion/effect --save -``` - -Or access Global build from CDN -```html - - -``` - -More doc from [Orillusion](https://www.orillusion.com/guide/effect/Readme.html) \ No newline at end of file diff --git a/packages/effect/grass/GrassNode.ts b/packages/effect/grass/GrassNode.ts deleted file mode 100644 index 5f77d432..00000000 --- a/packages/effect/grass/GrassNode.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Transform } from "@orillusion/core"; - -export class GrassNode extends Transform { - -} \ No newline at end of file diff --git a/packages/effect/index.ts b/packages/effect/index.ts deleted file mode 100644 index 39a2fef9..00000000 --- a/packages/effect/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from "./grass/GrassNode"; -export * from "./grass/component/GrassComponent"; -export * from "./grass/geometry/GrassGeometry"; -export * from "./grass/material/GrassMaterial"; -export * from "./terrain/geometry/TerrainGeometry"; diff --git a/packages/effect/package.json b/packages/effect/package.json deleted file mode 100644 index 85bdeeab..00000000 --- a/packages/effect/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "@orillusion/effect", - "version": "0.1.3", - "author": "Orillusion", - "description": "Orillusion Effects Plugin", - "main": "./dist/effect.umd.js", - "module": "./dist/effect.es.js", - "module:dev": "./index.ts", - "types": "./dist/index.d.ts", - "files": ["dist"], - "scripts": { - "build": "vite build && npm run build:types && npm run build:clean", - "build:types": "tsc --emitDeclarationOnly -p tsconfig.json", - "build:clean": "mv dist/packages/effect/* dist && rm -rf dist/src && rm -rf dist/packages" - }, - "license": "MIT", - "repository": { - "type": "git", - "url": "git+https://github.com/Orillusion/orillusion.git" - }, - "dependencies": { - "@orillusion/core": "^0.8.0" - } -} diff --git a/packages/effect/tsconfig.json b/packages/effect/tsconfig.json deleted file mode 100644 index 99cc83e4..00000000 --- a/packages/effect/tsconfig.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "compilerOptions": { - "target": "ESNext", - "useDefineForClassFields": true, - "module": "ESNext", - "lib": ["ESNext", "DOM"], - "moduleResolution": "Node", - "sourceMap": false, - "resolveJsonModule": true, - "esModuleInterop": true, - "types": ["vite/client", "@webgpu/types"], - // for build - // "noEmit": true, - "declaration": true, - "declarationDir": "dist", - "outDir": "dist", - "skipLibCheck": true, - "noImplicitAny": false, - "noUnusedLocals": false, - "noUnusedParameters":false, - "noImplicitReturns": false, - "strictPropertyInitialization": false, - "strictNullChecks": false, - "strict": false, - "paths": { - "@orillusion/core": ["../../src"], - "@orillusion/*": ["../*"] - } - } -} \ No newline at end of file diff --git a/packages/effect/vite.config.js b/packages/effect/vite.config.js deleted file mode 100644 index 1ad90b75..00000000 --- a/packages/effect/vite.config.js +++ /dev/null @@ -1,26 +0,0 @@ -import { defineConfig } from 'vite' -const path = require('path') -export default defineConfig({ - resolve: { - alias: { - '@orillusion/core': path.resolve(__dirname, '../../src'), - '@orillusion': path.resolve(__dirname, '../') - } - }, - build: { - target: 'esnext', - lib: { - entry: path.resolve('index.ts'), - name: 'Effect', - fileName: (format) => `effect.${format}.js` - }, - rollupOptions: { - external: ['@orillusion/core'], - output: { - globals: { - '@orillusion/core': 'Orillusion' - } - } - } - } -}) \ No newline at end of file diff --git a/packages/geometry/README.md b/packages/geometry/README.md index e079292a..4f3f3f23 100644 --- a/packages/geometry/README.md +++ b/packages/geometry/README.md @@ -7,7 +7,7 @@ npm install @orillusion/geometry --save ``` ```ts import { Scene3D } from "@orillusion/core" -import { TextGeometry } from "@orillusion/geometry" +import { TextGeometry, ExtrudeGeometry, TerrainGeometry } from "@orillusion/geometry" ``` Or access Global build from CDN diff --git a/packages/effect/grass/geometry/GrassGeometry.ts b/packages/geometry/grass/GrassGeometry.ts similarity index 95% rename from packages/effect/grass/geometry/GrassGeometry.ts rename to packages/geometry/grass/GrassGeometry.ts index 0289b3b5..4ec4dbfa 100644 --- a/packages/effect/grass/geometry/GrassGeometry.ts +++ b/packages/geometry/grass/GrassGeometry.ts @@ -1,15 +1,11 @@ -import { BoundingBox, GeometryBase, Vector3, VertexAttributeName } from "@orillusion/core"; -import { GrassNode } from "../GrassNode"; - - - +import { BoundingBox, GeometryBase, Transform, Vector3, VertexAttributeName } from "@orillusion/core"; export class GrassGeometry extends GeometryBase { public width: number; public height: number; public segmentW: number; public segmentH: number; - public nodes: GrassNode[]; + public nodes: Transform[]; constructor(width: number, height: number, segmentW: number = 1, segmentH: number = 1, count: number) { super(); @@ -43,7 +39,7 @@ export class GrassGeometry extends GeometryBase { let pi = 3.1415926 * 0.5; for (let gi = 0; gi < count; gi++) { - let node = new GrassNode(); + let node = new Transform(); this.nodes.push(node); let dir = new Vector3(1 * Math.random() - 0.5, 0.0, 1 * Math.random() - 0.5); diff --git a/packages/effect/grass/component/GrassComponent.ts b/packages/geometry/grass/component/GrassComponent.ts similarity index 83% rename from packages/effect/grass/component/GrassComponent.ts rename to packages/geometry/grass/component/GrassComponent.ts index db1e08c4..cbbd4861 100644 --- a/packages/effect/grass/component/GrassComponent.ts +++ b/packages/geometry/grass/component/GrassComponent.ts @@ -1,7 +1,6 @@ -import { BoundingBox, Color, ComponentBase, GPUPrimitiveTopology, LightingFunction_frag, MeshRenderer, Texture, UnLitMaterial, Vector3, VertexAttributeName } from "@orillusion/core"; +import { BoundingBox, Color, ComponentBase, GPUPrimitiveTopology, LightingFunction_frag, MeshRenderer, Texture, Transform, UnLitMaterial, Vector3, VertexAttributeName } from "@orillusion/core"; import { GrassMaterial } from "../material/GrassMaterial"; -import { GrassGeometry } from "../geometry/GrassGeometry"; -import { GrassNode } from "../GrassNode"; +import { GrassGeometry } from "../GrassGeometry"; export class GrassComponent extends MeshRenderer { @@ -40,7 +39,7 @@ export class GrassComponent extends MeshRenderer { this.grassMaterial.baseMap = grassTexture; } - public get nodes(): GrassNode[] { + public get nodes(): Transform[] { return this.grassGeometry.nodes; } } \ No newline at end of file diff --git a/packages/effect/grass/material/GrassMaterial.ts b/packages/geometry/grass/material/GrassMaterial.ts similarity index 100% rename from packages/effect/grass/material/GrassMaterial.ts rename to packages/geometry/grass/material/GrassMaterial.ts diff --git a/packages/effect/grass/shader/GrassBaseShader.ts b/packages/geometry/grass/shader/GrassBaseShader.ts similarity index 100% rename from packages/effect/grass/shader/GrassBaseShader.ts rename to packages/geometry/grass/shader/GrassBaseShader.ts diff --git a/packages/effect/grass/shader/GrassCastShadowShader.ts b/packages/geometry/grass/shader/GrassCastShadowShader.ts similarity index 100% rename from packages/effect/grass/shader/GrassCastShadowShader.ts rename to packages/geometry/grass/shader/GrassCastShadowShader.ts diff --git a/packages/effect/grass/shader/GrassShader.ts b/packages/geometry/grass/shader/GrassShader.ts similarity index 100% rename from packages/effect/grass/shader/GrassShader.ts rename to packages/geometry/grass/shader/GrassShader.ts diff --git a/packages/effect/grass/shader/GrassVertexAttributeShader.ts b/packages/geometry/grass/shader/GrassVertexAttributeShader.ts similarity index 100% rename from packages/effect/grass/shader/GrassVertexAttributeShader.ts rename to packages/geometry/grass/shader/GrassVertexAttributeShader.ts diff --git a/packages/geometry/index.ts b/packages/geometry/index.ts index eda175ee..eef3f1de 100644 --- a/packages/geometry/index.ts +++ b/packages/geometry/index.ts @@ -7,4 +7,8 @@ export * from "./ExtrudeGeometry/Path2D" export * from "./ExtrudeGeometry/Shape2D" export * from "./ExtrudeGeometry/ShapeUtils" export * from "./parser/FontParser" -export * from "./TextGeometry" \ No newline at end of file +export * from "./text/TextGeometry" +export * from "./terrain/TerrainGeometry" +export * from "./grass/GrassGeometry" +export * from "./grass/component/GrassComponent"; +export * from "./grass/material/GrassMaterial"; \ No newline at end of file diff --git a/packages/geometry/package.json b/packages/geometry/package.json index 49d0d30a..cf323957 100644 --- a/packages/geometry/package.json +++ b/packages/geometry/package.json @@ -1,6 +1,6 @@ { "name": "@orillusion/geometry", - "version": "0.2.1", + "version": "0.2.2", "author": "Orillusion", "description": "Orillusion geometry Plugin", "main": "./dist/geometry.umd.js", diff --git a/packages/effect/terrain/geometry/TerrainGeometry.ts b/packages/geometry/terrain/TerrainGeometry.ts similarity index 96% rename from packages/effect/terrain/geometry/TerrainGeometry.ts rename to packages/geometry/terrain/TerrainGeometry.ts index 4cfd3b7e..d602c051 100644 --- a/packages/effect/terrain/geometry/TerrainGeometry.ts +++ b/packages/geometry/terrain/TerrainGeometry.ts @@ -1,4 +1,4 @@ -import { BitmapTexture2D, Plane, PlaneGeometry, Texture, Vector3, VertexAttributeName, lerp } from "@orillusion/core" +import { BitmapTexture2D, PlaneGeometry, Vector3, VertexAttributeName, lerp } from "@orillusion/core" export class TerrainGeometry extends PlaneGeometry { diff --git a/packages/geometry/TextGeometry.ts b/packages/geometry/text/TextGeometry.ts similarity index 89% rename from packages/geometry/TextGeometry.ts rename to packages/geometry/text/TextGeometry.ts index 834c2339..a1372b25 100644 --- a/packages/geometry/TextGeometry.ts +++ b/packages/geometry/text/TextGeometry.ts @@ -1,7 +1,7 @@ -import { Shape2D } from "./ExtrudeGeometry/Shape2D"; -import { ExtrudeGeometry, ExtrudeGeometryArgs } from "./ExtrudeGeometry/ExtrudeGeometry"; -import { ShapeUtils } from "./ExtrudeGeometry/ShapeUtils"; -import { Font } from "./lib/opentype"; +import { Shape2D } from "../ExtrudeGeometry/Shape2D"; +import { ExtrudeGeometry, ExtrudeGeometryArgs } from "../ExtrudeGeometry/ExtrudeGeometry"; +import { ShapeUtils } from "../ExtrudeGeometry/ShapeUtils"; +import { Font } from "../lib/opentype"; export type TextGeometryArgs = ExtrudeGeometryArgs & { font: Font; diff --git a/samples/ext/_Sample_Boxes.ts b/samples/ext/_Sample_Boxes.ts deleted file mode 100644 index 2336ff6e..00000000 --- a/samples/ext/_Sample_Boxes.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { GUIHelp } from "@orillusion/debug/GUIHelp"; -import { Engine3D, View3D, Scene3D, CameraUtil, AtmosphericComponent, webGPUContext, HoverCameraController, Object3D, DirectLight, KelvinUtil, PlaneGeometry, VertexAttributeName, LitMaterial, MeshRenderer, Vector4, Vector3, Matrix3, PostProcessingComponent, TAAPost, BitmapTexture2D, GlobalFog, Color, BoxGeometry, UnLitMaterial, PointLight, GTAOPost, BloomPost } from "@orillusion/core"; -import { GUIUtil } from "@samples/utils/GUIUtil"; -import { GrassComponent, TerrainGeometry } from "@orillusion/effect"; - -// An sample of custom vertex attribute of geometry -class Sample_Boxes { - view: View3D; - post: PostProcessingComponent; - async run() { - Engine3D.setting.shadow.enable = true; - Engine3D.setting.shadow.updateFrameRate = 1; - Engine3D.setting.shadow.shadowBound = 500; - Engine3D.setting.shadow.autoUpdate = true; - Engine3D.setting.shadow.shadowSize = 1024; - // Engine3D.setting.render.zPrePass = true; - - GUIHelp.init(); - - await Engine3D.init(); - this.view = new View3D(); - this.view.scene = new Scene3D(); - this.view.scene.addComponent(AtmosphericComponent); - - this.view.camera = CameraUtil.createCamera3DObject(this.view.scene); - this.view.camera.enableCSM = true; - this.view.camera.perspective(60, webGPUContext.aspect, 1, 50000.0); - this.view.camera.object3D.z = -15; - this.view.camera.object3D.addComponent(HoverCameraController).setCamera(35, -20, 1000); - - Engine3D.startRenderView(this.view); - - this.post = this.view.scene.addComponent(PostProcessingComponent); - this.post.addPost(GTAOPost); - this.post.addPost(BloomPost); - let fog = this.post.addPost(GlobalFog); - fog.start = 91.0862; - fog.end = 487.5528; - fog.fogHeightScale = 0.0141; - fog.density = 0.2343; - fog.ins = 0.1041; - fog.skyFactor = 0.5316; - fog.overrideSkyFactor = 0.025; - - fog.fogColor = new Color(136 / 255, 215 / 255, 236 / 255, 1); - fog.fogHeightScale = 0.1; - fog.falloff = 2.5; - fog.scatteringExponent = 7.196; - fog.dirHeightLine = 6.5; - - GUIUtil.renderGlobalFog(fog); - - this.createScene(this.view.scene); - } - - private async createScene(scene: Scene3D) { - { - let sunObj = new Object3D(); - let sunLight = sunObj.addComponent(DirectLight); - sunLight.lightColor = KelvinUtil.color_temperature_to_rgb(6553); - sunLight.castShadow = true; - sunLight.intensity = 3; - sunObj.transform.rotationX = 50; - sunObj.transform.rotationY = 50; - GUIUtil.renderDirLight(sunLight); - scene.addChild(sunObj); - } - - { - let geometry = new BoxGeometry(5, 200, 5); - let litMaterial = new LitMaterial(); - // let litMaterial = new UnLitMaterial(); - let w = 30; - let h = 30; - for (let i = 0; i < w; i++) { - for (let j = 0; j < h; j++) { - let obj = new Object3D(); - let mr = obj.addComponent(MeshRenderer); - mr.material = litMaterial; - mr.geometry = geometry; - obj.x = i * 10 - w * 0.5 * 10; - obj.y = Math.random() * 100; - obj.z = j * 10 - h * 0.5 * 10; - scene.addChild(obj); - } - } - - let obj = new Object3D(); - let mr = obj.addComponent(MeshRenderer); - mr.material = litMaterial; - mr.geometry = geometry; - obj.localScale = new Vector3(1000, 1, 1000); - scene.addChild(obj); - } - - { - // for (let j = 0; j < 100; j++) { - // const lightObj = new Object3D();; - // let pointLight = lightObj.addComponent(PointLight); - // pointLight.castShadow = false; - // lightObj.transform.x = Math.random() * 100 * 10 - 100 * 10 * 0.5; - // lightObj.transform.y = 15; - // lightObj.transform.z = Math.random() * 100 * 10 - 100 * 10 * 0.5; - // pointLight.range = 100; - // pointLight.intensity = 60; - // scene.addChild(lightObj); - // } - } - - - // let globalFog = this.post.getPost(GlobalFog); - // GUIUtil.renderGlobalFog(globalFog); - } - -} - -new Sample_Boxes().run(); \ No newline at end of file diff --git a/samples/ext/Sample_Grass.ts b/samples/geometry/Sample_GrassGeometry.ts similarity index 98% rename from samples/ext/Sample_Grass.ts rename to samples/geometry/Sample_GrassGeometry.ts index 3e62d6b4..3d82a912 100644 --- a/samples/ext/Sample_Grass.ts +++ b/samples/geometry/Sample_GrassGeometry.ts @@ -1,7 +1,7 @@ import { GUIHelp } from "@orillusion/debug/GUIHelp"; import { Engine3D, View3D, Scene3D, CameraUtil, AtmosphericComponent, webGPUContext, HoverCameraController, Object3D, DirectLight, KelvinUtil, PlaneGeometry, VertexAttributeName, LitMaterial, MeshRenderer, Vector4, Vector3, Matrix3, PostProcessingComponent, TAAPost, BitmapTexture2D, GlobalFog, Color, FXAAPost } from "@orillusion/core"; import { GUIUtil } from "@samples/utils/GUIUtil"; -import { GrassComponent, TerrainGeometry } from "@orillusion/effect"; +import { GrassComponent, TerrainGeometry } from "@orillusion/geometry"; import { Stats } from "@orillusion/stats"; // An sample of custom vertex attribute of geometry diff --git a/samples/ext/Sample_Terrain.ts b/samples/geometry/Sample_TerrainGeometry.ts similarity index 98% rename from samples/ext/Sample_Terrain.ts rename to samples/geometry/Sample_TerrainGeometry.ts index 031266ed..9cc33726 100644 --- a/samples/ext/Sample_Terrain.ts +++ b/samples/geometry/Sample_TerrainGeometry.ts @@ -1,7 +1,7 @@ import { GUIHelp } from "@orillusion/debug/GUIHelp"; import { Engine3D, View3D, Scene3D, CameraUtil, AtmosphericComponent, webGPUContext, HoverCameraController, Object3D, DirectLight, KelvinUtil, PlaneGeometry, VertexAttributeName, LitMaterial, MeshRenderer, Vector4, Vector3, Matrix3, PostProcessingComponent, TAAPost, BitmapTexture2D, GlobalFog, Color, FXAAPost } from "@orillusion/core"; import { GUIUtil } from "@samples/utils/GUIUtil"; -import { GrassComponent, TerrainGeometry } from "@orillusion/effect"; +import { TerrainGeometry } from "@orillusion/geometry"; // An sample of custom vertex attribute of geometry class Sample_Terrain {