@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.3.3 → 3.3.6
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 +19 -20
- package/src/RenderingEngine.ts +0 -1336
- package/src/index.ts +0 -81
- package/src/injectors/Tag3dGeometryCreationInjector.ts +0 -154
- package/src/injectors/TextureUnifierInjector.ts +0 -214
- package/src/interfaces/ILoader.ts +0 -3
- package/src/interfaces/IPostProcessingEffectDefinitions.ts +0 -402
- package/src/interfaces/IRenderingEngine.ts +0 -48
- package/src/loaders/EnvironmentMapLoader.ts +0 -357
- package/src/loaders/GeometryLoader.ts +0 -585
- package/src/loaders/HTMLElementAnchorLoader.ts +0 -107
- package/src/loaders/LightLoader.ts +0 -171
- package/src/loaders/MaterialLoader.ts +0 -1413
- package/src/managers/CameraManager.ts +0 -178
- package/src/managers/EnvironmentGeometryManager.ts +0 -224
- package/src/managers/PostProcessingManager.ts +0 -1181
- package/src/managers/RenderingManager.ts +0 -657
- package/src/managers/SceneTracingManager.ts +0 -127
- package/src/managers/SceneTreeManager.ts +0 -576
- package/src/managers/postprocessing/GodRaysManager.ts +0 -52
- package/src/managers/postprocessing/OutlineManager.ts +0 -58
- package/src/managers/postprocessing/SSAARenderPass.ts +0 -339
- package/src/managers/postprocessing/SelectiveBloomManager.ts +0 -58
- package/src/managers/postprocessing/ao/ao/AOEffect.ts +0 -180
- package/src/managers/postprocessing/ao/ao/AOPass.ts +0 -128
- package/src/managers/postprocessing/ao/ao/shader/ao_compose.glsl +0 -17
- package/src/managers/postprocessing/ao/ao/shader/ao_compose.ts +0 -19
- package/src/managers/postprocessing/ao/hbao/HBAOEffect.ts +0 -41
- package/src/managers/postprocessing/ao/hbao/shader/hbao.glsl +0 -96
- package/src/managers/postprocessing/ao/hbao/shader/hbao.ts +0 -98
- package/src/managers/postprocessing/ao/hbao/shader/hbao_utils.glsl +0 -92
- package/src/managers/postprocessing/ao/hbao/shader/hbao_utils.ts +0 -95
- package/src/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.ts +0 -259
- package/src/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.glsl +0 -125
- package/src/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.ts +0 -127
- package/src/managers/postprocessing/ao/ssao/SSAOEffect.ts +0 -106
- package/src/managers/postprocessing/ao/ssao/shader/ssao.glsl +0 -128
- package/src/managers/postprocessing/ao/ssao/shader/ssao.ts +0 -130
- package/src/managers/postprocessing/ao/utils/shader/basic.glsl +0 -6
- package/src/managers/postprocessing/ao/utils/shader/basic.ts +0 -8
- package/src/managers/postprocessing/ao/utils/shader/sampleBlueNoise.glsl +0 -36
- package/src/managers/postprocessing/ao/utils/shader/sampleBlueNoise.ts +0 -38
- package/src/managers/postprocessing/utils/CopyMaterial.ts +0 -130
- package/src/managers/postprocessing/utils/CopyShader.ts +0 -39
- package/src/managers/postprocessing/utils/FullScreenQuad.ts +0 -47
- package/src/managers/postprocessing/utils/NormalPass.ts +0 -222
- package/src/managers/postprocessing/utils/RenderPass.ts +0 -366
- package/src/materials/GemMaterial.ts +0 -268
- package/src/materials/MeshUnlitMaterialParameters.ts +0 -4
- package/src/materials/MultiPointsMaterial.ts +0 -646
- package/src/materials/SpecularGlossinessMaterial.ts +0 -182
- package/src/objects/SDBone.ts +0 -51
- package/src/objects/SDColor.ts +0 -54
- package/src/objects/SDData.ts +0 -44
- package/src/objects/SDObject.ts +0 -58
- package/src/shaders/PCSS.ts +0 -124
- package/src/shaders/gem.ts +0 -579
- package/src/shaders/gem_frag.glsl +0 -522
- package/src/shaders/gem_vert.glsl +0 -53
- package/src/shaders/multi_points.ts +0 -291
- package/src/shaders/multi_points_frag.glsl +0 -166
- package/src/shaders/multi_points_vert.glsl +0 -120
- package/src/styling/viewport-css.ts +0 -113
- package/src/styling/viewport.css +0 -111
- package/src/three/font.ts +0 -2
- package/src/three/geometries/TextGeometry.ts +0 -58
- package/src/three/loaders/FontLoader.ts +0 -205
- package/src/three/loaders/RGBELoader.ts +0 -496
- package/src/types/IThreejsData.ts +0 -16
- package/src/types/ThreejsData.ts +0 -43
- package/tsconfig.json +0 -20
package/src/index.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ANTI_ALIASING_TECHNIQUE,
|
|
3
|
-
IBloomEffectDefinition,
|
|
4
|
-
IChromaticAberrationEffectDefinition,
|
|
5
|
-
IDepthOfFieldEffectDefinition,
|
|
6
|
-
IDotScreenEffectDefinition,
|
|
7
|
-
IGodRaysEffectDefinition,
|
|
8
|
-
IGridEffectDefinition,
|
|
9
|
-
IHBAOEffectDefinition,
|
|
10
|
-
IHueSaturationEffectDefinition,
|
|
11
|
-
INoiseEffectDefinition,
|
|
12
|
-
IOutlineEffectDefinition,
|
|
13
|
-
IPixelationEffectDefinition,
|
|
14
|
-
IPostProcessingEffectDefinition,
|
|
15
|
-
IPostProcessingEffectsArray,
|
|
16
|
-
IScanlineEffectDefinition,
|
|
17
|
-
ISelectiveBloomEffectDefinition,
|
|
18
|
-
ISepiaEffectDefinition,
|
|
19
|
-
ISSAOEffectDefinition,
|
|
20
|
-
ITiltShiftEffectDefinition,
|
|
21
|
-
IVignetteEffectDefinition,
|
|
22
|
-
POST_PROCESSING_EFFECT_TYPE
|
|
23
|
-
} from './interfaces/IPostProcessingEffectDefinitions';
|
|
24
|
-
import {
|
|
25
|
-
BlendFunction,
|
|
26
|
-
BloomEffect,
|
|
27
|
-
ChromaticAberrationEffect,
|
|
28
|
-
DepthOfFieldEffect,
|
|
29
|
-
DotScreenEffect,
|
|
30
|
-
EdgeDetectionMode,
|
|
31
|
-
Effect,
|
|
32
|
-
EffectComposer,
|
|
33
|
-
FXAAEffect,
|
|
34
|
-
GodRaysEffect,
|
|
35
|
-
GridEffect,
|
|
36
|
-
HueSaturationEffect,
|
|
37
|
-
KernelSize,
|
|
38
|
-
NoiseEffect,
|
|
39
|
-
OutlineEffect,
|
|
40
|
-
PixelationEffect,
|
|
41
|
-
PredicationMode,
|
|
42
|
-
Resolution,
|
|
43
|
-
ScanlineEffect,
|
|
44
|
-
SelectiveBloomEffect,
|
|
45
|
-
SepiaEffect,
|
|
46
|
-
SMAAEffect,
|
|
47
|
-
SMAAPreset,
|
|
48
|
-
SSAOEffect,
|
|
49
|
-
TiltShiftEffect,
|
|
50
|
-
VignetteEffect,
|
|
51
|
-
VignetteTechnique
|
|
52
|
-
} from 'postprocessing';
|
|
53
|
-
import { ENVIRONMENT_MAP, ENVIRONMENT_MAP_CUBE, ENVIRONMENT_MAP_EMPTY } from './loaders/EnvironmentMapLoader';
|
|
54
|
-
import { GlobalAccessObjects } from '@shapediver/viewer.shared.global-access-objects';
|
|
55
|
-
import { IThreejsData } from './types/IThreejsData';
|
|
56
|
-
import { MultiPointsMaterial } from './materials/MultiPointsMaterial';
|
|
57
|
-
import { PostProcessingManager } from './managers/PostProcessingManager';
|
|
58
|
-
import { RenderingEngine } from './RenderingEngine';
|
|
59
|
-
import { Tag3dGeometryCreationInjector } from './injectors/Tag3dGeometryCreationInjector';
|
|
60
|
-
import { TextureUnifierInjector } from './injectors/TextureUnifierInjector';
|
|
61
|
-
import { ThreejsData } from './types/ThreejsData';
|
|
62
|
-
|
|
63
|
-
export {
|
|
64
|
-
RenderingEngine, IThreejsData, ThreejsData, ENVIRONMENT_MAP, ENVIRONMENT_MAP_CUBE, ENVIRONMENT_MAP_EMPTY
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export {
|
|
68
|
-
MultiPointsMaterial
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export {
|
|
72
|
-
PostProcessingManager, ANTI_ALIASING_TECHNIQUE, POST_PROCESSING_EFFECT_TYPE, IPostProcessingEffectDefinition, Effect, EffectComposer, IPostProcessingEffectsArray,
|
|
73
|
-
IBloomEffectDefinition, IChromaticAberrationEffectDefinition, IDepthOfFieldEffectDefinition, IDotScreenEffectDefinition, IGodRaysEffectDefinition, IGridEffectDefinition, IHBAOEffectDefinition, IHueSaturationEffectDefinition, INoiseEffectDefinition, IOutlineEffectDefinition, IPixelationEffectDefinition, ISSAOEffectDefinition, IScanlineEffectDefinition, ISelectiveBloomEffectDefinition, ISepiaEffectDefinition, ITiltShiftEffectDefinition, IVignetteEffectDefinition,
|
|
74
|
-
BloomEffect, ChromaticAberrationEffect, DepthOfFieldEffect, DotScreenEffect, FXAAEffect, GodRaysEffect, GridEffect, HueSaturationEffect, NoiseEffect, OutlineEffect, PixelationEffect, SMAAEffect, SSAOEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, TiltShiftEffect, VignetteEffect,
|
|
75
|
-
BlendFunction, VignetteTechnique, KernelSize, SMAAPreset, EdgeDetectionMode, PredicationMode, Resolution
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const tag3dGeometryCreationInjector = new Tag3dGeometryCreationInjector();
|
|
79
|
-
GlobalAccessObjects.instance.loadTag3D = tag3dGeometryCreationInjector.convertTag3dToGeometry.bind(tag3dGeometryCreationInjector);
|
|
80
|
-
const textureUnifierInjector = new TextureUnifierInjector();
|
|
81
|
-
GlobalAccessObjects.instance.combineTextures = textureUnifierInjector.combineTextures.bind(textureUnifierInjector);
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import {
|
|
3
|
-
AttributeData,
|
|
4
|
-
GeometryData,
|
|
5
|
-
MaterialStandardData,
|
|
6
|
-
PRIMITIVE_MODE,
|
|
7
|
-
PrimitiveData
|
|
8
|
-
} from '@shapediver/viewer.shared.types';
|
|
9
|
-
import { Font } from '../three/loaders/FontLoader';
|
|
10
|
-
import { font } from '../three/font';
|
|
11
|
-
import { ITag3D } from '@shapediver/viewer.data-engine.shared-types';
|
|
12
|
-
import { ITreeNode, TreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
13
|
-
import { StateEngine } from '@shapediver/viewer.shared.services';
|
|
14
|
-
import { TextGeometry } from '../three/geometries/TextGeometry';
|
|
15
|
-
|
|
16
|
-
export class Tag3dGeometryCreationInjector {
|
|
17
|
-
// #region Properties (2)
|
|
18
|
-
|
|
19
|
-
readonly #stateEngine: StateEngine = StateEngine.instance;
|
|
20
|
-
|
|
21
|
-
public _font!: Font;
|
|
22
|
-
|
|
23
|
-
// #endregion Properties (2)
|
|
24
|
-
|
|
25
|
-
// #region Constructors (1)
|
|
26
|
-
|
|
27
|
-
constructor() {
|
|
28
|
-
this._font = new Font(font);
|
|
29
|
-
this.#stateEngine.fontLoaded.resolve(true);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// #endregion Constructors (1)
|
|
33
|
-
|
|
34
|
-
// #region Public Methods (1)
|
|
35
|
-
|
|
36
|
-
public convertTag3dToGeometry(tag3dInfo: ITag3D): ITreeNode | undefined {
|
|
37
|
-
const node = new TreeNode('tag3d_' + tag3dInfo.version);
|
|
38
|
-
|
|
39
|
-
tag3dInfo.size = tag3dInfo.size ? +tag3dInfo.size : 1;
|
|
40
|
-
if (tag3dInfo.text === undefined || tag3dInfo.text === '' || /^[ \t\n\r]*$/.test(tag3dInfo.text))
|
|
41
|
-
return;
|
|
42
|
-
|
|
43
|
-
const tagLines = tag3dInfo.text.split(/\r\n|\r|\n/g);
|
|
44
|
-
const lineArray = [];
|
|
45
|
-
|
|
46
|
-
for (let lineIndex = 0; lineIndex < tagLines.length; ++lineIndex) {
|
|
47
|
-
if (tagLines[lineIndex] === '') continue;
|
|
48
|
-
// create tag mesh object
|
|
49
|
-
const tag = new TextGeometry(tagLines[lineIndex], { size: tag3dInfo.size, height: tag3dInfo.size / 10, font: this._font });
|
|
50
|
-
lineArray.push(tag);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// create temporary object
|
|
54
|
-
const parentObject = new THREE.Object3D();
|
|
55
|
-
for (const line of lineArray) {
|
|
56
|
-
parentObject.add(new THREE.Mesh(line, new THREE.MeshPhongMaterial()));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// align lines
|
|
60
|
-
let bb, tempExtentsY, lineHeight = 0;
|
|
61
|
-
{
|
|
62
|
-
lineHeight = 0;
|
|
63
|
-
for (const child of parentObject.children) {
|
|
64
|
-
bb = new THREE.Box3().setFromObject(child);
|
|
65
|
-
tempExtentsY = bb.max.y - bb.min.y;
|
|
66
|
-
lineHeight = Math.max(lineHeight, tempExtentsY);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
lineHeight *= 1.15;
|
|
70
|
-
|
|
71
|
-
lineArray.forEach((line, i) => {
|
|
72
|
-
line.translate(0, (-i - 1) * lineHeight, 0);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// justification
|
|
76
|
-
bb = new THREE.Box3().setFromObject(parentObject);
|
|
77
|
-
|
|
78
|
-
const extentsX = bb.max.x - bb.min.x;
|
|
79
|
-
const extentsY = bb.max.y - bb.min.y;
|
|
80
|
-
const tagJustTranslation = new THREE.Vector3(0, 0, 0);
|
|
81
|
-
|
|
82
|
-
switch ((tag3dInfo.justification as string)) {
|
|
83
|
-
case 'TL':
|
|
84
|
-
break;
|
|
85
|
-
case 'TC':
|
|
86
|
-
tagJustTranslation.x = -extentsX * 0.5;
|
|
87
|
-
break;
|
|
88
|
-
case 'TR':
|
|
89
|
-
tagJustTranslation.x = -extentsX;
|
|
90
|
-
break;
|
|
91
|
-
case 'ML':
|
|
92
|
-
tagJustTranslation.y = extentsY * 0.5;
|
|
93
|
-
break;
|
|
94
|
-
case 'MC':
|
|
95
|
-
tagJustTranslation.x = -extentsX * 0.5;
|
|
96
|
-
tagJustTranslation.y = extentsY * 0.5;
|
|
97
|
-
break;
|
|
98
|
-
case 'MR':
|
|
99
|
-
tagJustTranslation.x = -extentsX;
|
|
100
|
-
tagJustTranslation.y = extentsY * 0.5;
|
|
101
|
-
break;
|
|
102
|
-
case 'BL':
|
|
103
|
-
tagJustTranslation.y = extentsY;
|
|
104
|
-
break;
|
|
105
|
-
case 'BC':
|
|
106
|
-
tagJustTranslation.x = -extentsX * 0.5;
|
|
107
|
-
tagJustTranslation.y = extentsY;
|
|
108
|
-
break;
|
|
109
|
-
case 'BR':
|
|
110
|
-
tagJustTranslation.x = -extentsX;
|
|
111
|
-
tagJustTranslation.y = extentsY;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
for (const line of lineArray) {
|
|
116
|
-
line.translate(tagJustTranslation.x, tagJustTranslation.y, tagJustTranslation.z);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// rotation
|
|
120
|
-
if (tag3dInfo.location.xAxis !== undefined) {
|
|
121
|
-
const rotMatrix = new THREE.Matrix4();
|
|
122
|
-
rotMatrix.set(tag3dInfo.location.xAxis.X, tag3dInfo.location.yAxis.X, tag3dInfo.location.normal.X, 0, tag3dInfo.location.xAxis.Y, tag3dInfo.location.yAxis.Y, tag3dInfo.location.normal.Y, 0, tag3dInfo.location.xAxis.Z, tag3dInfo.location.yAxis.Z, tag3dInfo.location.normal.Z, 0, 0, 0, 0, 1);
|
|
123
|
-
for (const line of lineArray) {
|
|
124
|
-
line.applyMatrix4(rotMatrix);
|
|
125
|
-
line.translate(tag3dInfo.location.origin.X, tag3dInfo.location.origin.Y, tag3dInfo.location.origin.Z);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
for (const line of lineArray) {
|
|
130
|
-
const attributes: {
|
|
131
|
-
[key: string]: AttributeData
|
|
132
|
-
} = {};
|
|
133
|
-
for (const attribute in line.attributes) {
|
|
134
|
-
let attributeName = attribute.toUpperCase();
|
|
135
|
-
if (/\d/.test(attributeName) && !attributeName.includes('_')) {
|
|
136
|
-
const index = attributeName.search(/\d/);
|
|
137
|
-
attributeName = attributeName.substring(0, index) + '_' + attributeName.substring(index, attributeName.length);
|
|
138
|
-
} else if (attributeName === 'TEXCOORD' || attributeName === 'COLOR' || attributeName === 'JOINTS' || attributeName === 'WEIGHTS') {
|
|
139
|
-
attributeName += '_0';
|
|
140
|
-
} else if (attributeName === 'UV') {
|
|
141
|
-
attributeName = 'TEXCOORD_0';
|
|
142
|
-
}
|
|
143
|
-
attributes[attributeName] = new AttributeData(<Float32Array>(<THREE.BufferAttribute>line.attributes[attribute]).array, line.attributes[attribute].itemSize, 0, 0, 0, false, (<Float32Array>(<THREE.BufferAttribute>line.attributes[attribute]).array).length / line.attributes[attribute].itemSize);
|
|
144
|
-
}
|
|
145
|
-
const child = new TreeNode('tag3d_' + line);
|
|
146
|
-
child.data.push(new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.TRIANGLES, new MaterialStandardData({ color: tag3dInfo.color, metalness: 0, roughness: 1 })));
|
|
147
|
-
node.children.push(child);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return node;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// #endregion Public Methods (1)
|
|
154
|
-
}
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
|
|
3
|
-
export class TextureUnifierInjector {
|
|
4
|
-
// #region Properties (5)
|
|
5
|
-
|
|
6
|
-
private _mergeShader?: THREE.ShaderMaterial;
|
|
7
|
-
private _quad?: THREE.Mesh;
|
|
8
|
-
private _quadCamera?: THREE.OrthographicCamera;
|
|
9
|
-
private _quadScene?: THREE.Scene;
|
|
10
|
-
private _renderer?: THREE.WebGLRenderer;
|
|
11
|
-
|
|
12
|
-
// #endregion Properties (5)
|
|
13
|
-
|
|
14
|
-
// #region Constructors (1)
|
|
15
|
-
|
|
16
|
-
constructor() { }
|
|
17
|
-
|
|
18
|
-
// #endregion Constructors (1)
|
|
19
|
-
|
|
20
|
-
// #region Public Methods (1)
|
|
21
|
-
|
|
22
|
-
public async combineTextures(red?: HTMLImageElement | ArrayBuffer, green?: HTMLImageElement | ArrayBuffer, blue?: HTMLImageElement | ArrayBuffer): Promise<{ image: HTMLImageElement | ArrayBuffer, blob: Blob }> {
|
|
23
|
-
if (!red && !green && !blue)
|
|
24
|
-
throw new Error('No maps supplied.');
|
|
25
|
-
|
|
26
|
-
if (red && red instanceof ArrayBuffer)
|
|
27
|
-
return { image: red, blob: new Blob([new Uint8Array(red)], { type: 'image/jpeg' }) };
|
|
28
|
-
|
|
29
|
-
if (green && green instanceof ArrayBuffer)
|
|
30
|
-
return { image: green, blob: new Blob([new Uint8Array(green)], { type: 'image/jpeg' }) };
|
|
31
|
-
|
|
32
|
-
if (blue && blue instanceof ArrayBuffer)
|
|
33
|
-
return { image: blue, blob: new Blob([new Uint8Array(blue)], { type: 'image/jpeg' }) };
|
|
34
|
-
|
|
35
|
-
if (!this._renderer)
|
|
36
|
-
this.createThreeJsUtils();
|
|
37
|
-
|
|
38
|
-
let width = 0, height = 0;
|
|
39
|
-
const textures = [red, green, blue];
|
|
40
|
-
for (const t of textures) {
|
|
41
|
-
if (t) {
|
|
42
|
-
if (width === 0 && height === 0) {
|
|
43
|
-
width = t.width;
|
|
44
|
-
height = t.height;
|
|
45
|
-
} else if (t.width !== width && t.height !== height) {
|
|
46
|
-
throw new Error('Maps have different sizes. Combining not supported.');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (red) {
|
|
52
|
-
const redTexture = new THREE.Texture(red);
|
|
53
|
-
redTexture.needsUpdate = true;
|
|
54
|
-
this._mergeShader!.uniforms.tRed.value = redTexture;
|
|
55
|
-
this._mergeShader!.uniforms.activeRed.value = true;
|
|
56
|
-
} else {
|
|
57
|
-
this._mergeShader!.uniforms.activeRed.value = false;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (green) {
|
|
61
|
-
const greenTexture = new THREE.Texture(green);
|
|
62
|
-
greenTexture.needsUpdate = true;
|
|
63
|
-
this._mergeShader!.uniforms.tGreen.value = greenTexture;
|
|
64
|
-
this._mergeShader!.uniforms.activeGreen.value = true;
|
|
65
|
-
} else {
|
|
66
|
-
this._mergeShader!.uniforms.activeGreen.value = false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (blue) {
|
|
70
|
-
const blueTexture = new THREE.Texture(blue);
|
|
71
|
-
blueTexture.needsUpdate = true;
|
|
72
|
-
this._mergeShader!.uniforms.tBlue.value = blueTexture;
|
|
73
|
-
this._mergeShader!.uniforms.activeBlue.value = true;
|
|
74
|
-
} else {
|
|
75
|
-
this._mergeShader!.uniforms.activeBlue.value = false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// The different render targets that are used by the passes
|
|
79
|
-
const renderTarget = new THREE.WebGLRenderTarget(width, height, {
|
|
80
|
-
minFilter: THREE.LinearFilter,
|
|
81
|
-
magFilter: THREE.LinearFilter,
|
|
82
|
-
format: THREE.RGBAFormat
|
|
83
|
-
});
|
|
84
|
-
renderTarget.texture.name = 'target.rt';
|
|
85
|
-
this._renderer!.setRenderTarget(renderTarget);
|
|
86
|
-
|
|
87
|
-
this._renderer!.render(this._quadScene!, this._quadCamera!);
|
|
88
|
-
|
|
89
|
-
const buffer = new Uint8ClampedArray(4 * width * height);
|
|
90
|
-
this._renderer!.readRenderTargetPixels(renderTarget, 0, 0, width, height, buffer);
|
|
91
|
-
|
|
92
|
-
const imageData = new ImageData(buffer, width, height);
|
|
93
|
-
const canvas = document.createElement('canvas');
|
|
94
|
-
const ctx = <CanvasRenderingContext2D>canvas.getContext('2d');
|
|
95
|
-
canvas.width = imageData.width;
|
|
96
|
-
canvas.height = imageData.height;
|
|
97
|
-
ctx.putImageData(imageData, 0, 0);
|
|
98
|
-
|
|
99
|
-
const imageOut = new Image();
|
|
100
|
-
const promises = [];
|
|
101
|
-
promises.push(new Promise<void>((resolve, reject) => {
|
|
102
|
-
imageOut.onload = () => resolve();
|
|
103
|
-
imageOut.onerror = reject;
|
|
104
|
-
}));
|
|
105
|
-
|
|
106
|
-
imageOut.crossOrigin = 'anonymous';
|
|
107
|
-
const mimeType = 'image/jpeg';
|
|
108
|
-
imageOut.src = canvas.toDataURL(mimeType, 1.0);
|
|
109
|
-
|
|
110
|
-
let blob!: Blob;
|
|
111
|
-
promises.push(new Promise<void>((resolve, reject) => {
|
|
112
|
-
canvas.toBlob((b) => {
|
|
113
|
-
if (!b) {
|
|
114
|
-
reject('Could not create blob.');
|
|
115
|
-
} else {
|
|
116
|
-
blob = b;
|
|
117
|
-
}
|
|
118
|
-
resolve();
|
|
119
|
-
}, mimeType, 1.0);
|
|
120
|
-
}));
|
|
121
|
-
|
|
122
|
-
await Promise.all(promises);
|
|
123
|
-
|
|
124
|
-
return { image: imageOut, blob };
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// #endregion Public Methods (1)
|
|
128
|
-
|
|
129
|
-
// #region Private Methods (1)
|
|
130
|
-
|
|
131
|
-
private createThreeJsUtils() {
|
|
132
|
-
this._mergeShader = new THREE.ShaderMaterial({
|
|
133
|
-
uniforms: {
|
|
134
|
-
tRed: { value: null },
|
|
135
|
-
activeRed: { value: false },
|
|
136
|
-
defaultRed: { value: 1.0 },
|
|
137
|
-
tGreen: { value: null },
|
|
138
|
-
activeGreen: { value: false },
|
|
139
|
-
defaultGreen: { value: 1.0 },
|
|
140
|
-
tBlue: { value: null },
|
|
141
|
-
activeBlue: { value: false },
|
|
142
|
-
defaultBlue: { value: 1.0 },
|
|
143
|
-
},
|
|
144
|
-
vertexShader: `// @author Michael Oppitz
|
|
145
|
-
|
|
146
|
-
uniform sampler2D tRed;
|
|
147
|
-
uniform bool activeRed;
|
|
148
|
-
uniform float defaultRed;
|
|
149
|
-
|
|
150
|
-
uniform sampler2D tGreen;
|
|
151
|
-
uniform bool activeGreen;
|
|
152
|
-
uniform float defaultGreen;
|
|
153
|
-
|
|
154
|
-
uniform sampler2D tBlue;
|
|
155
|
-
uniform bool activeBlue;
|
|
156
|
-
uniform float defaultBlue;
|
|
157
|
-
|
|
158
|
-
varying vec2 vUv;
|
|
159
|
-
|
|
160
|
-
void main() {
|
|
161
|
-
vUv = uv;
|
|
162
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
163
|
-
}`,
|
|
164
|
-
fragmentShader: `// @author Michael Oppitz
|
|
165
|
-
|
|
166
|
-
uniform sampler2D tRed;
|
|
167
|
-
uniform bool activeRed;
|
|
168
|
-
uniform float defaultRed;
|
|
169
|
-
|
|
170
|
-
uniform sampler2D tGreen;
|
|
171
|
-
uniform bool activeGreen;
|
|
172
|
-
uniform float defaultGreen;
|
|
173
|
-
|
|
174
|
-
uniform sampler2D tBlue;
|
|
175
|
-
uniform bool activeBlue;
|
|
176
|
-
uniform float defaultBlue;
|
|
177
|
-
|
|
178
|
-
varying vec2 vUv;
|
|
179
|
-
|
|
180
|
-
void main() {
|
|
181
|
-
vec4 outColor = vec4(0.0, 0.0, 0.0, 1.0);
|
|
182
|
-
|
|
183
|
-
if(activeRed == true) {
|
|
184
|
-
outColor.r = texture2D(tRed, vUv).r;
|
|
185
|
-
} else {
|
|
186
|
-
outColor.r = defaultRed;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if(activeGreen == true) {
|
|
190
|
-
outColor.g = texture2D(tGreen, vUv).g;
|
|
191
|
-
} else {
|
|
192
|
-
outColor.g = defaultGreen;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if(activeBlue == true) {
|
|
196
|
-
outColor.b = texture2D(tBlue, vUv).b;
|
|
197
|
-
} else {
|
|
198
|
-
outColor.b = defaultBlue;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
gl_FragColor = outColor;
|
|
202
|
-
}`
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
this._quadCamera = new THREE.OrthographicCamera(- 1, 1, 1, - 1, 0, 1);
|
|
206
|
-
this._quadScene = new THREE.Scene();
|
|
207
|
-
this._quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), this._mergeShader);
|
|
208
|
-
this._quadScene.add(this._quad);
|
|
209
|
-
|
|
210
|
-
this._renderer = new THREE.WebGLRenderer();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// #endregion Private Methods (1)
|
|
214
|
-
}
|