Skip to content

Commit 4d70061

Browse files
authored
Merge pull request #10 from swgpu/car_sample
Car sample
2 parents 10d783f + 54683ed commit 4d70061

File tree

16 files changed

+211
-124
lines changed

16 files changed

+211
-124
lines changed

bin/WARME-Blender-Exporter.zip

114 Bytes
Binary file not shown.
368 Bytes
Binary file not shown.
1.16 KB
Binary file not shown.

src/lib/gfx3/gfx3_drawable.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import { Gfx3Transformable } from './gfx3_transformable';
55
import { Gfx3BoundingBox } from './gfx3_bounding_box';
66
import { Quaternion } from '../core/quaternion';
77

8+
enum MeshEffect {
9+
NONE = 0,
10+
PIXELATION = 2,
11+
COLOR_LIMITATION = 4,
12+
DITHER = 8,
13+
OUTLINE = 16,
14+
SHADOW_VOLUME = 32,
15+
CHANNEL1 = 64
16+
};
17+
818
/**
919
* A 3D drawable object.
1020
*/
@@ -21,7 +31,7 @@ class Gfx3Drawable extends Gfx3Transformable implements Poolable<Gfx3Drawable> {
2131
*/
2232
constructor(vertexStride: number) {
2333
super();
24-
this.id = [0, 0, 0, 0];
34+
this.id = [0, 0, 0, 1];
2535
this.vertexSubBuffer = gfx3Manager.createVertexBuffer(0);
2636
this.vertices = [];
2737
this.vertexCount = 0;
@@ -126,33 +136,34 @@ class Gfx3Drawable extends Gfx3Transformable implements Poolable<Gfx3Drawable> {
126136

127137
/**
128138
* Set an identifier based on three components.
129-
* Note: WARME use some specials ID's in its internal pipeline, check the table below:
130-
* ■ decals group: g = n
131-
* ■ lights group: b = n
132-
* ■ pixelation: a = 1
133-
* ■ color limitation: a = 2
134-
* ■ dither: a = 4
135-
* ■ outline: a = 8
136-
* ■ shadow volume: a = 16
137-
* ■ channel 1: a = 32 (channel 1 is a rendering texture used by post process unit for many different things, it is invisible by default)
139+
* Note: SWGPU use some specials ID's in its internal pipeline, check the table below:
140+
* ■ R: The red channel.
141+
* ■ G: The green channel.
142+
* ■ A: The alpha channel [0, 1]
143+
* ■ B: The blue channel for effects
144+
* ■ pixelation: 2
145+
* ■ color limitation: 4
146+
* ■ dither: 8
147+
* ■ outline: 16
148+
* ■ shadow volume: 32
149+
* ■ channel1: 64
138150
*
139-
* @param {number} r - The pur identifier you can use for custom stuff.
140-
* @param {number} g - The decals group.
141-
* @param {number} b - The lights group.
142-
* @param {number} a - The flags value for specials effects.
151+
* @param {number} r - The red channel.
152+
* @param {number} g - The green channel.
153+
* @param {MeshEffect|number} b - The blue channel for effects.
154+
* @param {number} a - The alpha channel.
143155
*/
144-
setId(r: number, g: number = 0, b: number = 0, a: number = 0): void {
156+
setId(r: number, g: number = 0, b: MeshEffect = 0, a: number = 1): void {
145157
this.id = [r, g, b, a];
146158
}
147159

148160
/**
149-
* Set a single identifier component.
161+
* Set the effects.
150162
*
151-
* @param {number} index - The component index.
152-
* @param {number} value - The identifier value.
163+
* @param {MeshEffecta|number} effects - The effects.
153164
*/
154-
setSingleId(index: number, value: number): void {
155-
this.id[index] = value;
165+
setEffects(effects: number): void {
166+
this.id[2] = effects;
156167
}
157168

158169
/**
@@ -218,4 +229,4 @@ class Gfx3Drawable extends Gfx3Transformable implements Poolable<Gfx3Drawable> {
218229
}
219230
}
220231

221-
export { Gfx3Drawable };
232+
export { Gfx3Drawable, MeshEffect };

src/lib/gfx3_mesh/gfx3_mesh_light.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Gfx3MeshLight extends Gfx3Transformable {
1818
linear: number;
1919
exp: number;
2020
radius: number;
21-
meshId: number;
21+
group: number;
2222
/* spot */
2323
cutoff: number;
2424
direction: vec3;
@@ -33,7 +33,7 @@ class Gfx3MeshLight extends Gfx3Transformable {
3333
this.linear = 0;
3434
this.exp = 0;
3535
this.radius = 10;
36-
this.meshId = 0;
36+
this.group = 0;
3737
this.cutoff = 12.5;
3838
this.direction = [0, -1, 0];
3939
}
@@ -60,7 +60,7 @@ class Gfx3MeshLight extends Gfx3Transformable {
6060
this.linear = json['Linear'];
6161
this.exp = json['Exp'];
6262
this.radius = json['Radius'];
63-
this.meshId = json['MeshID'];
63+
this.group = json['Group'];
6464
this.cutoff = json['Cutoff'];
6565
this.direction = json['Direction'];
6666
}
@@ -75,7 +75,7 @@ class Gfx3MeshLight extends Gfx3Transformable {
7575
this.diffuse,
7676
this.specular,
7777
this.intensity,
78-
this.meshId,
78+
this.group,
7979
this.constant,
8080
this.linear,
8181
this.exp
@@ -89,7 +89,7 @@ class Gfx3MeshLight extends Gfx3Transformable {
8989
this.diffuse,
9090
this.specular,
9191
this.intensity,
92-
this.meshId,
92+
this.group,
9393
this.constant,
9494
this.linear,
9595
this.exp
@@ -180,13 +180,13 @@ class Gfx3MeshLight extends Gfx3Transformable {
180180
}
181181

182182
/**
183-
* Set mesh id targeted.
184-
* Note: 0 affect all mesh
183+
* Set group light identifier.
184+
* Note: 0 is the default group and will affect all mesh
185185
*
186-
* @param {number} meshId - The mesh id.
186+
* @param {number} group - The group id.
187187
*/
188-
setMeshId(meshId: number): void {
189-
this.meshId = meshId;
188+
setGroup(group: number): void {
189+
this.group = group;
190190
}
191191

192192
/**
@@ -268,11 +268,10 @@ class Gfx3MeshLight extends Gfx3Transformable {
268268
}
269269

270270
/**
271-
* Returns the mesh id affected by the light.
272-
* Note: 0 affect all mesh
271+
* Returns the group id.
273272
*/
274-
getMeshId(): number {
275-
return this.meshId;
273+
getGroup(): number {
274+
return this.group;
276275
}
277276

278277
/**

src/lib/gfx3_mesh/gfx3_mesh_material.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface MATOptions {
2727
id?: number;
2828
normalIntensity?: number;
2929
lightning?: boolean;
30+
lightGroup?: number;
3031
ambient?: vec3;
3132
diffuse?: vec3;
3233
specular?: vec3;
@@ -37,6 +38,7 @@ interface MATOptions {
3738
textureScrollAngle?: number;
3839
textureScrollRate?: number;
3940
textureScale?: vec2,
41+
textureBlendMode?: 'mul' | 'add';
4042
secondaryTexture?: Gfx3Texture;
4143
secondaryTextureScrollAngle?: number;
4244
secondaryTextureScrollRate?: number;
@@ -71,7 +73,8 @@ interface MATOptions {
7173
sParams?: Array<{name: string, value: number }>;
7274
s0Texture?: Gfx3Texture;
7375
s1Texture?: Gfx3Texture;
74-
colorBlendMode?: 'mul' | 'add';
76+
decalGroup?: number;
77+
effects?: number;
7578
};
7679

7780
interface Animation {
@@ -150,7 +153,7 @@ class Gfx3Material {
150153
this.colors[22] = options.dissolveGlow ? options.dissolveGlow[2] : 1.0;
151154
this.colors[23] = 0.0;
152155

153-
this.params = this.grp2.setFloat(1, 'MAT_PARAMS', 43);
156+
this.params = this.grp2.setFloat(1, 'MAT_PARAMS', 46);
154157
this.params[0] = options.id ?? 0;
155158
this.params[1] = options.normalIntensity ?? 1.0;
156159
this.params[2] = options.lightning ? 1.0 : 0.0;
@@ -177,13 +180,16 @@ class Gfx3Material {
177180
this.params[23] = options.distanceAlphaBlend ?? 0.0;
178181
this.params[24] = options.s0Texture ? 1.0 : 0.0;
179182
this.params[25] = options.s1Texture ? 1.0 : 0.0;
180-
this.params[26] = options.colorBlendMode ? (options.colorBlendMode == 'mul' ? 1.0 : 2.0) : 1.0;
183+
this.params[26] = options.textureBlendMode ? (options.textureBlendMode == 'mul' ? 1.0 : 2.0) : 1.0;
184+
this.params[27] = options.lightGroup ?? 0;
185+
this.params[28] = options.decalGroup ?? 0;
186+
this.params[29] = options.effects ?? 0;
181187

182188
if (options.sParams) {
183189
for (const sParam of options.sParams) {
184190
const paramIndex = Object.values(MAT_PARAMS_VARS).findIndex(n => n == sParam.name);
185191
if (paramIndex != -1) {
186-
this.params[27 + paramIndex] = sParam.value ?? 0.0;
192+
this.params[30 + paramIndex] = sParam.value ?? 0.0;
187193
}
188194
}
189195
}
@@ -299,6 +305,7 @@ class Gfx3Material {
299305
id: json['Id'],
300306
normalIntensity: json['NormalIntensity'],
301307
lightning: json['Lightning'],
308+
lightGroup: json['LightGroup'],
302309
emissive: json['Emissive'],
303310
ambient: json['Ambient'],
304311
diffuse: json['Diffuse'],
@@ -309,6 +316,7 @@ class Gfx3Material {
309316
textureScrollAngle: json['TextureScrollAngle'],
310317
textureScrollRate: json['TextureScrollRate'],
311318
textureScale: json['TextureScale'],
319+
textureBlendMode: json['TextureBlendMode'],
312320
secondaryTexture: json['SecondaryTexture'] ? await gfx3TextureManager.loadTexture(textureDir + json['SecondaryTexture']) : undefined,
313321
secondaryTextureScrollAngle: json['SecondaryTextureScrollAngle'],
314322
secondaryTextureScrollRate: json['SecondaryTextureScrollRate'],
@@ -342,6 +350,8 @@ class Gfx3Material {
342350
toonLightDir: json['ToonLightDir'],
343351
facingAlphaBlend: json['FacingAlphaBlend'],
344352
distanceAlphaBlend: json['DistanceAlphaBlend'],
353+
decalGroup: json['DecalGroup'],
354+
effects: json['Effects'],
345355
sParams: sParams
346356
});
347357
}
@@ -591,6 +601,26 @@ class Gfx3Material {
591601
this.dataChanged = true;
592602
}
593603

604+
/**
605+
* Set the light group identifier.
606+
*
607+
* @param {number} group - The light group identifier.
608+
*/
609+
setLightGroup(group: number): void {
610+
this.params[27] = group;
611+
this.dataChanged = true;
612+
}
613+
614+
/**
615+
* Set the decal group identifier.
616+
*
617+
* @param {number} group - The decal group identifier.
618+
*/
619+
setDecalGroup(group: number): void {
620+
this.params[28] = group;
621+
this.dataChanged = true;
622+
}
623+
594624
/**
595625
* Set the dissolve glow color.
596626
*
@@ -964,7 +994,7 @@ class Gfx3Material {
964994
throw new Error('Gfx3Material::setCustomParam(): Custom param name not found !');
965995
}
966996

967-
this.params[27 + paramIndex] = value;
997+
this.params[30 + paramIndex] = value;
968998
}
969999

9701000
/**
@@ -978,7 +1008,7 @@ class Gfx3Material {
9781008
throw new Error('Gfx3Material::getCustomParam(): Custom param name not found !');
9791009
}
9801010

981-
return this.params[27 + paramIndex];
1011+
return this.params[30 + paramIndex];
9821012
}
9831013

9841014
/**
@@ -1148,4 +1178,4 @@ class Gfx3Material {
11481178
}
11491179

11501180
export { Gfx3Material };
1151-
export type { TextureTarget };
1181+
export type { TextureTarget, MATFlipbook };

0 commit comments

Comments
 (0)