Skip to content

Commit

Permalink
change file organization and build way
Browse files Browse the repository at this point in the history
  • Loading branch information
hongfaqiu committed May 14, 2021
1 parent 56bdc63 commit a8a69eb
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 42 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/node_modules
/example
/data
/packages
package-lock.json
webpack.config.js
38 changes: 31 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "cesium-particle",
"version": "0.4.0-alpha.0",
"version": "0.4.0",
"description": "cesium particle system module",
"main": "src/index.js",
"scripts": {
"dev": "webpack-dev-server",
"build": "webpack --config webpack.prod.config.js",
"build-glsl": "webpack --config webpack.glsl.config.js",
"build-example": "webpack --config webpack.config.js"
},
"repository": {
Expand All @@ -26,12 +26,11 @@
"devDependencies": {
"@babel/core": "^7.13.16",
"babel-loader": "^8.2.2",
"cesium": "^1.65.0",
"cesium": "^1.81.0",
"copy-webpack-plugin": "^8.1.1",
"css-loader": "^5.2.4",
"dat.gui": "^0.7.7",
"html-webpack-plugin": "^5.3.1",
"netcdfjs": "^1.0.0",
"style-loader": "^2.0.0",
"url-loader": "^4.1.1",
"webpack": "^5.33.2",
Expand All @@ -40,5 +39,7 @@
"webpack-dev-server": "^3.11.2",
"webpack-glsl-loader": "^1.0.1"
},
"dependencies": {}
"dependencies": {
"netcdfjs": "^1.0.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions packages/shader/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const CalculateSpeedShader = require('./glsl/calculateSpeed.frag');
const UpdatePositionShader = require('./glsl/updatePosition.frag');
const PostProcessingPositionShader = require('./glsl/postProcessingPosition.frag');
const segmentDrawVert = require('./glsl/segmentDraw.vert');
const fullscreenVert = require('./glsl/fullscreen.vert');
const screenDrawFrag = require('./glsl/screenDraw.frag');
const segmentDrawFrag = require('./glsl/segmentDraw.frag');
const trailDrawFrag = require('./glsl/trailDraw.frag');

export {
CalculateSpeedShader,
UpdatePositionShader,
PostProcessingPositionShader,
segmentDrawVert,
fullscreenVert,
screenDrawFrag,
segmentDrawFrag,
trailDrawFrag
};
31 changes: 31 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,34 @@ defaultColorTable = [[1.0, 1.0, 1.0]]; // 默认的颜色配置
npm install / cnpm install
npm run dev
```

## Q&A

### 更改glsl文件之后未生效

在开发环境中调试glsl文件,需要在.src/modules/particlescomputing.js 和 particlesRendering.js 中修改glsl文件入口:

```js
import { CalculateSpeedShader, UpdatePositionShader, PostProcessingPositionShader } from '../../packages/shader';
```

在webpack.config.js中添加glsl-loader

```js
module.exports = {
module: {
rules: [
{
test: /\.(frag|vert)$/,
loader: 'webpack-glsl-loader'
}
]
}
}
```

或者使用打包命令,打包glsl文件为js:

```js
npm run buld-glsl
```
5 changes: 1 addition & 4 deletions src/modules/particlesComputing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { CustomPrimitive } from './customPrimitive';
import { DataProcess } from './dataProcess';
import { Util } from './util';
import * as Cesium from 'cesium/Cesium';

const CalculateSpeedShader = require('../glsl/calculateSpeed.frag');
const UpdatePositionShader = require('../glsl/updatePosition.frag');
const PostProcessingPositionShader = require('../glsl/postProcessingPosition.frag');
import { CalculateSpeedShader, UpdatePositionShader, PostProcessingPositionShader } from '../shader/shader.min.js';

class ParticlesComputing {
constructor(context, data, userInput, viewerParameters) {
Expand Down
14 changes: 3 additions & 11 deletions src/modules/particlesRendering.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import {
CustomPrimitive
} from './customPrimitive'
import {
Util
} from './util'
import { CustomPrimitive } from './customPrimitive'
import { Util } from './util'
import * as Cesium from 'cesium/Cesium'

const segmentDrawVert = require('../glsl/segmentDraw.vert');
const fullscreenVert = require('../glsl/fullscreen.vert');
const screenDrawFrag = require('../glsl/screenDraw.frag');
const segmentDrawFrag = require('../glsl/segmentDraw.frag');
const trailDrawFrag = require('../glsl/trailDraw.frag');
import { segmentDrawVert, fullscreenVert, screenDrawFrag, segmentDrawFrag, trailDrawFrag } from '../shader/shader.min.js';

class ParticlesRendering {
constructor(context, data, userInput, viewerParameters, particlesComputing, colour) {
Expand Down
1 change: 1 addition & 0 deletions src/shader/shader.min.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ module.exports = {
limit: 8192,
name: '[name].[ext]?[hash]'
}
},
{
test: /\.(frag|vert)$/,
loader: 'webpack-glsl-loader'
}
]
},
Expand All @@ -76,7 +72,6 @@ module.exports = {
}),
new webpack.HotModuleReplacementPlugin(), // 热更新插件
],
devtool: 'inline-source-map', // map文件追踪错误提示
devServer: {
contentBase: './dist', // 开发环境的服务目录
historyApiFallback: true,
Expand Down
27 changes: 27 additions & 0 deletions webpack.glsl.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const path = require('path');

module.exports = {
mode: 'production',
entry: path.resolve(__dirname, 'packages/shader/index.js'),
output: {
path: path.join(__dirname, 'src/shader/'),
filename: 'shader.min.js',
libraryTarget: 'commonjs' //模块输出方式
},
resolve: {
extensions: ['.js'],
},
module: {
rules: [
{
test: /(\.js)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.(frag|vert)$/,
loader: 'webpack-glsl-loader'
}
]
}
};
17 changes: 7 additions & 10 deletions webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const prdWebpackConfig= {
mode: 'production',
entry: path.resolve(__dirname, 'src/index.js'),
output: {
path: path.join(__dirname, 'lib'),
filename: "cesium-particle.js",
libraryTarget: 'commonjs2' //模块输出方式
path: path.join(__dirname, 'build'),
filename: 'cesium-particle.min.js',
libraryTarget: 'umd', //模块输出方式
umdNamedDefine: true
},
resolve: {
extensions: ['.js', '.json'],
Expand All @@ -21,9 +22,9 @@ const prdWebpackConfig= {
fs: false
}
},
externals: {
cesium: 'cesium' //打包时候排除cesium
},
plugins: [
new BundleAnalyzerPlugin()
],
module: {
rules: [
{
Expand All @@ -39,8 +40,4 @@ const prdWebpackConfig= {
}
};

if (NODE_ENV !== 'publish') {
prdWebpackConfig.plugins.push(new BundleAnalyzerPlugin())
}

module.exports = prdWebpackConfig;

0 comments on commit a8a69eb

Please sign in to comment.