Skip to content

Commit

Permalink
chore(model): clean up blend naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Jan 5, 2024
1 parent 8a9bdc6 commit 7141355
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
18 changes: 9 additions & 9 deletions src/lib/blend.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as THREE from 'three';

enum THREE_BLEND_MODE {
enum THREE_BLEND {
BLEND_OPAQUE = 0,
BLEND_ALPHA_KEY,
BLEND_ALPHA,
Expand All @@ -11,49 +11,49 @@ enum THREE_BLEND_MODE {
}

const THREE_BLEND_STATE = {
[THREE_BLEND_MODE.BLEND_OPAQUE]: {
[THREE_BLEND.BLEND_OPAQUE]: {
blending: THREE.NoBlending,
blendSrc: THREE.OneFactor,
blendSrcAlpha: THREE.OneFactor,
blendDst: THREE.ZeroFactor,
blendDstAlpha: THREE.ZeroFactor,
},
[THREE_BLEND_MODE.BLEND_ALPHA_KEY]: {
[THREE_BLEND.BLEND_ALPHA_KEY]: {
blending: THREE.NoBlending,
blendSrc: THREE.OneFactor,
blendSrcAlpha: THREE.OneFactor,
blendDst: THREE.ZeroFactor,
blendDstAlpha: THREE.ZeroFactor,
},
[THREE_BLEND_MODE.BLEND_ALPHA]: {
[THREE_BLEND.BLEND_ALPHA]: {
blending: THREE.CustomBlending,
blendSrc: THREE.SrcAlphaFactor,
blendSrcAlpha: THREE.OneFactor,
blendDst: THREE.OneMinusSrcAlphaFactor,
blendDstAlpha: THREE.OneMinusSrcAlphaFactor,
},
[THREE_BLEND_MODE.BLEND_NO_ALPHA_ADD]: {
[THREE_BLEND.BLEND_NO_ALPHA_ADD]: {
blending: THREE.CustomBlending,
blendSrc: THREE.OneFactor,
blendSrcAlpha: THREE.ZeroFactor,
blendDst: THREE.OneFactor,
blendDstAlpha: THREE.OneFactor,
},
[THREE_BLEND_MODE.BLEND_ADD]: {
[THREE_BLEND.BLEND_ADD]: {
blending: THREE.CustomBlending,
blendSrc: THREE.SrcAlphaFactor,
blendSrcAlpha: THREE.ZeroFactor,
blendDst: THREE.OneFactor,
blendDstAlpha: THREE.OneFactor,
},
[THREE_BLEND_MODE.BLEND_MOD]: {
[THREE_BLEND.BLEND_MOD]: {
blending: THREE.CustomBlending,
blendSrc: THREE.DstColorFactor,
blendSrcAlpha: THREE.DstAlphaFactor,
blendDst: THREE.ZeroFactor,
blendDstAlpha: THREE.ZeroFactor,
},
[THREE_BLEND_MODE.BLEND_MOD2X]: {
[THREE_BLEND.BLEND_MOD2X]: {
blending: THREE.CustomBlending,
blendSrc: THREE.DstColorFactor,
blendSrcAlpha: THREE.DstAlphaFactor,
Expand All @@ -62,4 +62,4 @@ const THREE_BLEND_STATE = {
},
};

export { THREE_BLEND_MODE, THREE_BLEND_STATE };
export { THREE_BLEND, THREE_BLEND_STATE };
6 changes: 3 additions & 3 deletions src/lib/model/ModelMaterial.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as THREE from 'three';
import { M2_MATERIAL_BLEND } from '@wowserhq/format';
import { M2_MATERIAL_TO_THREE_BLEND_MODE, M2_MATERIAL_PASS } from './const.js';
import { M2_MATERIAL_BLEND_TO_THREE_BLEND, M2_MATERIAL_PASS } from './const.js';
import { THREE_BLEND_STATE } from '../blend.js';

const DEFAULT_BLEND: M2_MATERIAL_BLEND = M2_MATERIAL_BLEND.BLEND_OPAQUE;
const DEFAULT_PASS: M2_MATERIAL_PASS = M2_MATERIAL_PASS.PASS_0;
const DEFAULT_SIDE: THREE.Side = THREE.FrontSide;
const DEFAULT_ALPHA: number = 1.0;

const getThreeBlendState = (blendMode: M2_MATERIAL_BLEND, pass: M2_MATERIAL_PASS) =>
THREE_BLEND_STATE[M2_MATERIAL_TO_THREE_BLEND_MODE[pass][blendMode]];
const getThreeBlendState = (blend: M2_MATERIAL_BLEND, pass: M2_MATERIAL_PASS) =>
THREE_BLEND_STATE[M2_MATERIAL_BLEND_TO_THREE_BLEND[pass][blend]];

class ModelMaterial extends THREE.RawShaderMaterial {
#blend: M2_MATERIAL_BLEND;
Expand Down
34 changes: 17 additions & 17 deletions src/lib/model/const.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { THREE_BLEND_MODE } from '../blend.js';
import { THREE_BLEND } from '../blend.js';

enum M2_MATERIAL_PASS {
PASS_0 = 0,
PASS_1,
PASS_COUNT,
}

const M2_MATERIAL_TO_THREE_BLEND_MODE = {
const M2_MATERIAL_BLEND_TO_THREE_BLEND = {
[M2_MATERIAL_PASS.PASS_0]: [
THREE_BLEND_MODE.BLEND_OPAQUE,
THREE_BLEND_MODE.BLEND_ALPHA_KEY,
THREE_BLEND_MODE.BLEND_ALPHA,
THREE_BLEND_MODE.BLEND_NO_ALPHA_ADD,
THREE_BLEND_MODE.BLEND_ADD,
THREE_BLEND_MODE.BLEND_MOD,
THREE_BLEND_MODE.BLEND_MOD2X,
THREE_BLEND.BLEND_OPAQUE,
THREE_BLEND.BLEND_ALPHA_KEY,
THREE_BLEND.BLEND_ALPHA,
THREE_BLEND.BLEND_NO_ALPHA_ADD,
THREE_BLEND.BLEND_ADD,
THREE_BLEND.BLEND_MOD,
THREE_BLEND.BLEND_MOD2X,
],
[M2_MATERIAL_PASS.PASS_1]: [
THREE_BLEND_MODE.BLEND_ALPHA,
THREE_BLEND_MODE.BLEND_ALPHA,
THREE_BLEND_MODE.BLEND_ALPHA,
THREE_BLEND_MODE.BLEND_NO_ALPHA_ADD,
THREE_BLEND_MODE.BLEND_ADD,
THREE_BLEND_MODE.BLEND_MOD,
THREE_BLEND_MODE.BLEND_MOD2X,
THREE_BLEND.BLEND_ALPHA,
THREE_BLEND.BLEND_ALPHA,
THREE_BLEND.BLEND_ALPHA,
THREE_BLEND.BLEND_NO_ALPHA_ADD,
THREE_BLEND.BLEND_ADD,
THREE_BLEND.BLEND_MOD,
THREE_BLEND.BLEND_MOD2X,
],
};

export { M2_MATERIAL_PASS, M2_MATERIAL_TO_THREE_BLEND_MODE };
export { M2_MATERIAL_PASS, M2_MATERIAL_BLEND_TO_THREE_BLEND };

0 comments on commit 7141355

Please sign in to comment.