Commit ae2acf21 authored by MARTIN Tanguy's avatar MARTIN Tanguy
Browse files

Upload Character Classes

parent 32c6f781
Pipeline #5196 passed with stage
in 14 seconds
const spriteBase = new THREE.PlaneGeometry(
220,
210
);
class Character {
constructor(front_sprite,back_sprite,x,y,z) {
this.x = x;
this.y = y;
this.z = z;
this.base = spriteBase.clone();
if(this.z >= 0) {
this.base.rotateY(Math.PI);
}
this.front_material = CharacterMaterialBase.clone();
this.back_material = CharacterMaterialBase.clone();
this.front_material.side = THREE.FrontSide;
this.back_material.side = THREE.BackSide;
this.front_material.uniforms.uTextures.value = [TextureLoader.load(front_sprite)];
this.back_material.uniforms.uTextures.value = [TextureLoader.load(back_sprite)];
this.materials = [this.front_material, this.back_material];
}
updateSprite() {
this.front_material.uniforms.uFireLightColor.value.copy(fireMaterial.uniforms.uMaterialColor.value);
this.back_material.uniforms.uFireLightColor.value.copy(fireMaterial.uniforms.uMaterialColor.value);
this.front_material.uniforms.uFireIntensity.value = fireIntensity;
this.back_material.uniforms.uFireIntensity.value = fireIntensity;
var pos = new THREE.Vector3();
fireLight.getWorldPosition(pos);
this.front_material.uniforms.uFireLightPos.value.copy(pos);
this.back_material.uniforms.uFireLightPos.value.copy(pos);
spotLight.getWorldPosition(pos);
this.front_material.uniforms.uSpotLightPos.value.copy(pos);
this.back_material.uniforms.uSpotLightPos.value.copy(pos);
}
draw() {
var sprite = new THREE.SceneUtils.createMultiMaterialObject(this.base, this.materials);
sprite.position.x=this.x;
sprite.position.y=this.y;
sprite.position.z=this.z;
sprite.receiveShadow = true;
sprite.castShadow = true;
return sprite;
}
}
class InteractiveBooleanCharacter extends Character {
constructor(var_name,front_sprite_true,back_sprite_true,front_sprite_false,back_sprite_false,x,y,z) {
super(
'',
'',
x,y,z
);
this.var_name = var_name;
this.front_material.defines.TEXTURES_NUM = 2;
this.front_material.uniforms.uTextures.value = [
TextureLoader.load(front_sprite_true),
TextureLoader.load(front_sprite_false)
];
this.front_material.uniforms.uBool.value = interactiveStates[var_name];
this.back_material.defines.TEXTURES_NUM = 2;
this.back_material.uniforms.uTextures.value = [
TextureLoader.load(back_sprite_true),
TextureLoader.load(back_sprite_false)
];
this.back_material.uniforms.uBool.value = interactiveStates[var_name];
}
updateSprite() {
super.updateSprite();
this.front_material.uniforms.uBool.value = interactiveStates[this.var_name];
this.back_material.uniforms.uBool.value = interactiveStates[this.var_name];
}
}
class InteractiveStringCharacter extends Character {
constructor(var_name,front_sprites,back_sprites,x,y,z) {
super(
'',
'',
x,y,z
);
this.var_name = var_name;
this.front_material.defines.TEXTURES_NUM = front_sprites.length;
this.back_material.defines.TEXTURES_NUM = back_sprites.length;
this.front_material.defines.TEXTURE_INDICE = interactiveStates[var_name];
this.back_material.defines.TEXTURE_INDICE = interactiveStates[var_name];
this.front_material.uniforms.uTextures.value = [];
for(var i = 0; i < front_sprites.length; i++) {
this.front_material.uniforms.uTextures.value.push(front_sprites[i]);
}
this.back_material.uniforms.uTextures.value = [];
for(var i = 0; i < front_sprites.length; i++) {
this.back_material.uniforms.uTextures.value.push(back_sprites[i]);
}
}
updateSprite() {
super.updateSprite();
this.front_material.defines.TEXTURE_INDICE = interactiveStates[this.var_name];
this.back_material.defines.TEXTURE_INDICE = interactiveStates[this.var_name];
this.front_material.needsUpdate = true;
this.back_material.needsUpdate = true;
}
}
class MainCharacter extends InteractiveBooleanCharacter {
constructor(var_name,front_sprite_true,back_sprite_true,front_sprite_false,back_sprite_false,x,y,z) {
super(var_name,front_sprite_true,back_sprite_true,front_sprite_false,back_sprite_false,x,y,z);
this.front_material.uniforms.uCharacterType.value = 3;
this.back_material.uniforms.uCharacterType.value = 3;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment