wgge 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wgge",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Web GL Game Engine",
5
5
  "main": "index.js",
6
6
  "devDependencies": {
@@ -1,136 +0,0 @@
1
- import DomRenderer from "../../core/renderer/dom/DomRenderer";
2
- import * as THREE from "three";
3
- import {BoxGeometry, SphereGeometry} from "three";
4
- import {EffectComposer} from "three/examples/jsm/postprocessing/EffectComposer";
5
- import {RenderPass} from "three/examples/jsm/postprocessing/RenderPass";
6
- import {ShaderPass} from "three/examples/jsm/postprocessing/ShaderPass";
7
- import {FXAAShader} from "three/examples/jsm/shaders/FXAAShader";
8
- import Vector2 from "../../core/model/vector/Vector2";
9
- import Vector3 from "../../core/model/vector/Vector3";
10
- import DOMHelper from "../../core/helper/DOMHelper";
11
-
12
- const PREVIEW_SIZE = new Vector2(350, 350);
13
-
14
- export default class MaterialPreviewRenderer extends DomRenderer {
15
-
16
- /**
17
- * @type MaterialModel
18
- */
19
- model;
20
-
21
- constructor(game, model, dom) {
22
- super(game, model, dom);
23
-
24
- this.model = model;
25
- this.container = null;
26
- this.scene = null;
27
- }
28
-
29
- activateInternal() {
30
- this.container = this.addElement('div', 'bg item-def');
31
- this.buttons = DOMHelper.createElement(this.container, 'div', 'buttons');
32
- this.close = DOMHelper.createElement(this.buttons, 'button', null, 'Close', () => this.game.editor.activeMaterial.set(null));
33
-
34
- this.paper = DOMHelper.createElement(this.container, 'div', 'paper');
35
- this.inner = DOMHelper.createElement(this.paper, 'div', 'inner');
36
-
37
- this.renderer = new THREE.WebGLRenderer({antialias: true, alpha: true});
38
- this.inner.appendChild(this.renderer.domElement);
39
- this.renderer.setSize(PREVIEW_SIZE.x, PREVIEW_SIZE.y);
40
- this.scene = new THREE.Scene();
41
-
42
- const horizontal = 3;
43
- const vertical = 3;
44
-
45
- this.camera = new THREE.OrthographicCamera(-horizontal, horizontal, -vertical, vertical);
46
- this.camera.updateProjectionMatrix();
47
-
48
- const camPosition = new Vector3(-100, 100, -100);
49
- this.camera.position.set(camPosition.x, camPosition.y, camPosition.z);
50
- this.camera.lookAt(0, 0, 0);
51
-
52
- this.ambientLight = new THREE.AmbientLight(0xe0e0e0);
53
- this.scene.add(this.ambientLight);
54
-
55
- this.directLight = new THREE.DirectionalLight(0xe0e0e0, 1);
56
- this.directLight.position.set(0, 10, 0);
57
- this.directLight.castShadow = true;
58
- this.directLight.shadow.bias = 0;
59
- this.directLight.shadow.camera.near = 0.5;
60
- this.directLight.shadow.camera.far = 25;
61
- this.directLight.shadow.camera.right = 15;
62
- this.directLight.shadow.camera.left = -15;
63
- this.directLight.shadow.camera.top = 15;
64
- this.directLight.shadow.camera.bottom = -15;
65
- this.directLight.shadow.mapSize.width = 1024;
66
- this.directLight.shadow.mapSize.height = 1024;
67
- this.scene.add(this.directLight);
68
-
69
- this.composer = new EffectComposer(this.renderer);
70
- this.composer.setSize(PREVIEW_SIZE.x, PREVIEW_SIZE.y);
71
-
72
- const renderPass = new RenderPass(this.scene, this.camera);
73
- renderPass.clearColor = new THREE.Color(0, 0, 0);
74
- renderPass.clearAlpha = 0;
75
- this.composer.addPass(renderPass);
76
-
77
- this.effectFXAA = new ShaderPass(FXAAShader);
78
- this.effectFXAA.uniforms['resolution'].value.set(1 / PREVIEW_SIZE.x, 1 / PREVIEW_SIZE.y);
79
- this.effectFXAA.material.transparent = true;
80
- this.composer.addPass(this.effectFXAA);
81
-
82
- const pixelRatio = this.renderer.getPixelRatio();
83
- this.effectFXAA.material.uniforms['resolution'].value.x = 1 / (PREVIEW_SIZE.x * pixelRatio);
84
- this.effectFXAA.material.uniforms['resolution'].value.y = 1 / (PREVIEW_SIZE.y * pixelRatio);
85
-
86
- this.updatePreview();
87
- }
88
-
89
- deactivateInternal() {
90
- this.ambientLight.dispose();
91
- this.ambientLight = null;
92
- this.directLight.dispose();
93
- this.directLight = null;
94
- this.scene = null;
95
- this.renderer.dispose();
96
- this.renderer = false;
97
- this.removeElement(this.container);
98
- if (this.gui) {
99
- this.gui.destroy();
100
- this.gui = null;
101
- }
102
- }
103
-
104
- renderInternal() {
105
- this.updatePreview();
106
- }
107
-
108
- updatePreview() {
109
- this.game.assets.resetMaterial(this.model.id.get());
110
- this.game.assets.loadMaterial(
111
- this.model.id.get(),
112
- (material) => {
113
- if (this.ball) {
114
- this.ball.removeFromParent();
115
- }
116
- this.ball = new THREE.Mesh(
117
- new SphereGeometry(),
118
- material
119
- );
120
- this.scene.add(this.ball);
121
-
122
- if (this.box) {
123
- this.box.removeFromParent();
124
- }
125
- this.box = new THREE.Mesh(
126
- new BoxGeometry(),
127
- material
128
- );
129
- this.box.position.set(-10, -10, -10);
130
- this.scene.add(this.box);
131
- this.composer.render();
132
- }
133
- )
134
- }
135
-
136
- }
@@ -1,16 +0,0 @@
1
- import AssetLoader from "./AssetLoader";
2
- import {GLTFLoader} from "three/examples/jsm/loaders/GLTFLoader";
3
-
4
- export default class GlbLoader extends AssetLoader {
5
-
6
- loadInternal() {
7
- const loader = new GLTFLoader();
8
- loader.load(
9
- this.url(),
10
- (gltf) => this.finish(gltf),
11
- null,
12
- (err) => this.fail(`Glb '${this.url()}' not loaded: ${err}`)
13
- );
14
- }
15
-
16
- }
@@ -1,50 +0,0 @@
1
- import * as THREE from "three";
2
- import AssetLoader from "./AssetLoader";
3
- import StringHelper from "../../../../core/helper/StringHelper";
4
-
5
- /**
6
- * Loads a single THREE material.
7
- */
8
- export default class MaterialLoader extends AssetLoader {
9
-
10
- loadInternal() {
11
-
12
- const id = StringHelper.extractId(this.uri);
13
- const definition = this.assets.resources.materials.getById(id);
14
-
15
- if (!definition) {
16
- this.fail(`material ID ${this.uri} not found`);
17
- return;
18
- }
19
-
20
- const params = {
21
- color: definition.color.get()
22
- };
23
-
24
- if (definition.useTexture.get()) {
25
- this.assets.getAsset(
26
- definition.uri.get(),
27
- (img) => {
28
- const texture = new THREE.Texture();
29
- texture.image = img;
30
- texture.needsUpdate = true;
31
- texture.wrapS = definition.wrapS.get();
32
- texture.wrapT = definition.wrapT.get();
33
- texture.repeat.set(
34
- definition.repeatX.get(),
35
- definition.repeatY.get()
36
- );
37
- params.map = texture;
38
- this.finish(this.createMaterial(definition.threeType.get(), params));
39
- }
40
- );
41
- } else {
42
- this.finish(this.createMaterial(definition.threeType.get(), params));
43
- }
44
- }
45
-
46
- createMaterial(threeType, params) {
47
- return new THREE[threeType](params);
48
- }
49
-
50
- }
@@ -1,28 +0,0 @@
1
- import AssetLoader from "./AssetLoader";
2
- import StringHelper from "../../../../core/helper/StringHelper";
3
- import AnimationHelper from "../../../../core/animation/3d/AnimationHelper";
4
- import * as SkeletonUtils from "three/examples/jsm/utils/SkeletonUtils";
5
-
6
- /**
7
- * Loads an AnimationHelper for 3d model
8
- */
9
- export default class Model3dAnimationLoader extends AssetLoader {
10
-
11
- loadInternal() {
12
-
13
- const id = StringHelper.extractId(this.uri);
14
- const model = this.assets.resources.models3d.getById(id);
15
-
16
- if (!model) {
17
- this.fail(`3D model id ${id} (${this.uri}) not found!`);
18
- return;
19
- }
20
-
21
- this.assets.getAsset(model.uri.get(), (gltf) => {
22
- const anim = new AnimationHelper(SkeletonUtils.clone(gltf.scene), gltf.animations);
23
- anim.mesh.scale.set(model.scale.x, model.scale.y, model.scale.z);
24
- this.finish(anim);
25
- });
26
- }
27
-
28
- }
@@ -1,26 +0,0 @@
1
- import AssetLoader from "./AssetLoader";
2
- import StringHelper from "../../../../core/helper/StringHelper";
3
-
4
- /**
5
- * Loads a 3d model
6
- */
7
- export default class Model3dLoader extends AssetLoader {
8
-
9
- loadInternal() {
10
-
11
- const id = StringHelper.extractId(this.uri);
12
- const model = this.assets.resources.models3d.getById(id);
13
-
14
- if (!model) {
15
- this.fail(`3D model id ${id} (${this.uri}) not found!`);
16
- return;
17
- }
18
-
19
- this.assets.getAsset(model.uri.get(), (gltf) => {
20
- const mesh = gltf.scene.clone();
21
- mesh.scale.set(model.scale.x, model.scale.y, model.scale.z);
22
- this.finish(mesh);
23
- });
24
- }
25
-
26
- }
@@ -1,40 +0,0 @@
1
- import * as THREE from "three";
2
- import AssetLoader from "./AssetLoader";
3
- import StringHelper from "../../../../core/helper/StringHelper";
4
-
5
- /**
6
- * Loads a single Sprite
7
- */
8
- export default class SpriteLoader extends AssetLoader {
9
-
10
- loadInternal() {
11
-
12
- const spriteId = StringHelper.extractId(this.uri);
13
- const sprite = this.assets.resources.sprites.getById(spriteId);
14
-
15
- if (!sprite) {
16
- this.fail(`Sprite ${spriteId} not found!`);
17
- return;
18
- }
19
-
20
- this.assets.getAsset(sprite.uri.get(), (img) => {
21
- const texture = new THREE.Texture();
22
- texture.image = img;
23
- texture.needsUpdate = true;
24
- texture.wrapS = THREE.RepeatWrapping;
25
- texture.wrapT = THREE.RepeatWrapping;
26
- texture.repeat.set(1, 1);
27
- const mesh = new THREE.Mesh(new THREE.PlaneGeometry(sprite.size.x, sprite.size.y), new THREE.MeshBasicMaterial({
28
- transparent: true,
29
- map: texture
30
- }));
31
- //const mesh = new THREE.Sprite(new THREE.SpriteMaterial({map: texture}));
32
- mesh.position.set(sprite.coordinates.x, sprite.coordinates.y, sprite.coordinates.z);
33
- const target = mesh.position.clone().add(new THREE.Vector3(-1, 1, -1));
34
- mesh.lookAt(target.x, target.y, target.z);
35
- this.finish(mesh);
36
- });
37
-
38
- }
39
-
40
- }
@@ -1,69 +0,0 @@
1
- import DirtyValue from "../../../core/model/value/DirtyValue";
2
- import IdentifiedModelNode from "../../../core/model/collection/table/IdentifiedModelNode";
3
- import * as THREE from "three";
4
- import BoolValue from "../../../core/model/value/BoolValue";
5
- import IntValue from "../../../core/model/value/IntValue";
6
-
7
- export default class MaterialModel extends IdentifiedModelNode {
8
-
9
- /**
10
- * @type DirtyValue
11
- */
12
- name;
13
-
14
- /**
15
- * @type DirtyValue
16
- */
17
- threeType;
18
-
19
- /**
20
- * @type DirtyValue
21
- */
22
- color;
23
-
24
- /**
25
- * @type BoolValue
26
- */
27
- useTexture;
28
-
29
- /**
30
- * @type DirtyValue
31
- */
32
- uri;
33
-
34
- /**
35
- * @type IntValue
36
- */
37
- wrapS;
38
-
39
- /**
40
- * @type IntValue
41
- */
42
- wrapT;
43
-
44
- /**
45
- * @type IntValue
46
- */
47
- repeatX;
48
-
49
- /**
50
- * @type IntValue
51
- */
52
- repeatY;
53
-
54
- constructor(id) {
55
- super(id);
56
-
57
- this.name = this.addProperty('name', new DirtyValue(`Material ${id}`));
58
- this.threeType = this.addProperty('threeType', new DirtyValue('MeshBasicMaterial'));
59
- this.color = this.addProperty('color', new DirtyValue('#700000'));
60
-
61
- this.useTexture = this.addProperty('useTexture', new BoolValue(true));
62
- this.uri = this.addProperty('uri', new DirtyValue('img/texture/dirt.png'));
63
- this.wrapS = this.addProperty('wrapS', new IntValue(THREE.RepeatWrapping));
64
- this.wrapT = this.addProperty('wrapT', new IntValue(THREE.RepeatWrapping));
65
- this.repeatX = this.addProperty('repeatX', new IntValue(2));
66
- this.repeatY = this.addProperty('repeatY', new IntValue(2));
67
- }
68
-
69
- }