Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update libraries2 #104

Merged
merged 3 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Some settings will be ignored or generates inconsistent lighting.
|~4.1.0|^2.0.0|
|~4.2.0|^3.0.0|
|~5.0.0-rc.0|^4.0.0|
|^5.19.0|^5.0.0|

## Features

Expand Down
49 changes: 26 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,43 @@
"typings": "dist/index.d.ts",
"main": "dist/index.module.js",
"devDependencies": {
"@babylonjs/core": "~5.0.0-rc.0",
"@babylonjs/inspector": "~5.0.0-rc.0",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.2",
"@semantic-release/npm": "^9.0.1",
"@semantic-release/release-notes-generator": "^10.0.3",
"@types/node": "^14.14.34",
"@babylonjs/core": "^5.19.0",
"@babylonjs/gui": "^5.19.0",
"@babylonjs/gui-editor": "^5.19.0",
"@babylonjs/inspector": "^5.19.0",
"@babylonjs/loaders": "^5.19.0",
"@babylonjs/materials": "^5.19.0",
"@babylonjs/serializers": "^5.19.0",
"@types/react": ">=16.7.3",
"@types/react-dom": ">=16.0.9",
"babylonjs-gltf2interface": "^5.0.0",
"@types/node": "^14.18.22",
"cz-conventional-changelog": "3.3.0",
"gh-pages": "^3.2.0",
"http-server": "^14.1.0",
"jest": "^27.0.4",
"jest-dev-server": "^6.0.3",
"jest-puppeteer": "^6.1.0",
"puppeteer": "^13.4.1",
"raw-loader": "^4.0.2",
"semantic-release": "^19.0.2",
"ts-loader": "^8.2.0",
"gh-pages": "^4.0.0",
"http-server": "^14.1.1",
"jest": "^28.1.3",
"jest-dev-server": "^6.1.1",
"jest-puppeteer": "^6.1.1",
"puppeteer": "^15.4.1",
"semantic-release": "^19.0.3",
"ts-loader": "^9.2.6",
"tslib": "^2.4.0",
"tslint": "^6.1.3",
"typescript": "^4.3.2",
"webpack": "^4.41.5",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4",
"typescript": "^4.4.4",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.9.3",
"webpack-merge": "^5.8.0"
},
"peerDependencies": {
"@babylonjs/core": "~5.0.0-rc.0"
"@babylonjs/core": "^5.19.0"
},
"scripts": {
"build": "webpack",
"build:gh-pages": "webpack --config webpack.test.config.js",
"build:test": "yarn build:gh-pages",
"lint": "tslint -p .",
"debug": "webpack-dev-server --config webpack.test.config.js",
"debug": "webpack serve --config webpack.test.config.js",
"release": "semantic-release",
"release:gh-pages": "gh-pages -d test -u \"Masaru Yamagishi <m-yamagishi@virtualcast.jp>\" -m \"ci(gh-pages): update gh-pages [skip ci]\"",
"test": "jest test/jest.test.js"
Expand Down
2 changes: 1 addition & 1 deletion src/mtoon-material-defines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class MToonMaterialDefines extends MaterialDefines implements IImageProce
public MAINUV6 = false;
public DIFFUSE = false;
public DIFFUSEDIRECTUV = 0;
public BAKED_VERTYEX_ANIMATION_TEXTURE = false;
public BAKED_VERTEX_ANIMATION_TEXTURE = false;
// public AMBIENT = false;
// public AMBIENTDIRECTUV = 0;
// public OPACITY = false;
Expand Down
61 changes: 36 additions & 25 deletions src/mtoon-material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ import { MToonMaterialDefines } from './mtoon-material-defines';

const onCreatedEffectParameters = { effect: null as unknown as Effect, subMesh: null as unknown as Nullable<SubMesh> };

// get shader string
const UboDeclaration = require('./shaders/ubo-declaration.vert').default;
const VertexDeclaration = require('./shaders/vertex-declaration.vert').default;
const FragmentDeclaration = require('./shaders/fragment-declaration.frag').default;
const FragmentFunctions = require('./shaders/mtoon-fragment-functions.frag').default;
const BumpFragment = require('./shaders/bump-fragment.frag').default;
const LightFragment = require('./shaders/light-fragment.frag').default;
const VertexShader = require('./shaders/mtoon.vert').default;
const FragmentShader = require('./shaders/mtoon.frag').default;
import UboDeclaration from './shaders/ubo-declaration.vert';
import VertexDeclaration from './shaders/vertex-declaration.vert';
import FragmentDeclaration from './shaders/fragment-declaration.frag';
import FragmentFunctions from './shaders/mtoon-fragment-functions.frag';
import BumpFragment from './shaders/bump-fragment.frag';
import LightFragment from './shaders/light-fragment.frag';
import VertexShader from './shaders/mtoon.vert';
import FragmentShader from './shaders/mtoon.frag';

/**
* Debug shading mode
Expand Down Expand Up @@ -307,6 +306,10 @@ export class MToonMaterial extends PushMaterial {
* No support for vertex alpha
*/
public readonly useVertexAlpha: boolean = false;
/**
* No support for baked vertex animation
*/
public readonly useBakedVertexAnimation: boolean = false;

/**
* Defines the alpha limits in alpha test mode.
Expand Down Expand Up @@ -401,8 +404,7 @@ export class MToonMaterial extends PushMaterial {
// Pick the scene configuration if needed
if (!configuration) {
this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;
}
else {
} else {
this._imageProcessingConfiguration = configuration;
}

Expand Down Expand Up @@ -966,7 +968,7 @@ export class MToonMaterial extends PushMaterial {
}

if (subMesh.effect && this.isFrozen) {
if (subMesh.effect._wasPreviouslyReady) {
if (subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {
return true;
}
}
Expand Down Expand Up @@ -1048,6 +1050,8 @@ export class MToonMaterial extends PushMaterial {
defines.OBJECTSPACE_NORMALMAP = this.useObjectSpaceNormalMap;
} else {
defines.BUMP = false;
defines.PARALLAX = false;
defines.PARALLAXOCCLUSION = false;
}

defines.TWOSIDEDLIGHTING = !this._backFaceCulling && this._twoSidedLighting;
Expand Down Expand Up @@ -1109,16 +1113,6 @@ export class MToonMaterial extends PushMaterial {
defines,
);

// Attribs
MaterialHelper.PrepareDefinesForAttributes(
mesh,
defines,
this.useVertexColor,
this.useBones,
this.useMorphTargets,
this.useVertexAlpha,
);

// Values that need to be evaluated on every frame
MaterialHelper.PrepareDefinesForFrameBoundValues(
scene,
Expand All @@ -1132,6 +1126,20 @@ export class MToonMaterial extends PushMaterial {
// External config
this._eventInfo.defines = defines;
this._eventInfo.mesh = mesh;
this._callbackPluginEventPrepareDefinesBeforeAttributes(this._eventInfo);

// Attribs
MaterialHelper.PrepareDefinesForAttributes(
mesh,
defines,
this.useVertexColor,
this.useBones,
this.useMorphTargets,
this.useVertexAlpha,
this.useBakedVertexAnimation,
);

// External config
this._callbackPluginEventPrepareDefines(this._eventInfo);

// Get correct effect
Expand All @@ -1147,11 +1155,11 @@ export class MToonMaterial extends PushMaterial {
}

if (defines.PARALLAX) {
fallbacks.addFallback(1, "PARALLAX");
fallbacks.addFallback(1, 'PARALLAX');
}

if (defines.PARALLAXOCCLUSION) {
fallbacks.addFallback(0, "PARALLAXOCCLUSION");
fallbacks.addFallback(0, 'PARALLAXOCCLUSION');
}

if (defines.FOG) {
Expand Down Expand Up @@ -1196,6 +1204,7 @@ export class MToonMaterial extends PushMaterial {
MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
MaterialHelper.PrepareAttributesForInstances(attribs, defines);
MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);
MaterialHelper.PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);

const shaderName = 'mtoon';

Expand Down Expand Up @@ -1250,9 +1259,11 @@ export class MToonMaterial extends PushMaterial {
this._eventInfo.fallbackRank = 0;
this._eventInfo.defines = defines;
this._eventInfo.uniforms = uniforms;
this._eventInfo.attributes = attribs;
this._eventInfo.samplers = samplers;
this._eventInfo.uniformBuffersNames = uniformBuffers;
this._eventInfo.customCode = undefined;
this._eventInfo.mesh = mesh;
this._callbackPluginEventGeneric(MaterialPluginEvent.PrepareEffect, this._eventInfo);

// PrePassConfiguration.AddUniforms(uniforms);
Expand Down Expand Up @@ -1324,6 +1335,7 @@ export class MToonMaterial extends PushMaterial {

defines._renderId = scene.getRenderId();
subMesh.effect._wasPreviouslyReady = true;
subMesh.effect._wasPreviouslyUsingInstances = useInstances;

return true;
}
Expand Down Expand Up @@ -1442,7 +1454,6 @@ export class MToonMaterial extends PushMaterial {
const ubo = this._uniformBuffer;
if (mustRebind) {
this.bindViewProjection(effect);

if (!ubo.useUbo || !this.isFrozen || !ubo.isSync) {
if (scene.texturesEnabled) {
this.bindTexture(this._diffuseTexture, ubo, effect, 'diffuse', 'vDiffuseInfos');
Expand Down
12 changes: 6 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"importHelpers": true,
"moduleResolution": "node",
"module": "esNext",
"target": "es5",
"target": "es2017",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
Expand All @@ -14,16 +14,16 @@
"strictNullChecks": true,
"strictFunctionTypes": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"strictPropertyInitialization": false, // @serialize decorator
"strict": true,
"lib": [
"es5",
"dom",
"es2015.promise",
"es2015.collection",
"es2015.iterable"
],
"outDir": "dist"
},
"include": [
"./src/**/*"
"./src/**/*",
"./index.d.ts",
]
}
26 changes: 12 additions & 14 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const baseConfig = {
rules: [
{
test: /\.(vert|frag)$/,
use: 'raw-loader',
type: 'asset/source',
},
{
test: /\.ts$/,
use: 'ts-loader',
loader: 'ts-loader',
},
],
},
Expand All @@ -29,10 +29,11 @@ module.exports = [
*/
merge(baseConfig, {
output: {
library: 'babylon-mtoon-material',
libraryTarget: 'umd',
library: {
name: 'babylon-mtoon-material',
type: 'umd',
},
filename: 'index.module.js',
path: resolve(__dirname, 'dist'),
},
externals: [
/^@babylonjs\/core.*$/,
Expand All @@ -43,18 +44,15 @@ module.exports = [
*/
merge(baseConfig, {
output: {
library: 'MToonMaterial',
libraryTarget: 'window',
libraryExport: 'MToonMaterial',
library: {
name: 'MToonMaterial',
type: 'window',
export: 'MToonMaterial',
},
filename: 'index.js',
path: resolve(__dirname, 'dist'),
},
externals: [
function (context, request, callback) {
// materialPluginEvent is not assigned at window.BABYLON
if (request.includes('@babylonjs/core/Materials/materialPluginEvent')) {
return callback();
}
({context, request}, callback) => {
if (/^@babylonjs\/core.*$/.test(request)) {
return callback(null, `window BABYLON`);
}
Expand Down
18 changes: 14 additions & 4 deletions webpack.test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ module.exports = {
devtool: 'source-map',
entry: resolve(__dirname, 'src', 'test', 'index'),
output: {
library: 'babylon-mtoon-material',
libraryTarget: 'umd',
library: {
name: 'babylon-mtoon-material',
type: 'umd',
},
filename: '[name].js',
path: resolve(__dirname, 'test'),
},
module: {
rules: [
{
test: /\.(vert|frag)$/,
use: 'raw-loader',
type: 'asset/source',
},
{
test: /\.ts$/,
use: 'ts-loader',
loader: 'ts-loader',
},
],
},
Expand All @@ -35,6 +37,14 @@ module.exports = {
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
name(_module, chunks, _cacheGroupKey) {
return `vendors~${chunks[0].name}`;
},
},
},
},
},
target: 'web',
Expand Down
Loading