x_ite 8.6.8 → 8.6.10
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/.vscode/tasks.json +1 -1
- package/dist/assets/components/Annotation.js +13 -13
- package/dist/assets/components/Annotation.min.js +1 -1
- package/dist/assets/components/CADGeometry.js +13 -13
- package/dist/assets/components/CADGeometry.min.js +1 -1
- package/dist/assets/components/CubeMapTexturing.js +25 -25
- package/dist/assets/components/CubeMapTexturing.min.js +1 -1
- package/dist/assets/components/DIS.js +13 -13
- package/dist/assets/components/DIS.min.js +1 -1
- package/dist/assets/components/EventUtilities.js +9 -9
- package/dist/assets/components/EventUtilities.min.js +1 -1
- package/dist/assets/components/Geometry2D.js +19 -19
- package/dist/assets/components/Geometry2D.min.js +1 -1
- package/dist/assets/components/Geospatial.js +33 -33
- package/dist/assets/components/Geospatial.min.js +1 -1
- package/dist/assets/components/HAnim.js +18 -18
- package/dist/assets/components/HAnim.min.js +1 -1
- package/dist/assets/components/KeyDeviceSensor.js +8 -8
- package/dist/assets/components/KeyDeviceSensor.min.js +1 -1
- package/dist/assets/components/Layout.js +27 -27
- package/dist/assets/components/Layout.min.js +1 -1
- package/dist/assets/components/NURBS.js +24 -24
- package/dist/assets/components/NURBS.min.js +1 -1
- package/dist/assets/components/ParticleSystems.js +25 -27
- package/dist/assets/components/ParticleSystems.min.js +1 -1
- package/dist/assets/components/Picking.js +19 -19
- package/dist/assets/components/Picking.min.js +1 -1
- package/dist/assets/components/RigidBodyPhysics.js +18 -18
- package/dist/assets/components/RigidBodyPhysics.min.js +1 -1
- package/dist/assets/components/Scripting.js +28 -28
- package/dist/assets/components/Scripting.min.js +1 -1
- package/dist/assets/components/Text.js +24 -24
- package/dist/assets/components/Text.min.js +1 -1
- package/dist/assets/components/TextureProjector.js +14 -14
- package/dist/assets/components/TextureProjector.min.js +1 -1
- package/dist/assets/components/Texturing3D.js +30 -30
- package/dist/assets/components/Texturing3D.min.js +1 -1
- package/dist/assets/components/VolumeRendering.js +19 -19
- package/dist/assets/components/VolumeRendering.min.js +1 -1
- package/dist/assets/components/X_ITE.js +9 -9
- package/dist/assets/components/X_ITE.min.js +1 -1
- package/dist/x_ite.css +1 -1
- package/dist/x_ite.js +907 -660
- package/dist/x_ite.min.js +1 -1
- package/dist/x_ite.zip +0 -0
- package/docs/_config.yml +2 -2
- package/docs/_posts/getting-started.md +1 -1
- package/docs/laboratory/gltf-sample-viewer.html +4 -4
- package/package.json +1 -1
- package/src/assets/shaders/webgl1/Pointing.fs.js +1 -1
- package/src/assets/shaders/webgl1/include/Fragment.glsl.js +19 -2
- package/src/assets/shaders/webgl1/include/Point.glsl.js +10 -2
- package/src/assets/shaders/webgl1/include/Texture.glsl.js +31 -1
- package/src/assets/shaders/webgl1/include/Vertex.glsl.js +24 -0
- package/src/assets/shaders/webgl2/Pointing.fs.js +1 -1
- package/src/assets/shaders/webgl2/include/Fragment.glsl.js +20 -1
- package/src/assets/shaders/webgl2/include/Point.glsl.js +12 -4
- package/src/assets/shaders/webgl2/include/Texture.glsl.js +17 -20
- package/src/assets/shaders/webgl2/include/Vertex.glsl.js +24 -0
- package/src/bookmarks.js +1 -1
- package/src/tests.js +2 -1
- package/src/x_ite/Browser/Core/BrowserOptions.js +3 -0
- package/src/x_ite/Browser/Core/BrowserTimings.js +12 -11
- package/src/x_ite/Browser/Core/Context.js +66 -64
- package/src/x_ite/Browser/Core/ContextMenu.js +0 -9
- package/src/x_ite/Browser/Navigation/ExamineViewer.js +1 -1
- package/src/x_ite/Browser/Texturing/X3DTexturingContext.js +8 -0
- package/src/x_ite/Browser/VERSION.js +1 -1
- package/src/x_ite/Browser/X3DBrowser.js +1 -1
- package/src/x_ite/Components/Core/X3DBindableNode.js +0 -2
- package/src/x_ite/Components/Core/X3DNode.js +3 -8
- package/src/x_ite/Components/Layering/X3DLayerNode.js +6 -2
- package/src/x_ite/Components/Navigation/NavigationInfo.js +1 -0
- package/src/x_ite/Components/Navigation/X3DViewpointNode.js +34 -21
- package/src/x_ite/Components/ParticleSystems/ParticleSystem.js +2 -4
- package/src/x_ite/Components/Rendering/X3DGeometryNode.js +5 -19
- package/src/x_ite/Components/Rendering/X3DLineGeometryNode.js +6 -12
- package/src/x_ite/Components/Rendering/X3DPointGeometryNode.js +4 -8
- package/src/x_ite/Components/Shaders/X3DProgrammableShaderObject.js +30 -27
- package/src/x_ite/Components/Shape/Material.js +4 -0
- package/src/x_ite/Components/Shape/PhysicalMaterial.js +4 -0
- package/src/x_ite/Components/Shape/TwoSidedMaterial.js +1 -0
- package/src/x_ite/Components/Shape/X3DMaterialNode.js +21 -19
- package/src/x_ite/Components/Shape/X3DOneSidedMaterialNode.js +4 -0
- package/src/x_ite/Components/Texturing/ImageTexture.js +80 -46
- package/src/x_ite/Components/Texturing/MultiTexture.js +7 -4
- package/src/x_ite/Components/Texturing/MultiTextureCoordinate.js +19 -16
- package/src/x_ite/Components/Texturing/MultiTextureTransform.js +16 -32
- package/src/x_ite/Components/Texturing/TextureCoordinateGenerator.js +1 -1
- package/src/x_ite/Components/Texturing/X3DSingleTextureCoordinateNode.js +2 -8
- package/src/x_ite/Components/Texturing/X3DSingleTextureTransformNode.js +2 -8
- package/src/x_ite/Execution/NamedNodesHandling.js +84 -0
- package/src/x_ite/Execution/X3DExecutionContext.js +7 -37
- package/src/x_ite/Execution/X3DScene.js +5 -0
- package/src/x_ite/InputOutput/FileLoader.js +1 -1
- package/src/x_ite/InputOutput/Generator.js +32 -81
- package/src/x_ite/Parser/GLTF2Parser.js +109 -43
- package/src/x_ite/Parser/OBJParser.js +42 -30
- package/src/x_ite/Parser/STLAParser.js +3 -0
- package/src/x_ite/Parser/SVGParser.js +4 -0
- package/src/x_ite/Rendering/X3DRenderObject.js +1 -0
- package/src/x_ite.html +53 -47
- package/x_ite.min.html +53 -47
- /package/docs/assets/X3D/{Michroma-Regular.ttf → teaser/Michroma-Regular.ttf} +0 -0
- /package/docs/assets/X3D/{peakpx.jpg → teaser/peakpx.jpg} +0 -0
- /package/docs/assets/X3D/{teaser.x3d → teaser/teaser.x3d} +0 -0
|
@@ -110,9 +110,6 @@ X3DProgrammableShaderObject .prototype =
|
|
|
110
110
|
|
|
111
111
|
browser .getRenderingProperties () ._LogarithmicDepthBuffer .addInterest ("set_logarithmicDepthBuffer__", this);
|
|
112
112
|
|
|
113
|
-
// Use by multi texture nodes.
|
|
114
|
-
this .x3d_MaxTextures = browser .getMaxTextures ();
|
|
115
|
-
|
|
116
113
|
this .set_logarithmicDepthBuffer__ ();
|
|
117
114
|
},
|
|
118
115
|
set_logarithmicDepthBuffer__: function ()
|
|
@@ -136,12 +133,14 @@ X3DProgrammableShaderObject .prototype =
|
|
|
136
133
|
// Get uniforms and attributes.
|
|
137
134
|
|
|
138
135
|
const
|
|
139
|
-
program
|
|
140
|
-
browser
|
|
141
|
-
gl
|
|
142
|
-
maxClipPlanes
|
|
143
|
-
maxLights
|
|
144
|
-
maxTextures
|
|
136
|
+
program = this .getProgram (),
|
|
137
|
+
browser = this .getBrowser (),
|
|
138
|
+
gl = browser .getContext (),
|
|
139
|
+
maxClipPlanes = browser .getMaxClipPlanes (),
|
|
140
|
+
maxLights = browser .getMaxLights (),
|
|
141
|
+
maxTextures = browser .getMaxTextures (),
|
|
142
|
+
maxTextureTransforms = browser .getMaxTextureTransforms (),
|
|
143
|
+
maxTexCoords = browser .getMaxTexCoords ();
|
|
145
144
|
|
|
146
145
|
gl .useProgram (program);
|
|
147
146
|
|
|
@@ -154,6 +153,7 @@ X3DProgrammableShaderObject .prototype =
|
|
|
154
153
|
|
|
155
154
|
this .x3d_Id = gl .getUniformLocation (program, "x3d_Id");
|
|
156
155
|
this .x3d_LogarithmicFarFactor1_2 = gl .getUniformLocation (program, "x3d_LogarithmicFarFactor1_2");
|
|
156
|
+
this .x3d_MinAlpha = gl .getUniformLocation (program, "x3d_MinAlpha");
|
|
157
157
|
|
|
158
158
|
for (let i = 0; i < maxClipPlanes; ++ i)
|
|
159
159
|
this .x3d_ClipPlane [i] = gl .getUniformLocation (program, "x3d_ClipPlane[" + i + "]");
|
|
@@ -242,17 +242,6 @@ X3DProgrammableShaderObject .prototype =
|
|
|
242
242
|
|
|
243
243
|
for (let i = 0; i < maxTextures; ++ i)
|
|
244
244
|
{
|
|
245
|
-
// Attributes
|
|
246
|
-
|
|
247
|
-
const x3d_TexCoord = this .getAttribLocation (gl, program, "x3d_TexCoord" + i, i ? "" : "x3d_TexCoord");
|
|
248
|
-
|
|
249
|
-
if (x3d_TexCoord !== -1)
|
|
250
|
-
this .x3d_TexCoord .push ([i, x3d_TexCoord]);
|
|
251
|
-
|
|
252
|
-
// Uniforms
|
|
253
|
-
|
|
254
|
-
this .x3d_TextureMatrix [i] = gl .getUniformLocation (program, "x3d_TextureMatrix[" + i + "]");
|
|
255
|
-
|
|
256
245
|
this .x3d_TextureCoordinateGeneratorMode [i] = gl .getUniformLocation (program, "x3d_TextureCoordinateGenerator[" + i + "].mode");
|
|
257
246
|
this .x3d_TextureCoordinateGeneratorParameter [i] = gl .getUniformLocation (program, "x3d_TextureCoordinateGenerator[" + i + "].parameter");
|
|
258
247
|
|
|
@@ -272,6 +261,22 @@ X3DProgrammableShaderObject .prototype =
|
|
|
272
261
|
this .x3d_ProjectiveTextureLocation [i] = gl .getUniformLocation (program, "x3d_ProjectiveTextureLocation[" + i + "]");
|
|
273
262
|
}
|
|
274
263
|
|
|
264
|
+
for (let i = 0; i < maxTextureTransforms; ++ i)
|
|
265
|
+
{
|
|
266
|
+
const uniform = gl .getUniformLocation (program, "x3d_TextureMatrix[" + i + "]");
|
|
267
|
+
|
|
268
|
+
if (uniform !== null)
|
|
269
|
+
this .x3d_TextureMatrix [i] = uniform;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
for (let i = 0; i < maxTexCoords; ++ i)
|
|
273
|
+
{
|
|
274
|
+
const x3d_TexCoord = this .getAttribLocation (gl, program, "x3d_TexCoord" + i, i ? "" : "x3d_TexCoord");
|
|
275
|
+
|
|
276
|
+
if (x3d_TexCoord !== -1)
|
|
277
|
+
this .x3d_TexCoord .push ([i, x3d_TexCoord]);
|
|
278
|
+
}
|
|
279
|
+
|
|
275
280
|
this .x3d_TexCoordRamp = gl .getUniformLocation (program, "x3d_TexCoordRamp");
|
|
276
281
|
|
|
277
282
|
this .x3d_Viewport = gl .getUniformLocation (program, "x3d_Viewport");
|
|
@@ -355,7 +360,7 @@ X3DProgrammableShaderObject .prototype =
|
|
|
355
360
|
for (const uniform of this .x3d_ProjectiveTexture)
|
|
356
361
|
gl .uniform1i (uniform, browser .getDefaultTexture2DUnit ());
|
|
357
362
|
|
|
358
|
-
gl .uniform1i
|
|
363
|
+
gl .uniform1i (this .x3d_TexCoordRamp, browser .getDefaultTexture2DUnit ());
|
|
359
364
|
},
|
|
360
365
|
getUniformLocation: function (gl, program, name, depreciated)
|
|
361
366
|
{
|
|
@@ -1041,8 +1046,7 @@ X3DProgrammableShaderObject .prototype =
|
|
|
1041
1046
|
|
|
1042
1047
|
// Fog
|
|
1043
1048
|
|
|
1044
|
-
|
|
1045
|
-
fogNode .setShaderUniforms (gl, this);
|
|
1049
|
+
fogNode?.setShaderUniforms (gl, this);
|
|
1046
1050
|
|
|
1047
1051
|
// Clip planes and local lights
|
|
1048
1052
|
|
|
@@ -1056,11 +1060,11 @@ X3DProgrammableShaderObject .prototype =
|
|
|
1056
1060
|
// Alpha
|
|
1057
1061
|
|
|
1058
1062
|
gl .uniform1f (this .x3d_AlphaCutoff, appearanceNode .getAlphaCutoff ());
|
|
1063
|
+
gl .uniform1f (this .x3d_MinAlpha, renderContext .minAlpha);
|
|
1059
1064
|
|
|
1060
1065
|
// Style Properties
|
|
1061
1066
|
|
|
1062
|
-
|
|
1063
|
-
stylePropertiesNode .setShaderUniforms (gl, this);
|
|
1067
|
+
stylePropertiesNode?.setShaderUniforms (gl, this);
|
|
1064
1068
|
|
|
1065
1069
|
// Material
|
|
1066
1070
|
|
|
@@ -1068,8 +1072,7 @@ X3DProgrammableShaderObject .prototype =
|
|
|
1068
1072
|
|
|
1069
1073
|
// Texture
|
|
1070
1074
|
|
|
1071
|
-
|
|
1072
|
-
textureNode .setShaderUniforms (gl, this, renderObject);
|
|
1075
|
+
textureNode?.setShaderUniforms (gl, this, renderObject);
|
|
1073
1076
|
|
|
1074
1077
|
appearanceNode .getTextureTransform () .setShaderUniforms (gl, this);
|
|
1075
1078
|
geometryContext .getTextureCoordinate () .setShaderUniforms (gl, this);
|
|
@@ -214,6 +214,10 @@ Material .prototype = Object .assign (Object .create (X3DOneSidedMaterialNode .p
|
|
|
214
214
|
this .setTransparent (!!(this .getTransparency () ||
|
|
215
215
|
(this .diffuseTextureNode && this .diffuseTextureNode .isTransparent ())));
|
|
216
216
|
},
|
|
217
|
+
getBaseTexture: function ()
|
|
218
|
+
{
|
|
219
|
+
return this .diffuseTexture;
|
|
220
|
+
},
|
|
217
221
|
getTextureIndices: (function ()
|
|
218
222
|
{
|
|
219
223
|
let i = 0;
|
|
@@ -173,6 +173,10 @@ PhysicalMaterial .prototype = Object .assign (Object .create (X3DOneSidedMateria
|
|
|
173
173
|
this .setTransparent (!!(this .getTransparency () ||
|
|
174
174
|
(this .baseTextureNode && this .baseTextureNode .isTransparent ())));
|
|
175
175
|
},
|
|
176
|
+
getBaseTexture: function ()
|
|
177
|
+
{
|
|
178
|
+
return this .baseTextureNode;
|
|
179
|
+
},
|
|
176
180
|
getTextureIndices: (function ()
|
|
177
181
|
{
|
|
178
182
|
let i = 0;
|
|
@@ -248,6 +248,7 @@ TwoSidedMaterial .prototype = Object .assign (Object .create (X3DMaterialNode .p
|
|
|
248
248
|
{
|
|
249
249
|
this .setTransparent (Boolean (this ._transparency .getValue () || (this ._separateBackColor .getValue () && this ._backTransparency .getValue ())));
|
|
250
250
|
},
|
|
251
|
+
getBaseTexture: Material .prototype .getBaseTexture,
|
|
251
252
|
getMaterialKey: Material .prototype .getMaterialKey,
|
|
252
253
|
createShader: Material .prototype .createShader,
|
|
253
254
|
setShaderUniforms: function (gl, shaderObject, renderObject, textureTransformMapping, textureCoordinateMapping, front)
|
|
@@ -88,6 +88,10 @@ X3DMaterialNode .prototype = Object .assign (Object .create (X3DAppearanceChildN
|
|
|
88
88
|
{
|
|
89
89
|
return this ._transparent .getValue ();
|
|
90
90
|
},
|
|
91
|
+
getBaseTexture: function ()
|
|
92
|
+
{
|
|
93
|
+
return null;
|
|
94
|
+
},
|
|
91
95
|
setTexture: function (index, textureNode)
|
|
92
96
|
{
|
|
93
97
|
const textureType = textureNode ? textureNode .getTextureType () - 1 : 0;
|
|
@@ -212,37 +216,35 @@ X3DMaterialNode .prototype = Object .assign (Object .create (X3DAppearanceChildN
|
|
|
212
216
|
options .push ("X3D_STYLE_PROPERTIES");
|
|
213
217
|
|
|
214
218
|
if (+this .textureBits)
|
|
215
|
-
{
|
|
216
219
|
options .push ("X3D_MATERIAL_TEXTURES");
|
|
217
|
-
|
|
218
|
-
|
|
220
|
+
|
|
221
|
+
if (renderContext .textureNode)
|
|
222
|
+
{
|
|
223
|
+
// ScreenText
|
|
224
|
+
|
|
225
|
+
options .push ("X3D_TEXTURE",
|
|
226
|
+
"X3D_NUM_TEXTURES 1",
|
|
227
|
+
"X3D_NUM_TEXTURE_TRANSFORMS 1",
|
|
228
|
+
"X3D_NUM_TEXTURE_COORDINATES 1",
|
|
229
|
+
"X3D_TEXTURE0_2D");
|
|
219
230
|
}
|
|
220
231
|
else
|
|
221
232
|
{
|
|
222
|
-
if (
|
|
223
|
-
{
|
|
224
|
-
// ScreenText
|
|
225
|
-
|
|
226
|
-
options .push ("X3D_TEXTURE",
|
|
227
|
-
"X3D_NUM_TEXTURES 1",
|
|
228
|
-
"X3D_NUM_TEXTURE_TRANSFORMS 1",
|
|
229
|
-
"X3D_NUM_TEXTURE_COORDINATES 1",
|
|
230
|
-
"X3D_TEXTURE0_2D");
|
|
231
|
-
}
|
|
232
|
-
else if (+appearanceNode .getTextureBits ())
|
|
233
|
+
if (+appearanceNode .getTextureBits () && !this .getBaseTexture ())
|
|
233
234
|
{
|
|
234
235
|
const textureNode = appearanceNode .getTexture ();
|
|
235
236
|
|
|
236
237
|
options .push ("X3D_TEXTURE");
|
|
237
|
-
options .push ("X3D_NUM_TEXTURES "
|
|
238
|
-
options .push ("X3D_NUM_TEXTURE_TRANSFORMS " + textureNode .getCount ());
|
|
239
|
-
options .push ("X3D_NUM_TEXTURE_COORDINATES " + textureNode .getCount ());
|
|
240
|
-
|
|
241
|
-
textureNode .getShaderOptions (options);
|
|
238
|
+
options .push ("X3D_NUM_TEXTURES " + textureNode .getCount ());
|
|
242
239
|
|
|
243
240
|
if (textureNode .getType () .includes (X3DConstants .MultiTexture))
|
|
244
241
|
options .push ("X3D_MULTI_TEXTURING");
|
|
242
|
+
|
|
243
|
+
textureNode .getShaderOptions (options);
|
|
245
244
|
}
|
|
245
|
+
|
|
246
|
+
options .push ("X3D_NUM_TEXTURE_TRANSFORMS " + (appearanceNode .getTextureTransformMapping () .size || 1));
|
|
247
|
+
options .push ("X3D_NUM_TEXTURE_COORDINATES " + (geometryContext .textureCoordinateMapping .size || 1));
|
|
246
248
|
}
|
|
247
249
|
|
|
248
250
|
switch (shapeNode .getShapeKey ())
|
|
@@ -115,6 +115,10 @@ X3DOneSidedMaterialNode .prototype = Object .assign (Object .create (X3DMaterial
|
|
|
115
115
|
{
|
|
116
116
|
this .setTransparent (Boolean (this .transparency));
|
|
117
117
|
},
|
|
118
|
+
getBaseTexture: function ()
|
|
119
|
+
{
|
|
120
|
+
return this .getEmissiveTexture ();
|
|
121
|
+
},
|
|
118
122
|
getEmissiveTexture: function ()
|
|
119
123
|
{
|
|
120
124
|
return this .emissiveTextureNode;
|
|
@@ -62,7 +62,6 @@ function ImageTexture (executionContext)
|
|
|
62
62
|
this .addType (X3DConstants .ImageTexture);
|
|
63
63
|
|
|
64
64
|
this .image = $("<img></img>");
|
|
65
|
-
this .canvas = $("<canvas></canvas>");
|
|
66
65
|
this .urlStack = new Fields .MFString ();
|
|
67
66
|
}
|
|
68
67
|
|
|
@@ -148,7 +147,7 @@ ImageTexture .prototype = Object .assign (Object .create (X3DTexture2DNode .prot
|
|
|
148
147
|
|
|
149
148
|
this .loadNext ();
|
|
150
149
|
},
|
|
151
|
-
setImage: function ()
|
|
150
|
+
setImage: async function ()
|
|
152
151
|
{
|
|
153
152
|
if (DEBUG)
|
|
154
153
|
{
|
|
@@ -159,23 +158,21 @@ ImageTexture .prototype = Object .assign (Object .create (X3DTexture2DNode .prot
|
|
|
159
158
|
try
|
|
160
159
|
{
|
|
161
160
|
const
|
|
162
|
-
gl
|
|
163
|
-
image
|
|
164
|
-
canvas = this .canvas [0],
|
|
165
|
-
cx = canvas .getContext ("2d", { willReadFrequently: true });
|
|
166
|
-
|
|
167
|
-
let
|
|
168
|
-
width = image .width,
|
|
169
|
-
height = image .height;
|
|
161
|
+
gl = this .getBrowser () .getContext (),
|
|
162
|
+
image = this .image [0];
|
|
170
163
|
|
|
171
164
|
// https://developer.mozilla.org/en-US/docs/Web/API/createImageBitmap
|
|
172
165
|
// createImageBitmap
|
|
173
166
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (gl .getVersion () >= 2 || (Algorithm .isPowerOfTwo (width) && Algorithm .isPowerOfTwo (height)))
|
|
167
|
+
if (gl .getVersion () === 1 && !(Algorithm .isPowerOfTwo (image .width) && Algorithm .isPowerOfTwo (image .height)))
|
|
177
168
|
{
|
|
178
|
-
|
|
169
|
+
const
|
|
170
|
+
canvas = document .createElement ("canvas"),
|
|
171
|
+
cx = canvas .getContext ("2d", { willReadFrequently: true }),
|
|
172
|
+
width = Algorithm .nextPowerOfTwo (image .width),
|
|
173
|
+
height = Algorithm .nextPowerOfTwo (image .height);
|
|
174
|
+
|
|
175
|
+
// Flip Y and scale image to next power of two if needed.
|
|
179
176
|
|
|
180
177
|
canvas .width = width;
|
|
181
178
|
canvas .height = height;
|
|
@@ -189,49 +186,38 @@ ImageTexture .prototype = Object .assign (Object .create (X3DTexture2DNode .prot
|
|
|
189
186
|
cx .scale (1, -1);
|
|
190
187
|
}
|
|
191
188
|
|
|
192
|
-
cx .drawImage (image, 0, 0);
|
|
189
|
+
cx .drawImage (image, 0, 0, image .width, image .height, 0, 0, width, height);
|
|
193
190
|
cx .restore ();
|
|
194
|
-
}
|
|
195
|
-
else
|
|
196
|
-
{
|
|
197
|
-
// Flip Y and scale image to next power of two.
|
|
198
191
|
|
|
199
|
-
|
|
200
|
-
height = Algorithm .nextPowerOfTwo (height);
|
|
192
|
+
// Determine image alpha.
|
|
201
193
|
|
|
202
|
-
|
|
203
|
-
|
|
194
|
+
const
|
|
195
|
+
data = cx .getImageData (0, 0, width, height) .data,
|
|
196
|
+
transparent = this .isImageTransparent (data);
|
|
204
197
|
|
|
205
|
-
|
|
206
|
-
cx .save ();
|
|
198
|
+
// Upload image to GPU.
|
|
207
199
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
cx .translate (0, height);
|
|
211
|
-
cx .scale (1, -1);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
cx .drawImage (image, 0, 0, image .width, image .height, 0, 0, width, height);
|
|
215
|
-
cx .restore ();
|
|
200
|
+
this .setTexture (width, height, transparent, data, false);
|
|
201
|
+
this .setLoadState (X3DConstants .COMPLETE_STATE);
|
|
216
202
|
}
|
|
203
|
+
else
|
|
204
|
+
{
|
|
205
|
+
const
|
|
206
|
+
data = await this .getImageData (image),
|
|
207
|
+
transparent = this .isImageTransparent (data),
|
|
208
|
+
width = image .width,
|
|
209
|
+
height = image .height;
|
|
217
210
|
|
|
218
|
-
|
|
211
|
+
// Flip Y if needed.
|
|
219
212
|
|
|
220
|
-
|
|
213
|
+
if (!this ._flipVertically .getValue ())
|
|
214
|
+
this .flipImage (data, width, height, 4);
|
|
221
215
|
|
|
222
|
-
|
|
216
|
+
// Upload image to GPU.
|
|
223
217
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (data [i] !== 255)
|
|
227
|
-
{
|
|
228
|
-
transparent = true;
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
218
|
+
this .setTexture (width, height, transparent, data, false);
|
|
219
|
+
this .setLoadState (X3DConstants .COMPLETE_STATE);
|
|
231
220
|
}
|
|
232
|
-
|
|
233
|
-
this .setTexture (width, height, transparent, data, false);
|
|
234
|
-
this .setLoadState (X3DConstants .COMPLETE_STATE);
|
|
235
221
|
}
|
|
236
222
|
catch (error)
|
|
237
223
|
{
|
|
@@ -239,6 +225,54 @@ ImageTexture .prototype = Object .assign (Object .create (X3DTexture2DNode .prot
|
|
|
239
225
|
this .setError ({ type: error .message });
|
|
240
226
|
}
|
|
241
227
|
},
|
|
228
|
+
getImageData: async function (image)
|
|
229
|
+
{
|
|
230
|
+
const
|
|
231
|
+
gl = this .getBrowser () .getContext (),
|
|
232
|
+
framebuffer = gl .createFramebuffer (),
|
|
233
|
+
texture = gl .createTexture (),
|
|
234
|
+
data = new Uint8Array (image .width * image .height * 4);
|
|
235
|
+
|
|
236
|
+
gl .bindFramebuffer (gl.FRAMEBUFFER, framebuffer);
|
|
237
|
+
gl .bindTexture (gl.TEXTURE_2D, texture);
|
|
238
|
+
gl .framebufferTexture2D (gl.FRAMEBUFFER, gl .COLOR_ATTACHMENT0, gl .TEXTURE_2D, texture, 0);
|
|
239
|
+
gl .texImage2D (gl .TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
240
|
+
await gl .readPixelsAsync (0, 0, image .width, image .height, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
241
|
+
gl .deleteFramebuffer (framebuffer);
|
|
242
|
+
gl .deleteTexture (texture);
|
|
243
|
+
|
|
244
|
+
return data;
|
|
245
|
+
},
|
|
246
|
+
isImageTransparent: function (data)
|
|
247
|
+
{
|
|
248
|
+
for (let i = 3, length = data .length; i < length; i += 4)
|
|
249
|
+
{
|
|
250
|
+
if (data [i] !== 255)
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return false;
|
|
255
|
+
},
|
|
256
|
+
flipImage (data, width, height, components)
|
|
257
|
+
{
|
|
258
|
+
const
|
|
259
|
+
height1_2 = height >> 1,
|
|
260
|
+
bytesPerRow = width * components,
|
|
261
|
+
tmp = new Uint8Array (bytesPerRow);
|
|
262
|
+
|
|
263
|
+
for (let y = 0; y < height1_2; ++ y)
|
|
264
|
+
{
|
|
265
|
+
const
|
|
266
|
+
top = y * bytesPerRow,
|
|
267
|
+
bottom = (height - y - 1) * bytesPerRow;
|
|
268
|
+
|
|
269
|
+
tmp .set (data .subarray (top, top + bytesPerRow));
|
|
270
|
+
data .copyWithin (top, bottom, bottom + bytesPerRow);
|
|
271
|
+
data .set (tmp, bottom);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return data;
|
|
275
|
+
},
|
|
242
276
|
dispose: function ()
|
|
243
277
|
{
|
|
244
278
|
X3DUrlObject .prototype .dispose .call (this);
|
|
@@ -63,6 +63,9 @@ function MultiTexture (executionContext)
|
|
|
63
63
|
|
|
64
64
|
this .addChildObjects ("loadState", new Fields .SFInt32 (X3DConstants .NOT_STARTED_STATE));
|
|
65
65
|
|
|
66
|
+
const browser = this .getBrowser ();
|
|
67
|
+
|
|
68
|
+
this .maxTextures = browser .getMaxTextures ()
|
|
66
69
|
this .color = new Float32Array (4);
|
|
67
70
|
this .modes = [ ];
|
|
68
71
|
this .alphaModes = [ ];
|
|
@@ -118,7 +121,7 @@ MultiTexture .prototype = Object .assign (Object .create (X3DTextureNode .protot
|
|
|
118
121
|
},
|
|
119
122
|
getCount: function ()
|
|
120
123
|
{
|
|
121
|
-
return Math .min (this .
|
|
124
|
+
return Math .min (this .maxTextures, this .textureNodes .length);
|
|
122
125
|
},
|
|
123
126
|
getMode: function (index)
|
|
124
127
|
{
|
|
@@ -281,7 +284,7 @@ MultiTexture .prototype = Object .assign (Object .create (X3DTextureNode .protot
|
|
|
281
284
|
updateTextureBits: function (textureBits)
|
|
282
285
|
{
|
|
283
286
|
const
|
|
284
|
-
maxTextures = this .
|
|
287
|
+
maxTextures = this .maxTextures,
|
|
285
288
|
textureNodes = this .textureNodes,
|
|
286
289
|
channels = Math .min (maxTextures, textureNodes .length);
|
|
287
290
|
|
|
@@ -294,7 +297,7 @@ MultiTexture .prototype = Object .assign (Object .create (X3DTextureNode .protot
|
|
|
294
297
|
{
|
|
295
298
|
const
|
|
296
299
|
textureNodes = this .textureNodes,
|
|
297
|
-
channels = Math .min (this .
|
|
300
|
+
channels = Math .min (this .maxTextures, textureNodes .length);
|
|
298
301
|
|
|
299
302
|
for (let i = 0; i < channels; ++ i)
|
|
300
303
|
textureNodes [i] .getShaderOptions (options, i);
|
|
@@ -308,7 +311,7 @@ MultiTexture .prototype = Object .assign (Object .create (X3DTextureNode .protot
|
|
|
308
311
|
{
|
|
309
312
|
const
|
|
310
313
|
textureNodes = this .textureNodes,
|
|
311
|
-
channels = Math .min (this .
|
|
314
|
+
channels = Math .min (this .maxTextures, textureNodes .length);
|
|
312
315
|
|
|
313
316
|
gl .uniform4fv (shaderObject .x3d_MultiTextureColor, this .color);
|
|
314
317
|
|
|
@@ -58,6 +58,9 @@ function MultiTextureCoordinate (executionContext)
|
|
|
58
58
|
|
|
59
59
|
this .addType (X3DConstants .MultiTextureCoordinate);
|
|
60
60
|
|
|
61
|
+
const browser = this .getBrowser ();
|
|
62
|
+
|
|
63
|
+
this .maxTexCoords = browser .getMaxTexCoords ();
|
|
61
64
|
this .textureCoordinateNodes = [ ];
|
|
62
65
|
}
|
|
63
66
|
|
|
@@ -110,7 +113,7 @@ MultiTextureCoordinate .prototype = Object .assign (Object .create (X3DTextureCo
|
|
|
110
113
|
},
|
|
111
114
|
getCount: function ()
|
|
112
115
|
{
|
|
113
|
-
return Math .min (this .
|
|
116
|
+
return Math .min (this .maxTexCoords, this .textureCoordinateNodes .length);
|
|
114
117
|
},
|
|
115
118
|
isEmpty: function ()
|
|
116
119
|
{
|
|
@@ -136,21 +139,27 @@ MultiTextureCoordinate .prototype = Object .assign (Object .create (X3DTextureCo
|
|
|
136
139
|
},
|
|
137
140
|
init: function (multiArray)
|
|
138
141
|
{
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
const
|
|
143
|
+
textureCoordinateNodes = this .textureCoordinateNodes,
|
|
144
|
+
length = Math .min (this .maxTexCoords, textureCoordinateNodes .length);
|
|
145
|
+
|
|
146
|
+
for (let i = 0; i < length; ++ i)
|
|
147
|
+
textureCoordinateNodes [i] .init (multiArray);
|
|
141
148
|
},
|
|
142
149
|
addPoint: function (index, multiArray)
|
|
143
150
|
{
|
|
144
|
-
const
|
|
151
|
+
const
|
|
152
|
+
textureCoordinateNodes = this .textureCoordinateNodes,
|
|
153
|
+
length = Math .min (this .maxTexCoords, textureCoordinateNodes .length);
|
|
145
154
|
|
|
146
|
-
for (let i = 0
|
|
155
|
+
for (let i = 0; i < length; ++ i)
|
|
147
156
|
textureCoordinateNodes [i] .addPointToChannel (index, multiArray [i]);
|
|
148
157
|
},
|
|
149
158
|
getTextureCoordinateMapping: function (textureCoordinateMapping)
|
|
150
159
|
{
|
|
151
160
|
const
|
|
152
161
|
textureCoordinateNodes = this .textureCoordinateNodes,
|
|
153
|
-
length = Math .min (this .
|
|
162
|
+
length = Math .min (this .maxTexCoords, textureCoordinateNodes .length);
|
|
154
163
|
|
|
155
164
|
for (let i = 0; i < length; ++ i)
|
|
156
165
|
textureCoordinateNodes [i] .getTextureCoordinateMapping (textureCoordinateMapping, i);
|
|
@@ -159,22 +168,16 @@ MultiTextureCoordinate .prototype = Object .assign (Object .create (X3DTextureCo
|
|
|
159
168
|
{
|
|
160
169
|
const
|
|
161
170
|
textureCoordinateNodes = this .textureCoordinateNodes,
|
|
162
|
-
length = Math .min (
|
|
163
|
-
|
|
164
|
-
for (let i = 0; i < length; ++ i)
|
|
165
|
-
textureCoordinateNodes [i] .setShaderUniformsToChannel (gl, shaderObject, i);
|
|
171
|
+
length = Math .min (this .maxTexCoords, textureCoordinateNodes .length);
|
|
166
172
|
|
|
167
173
|
if (length)
|
|
168
174
|
{
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
for (let i = length, l = shaderObject .x3d_MaxTextures; i < l; ++ i)
|
|
172
|
-
last .setShaderUniformsToChannel (gl, shaderObject, i);
|
|
175
|
+
for (let i = 0; i < length; ++ i)
|
|
176
|
+
textureCoordinateNodes [i] .setShaderUniforms (gl, shaderObject, i);
|
|
173
177
|
}
|
|
174
178
|
else
|
|
175
179
|
{
|
|
176
|
-
|
|
177
|
-
gl .uniform1i (shaderObject .x3d_TextureCoordinateGeneratorMode [i], 0);
|
|
180
|
+
this .getBrowser () .getDefaultTextureCoordinate () .setShaderUniforms (gl, shaderObject, 0);
|
|
178
181
|
}
|
|
179
182
|
},
|
|
180
183
|
});
|
|
@@ -51,7 +51,6 @@ import FieldDefinitionArray from "../../Base/FieldDefinitionArray.js";
|
|
|
51
51
|
import X3DTextureTransformNode from "./X3DTextureTransformNode.js";
|
|
52
52
|
import X3DConstants from "../../Base/X3DConstants.js";
|
|
53
53
|
import X3DCast from "../../Base/X3DCast.js";
|
|
54
|
-
import Matrix4 from "../../../standard/Math/Numbers/Matrix4.js";
|
|
55
54
|
|
|
56
55
|
function MultiTextureTransform (executionContext)
|
|
57
56
|
{
|
|
@@ -59,6 +58,9 @@ function MultiTextureTransform (executionContext)
|
|
|
59
58
|
|
|
60
59
|
this .addType (X3DConstants .MultiTextureTransform);
|
|
61
60
|
|
|
61
|
+
const browser = this .getBrowser ();
|
|
62
|
+
|
|
63
|
+
this .maxTextureTransforms = browser .getMaxTextureTransforms ();
|
|
62
64
|
this .textureTransformNodes = [ ];
|
|
63
65
|
}
|
|
64
66
|
|
|
@@ -102,53 +104,35 @@ MultiTextureTransform .prototype = Object .assign (Object .create (X3DTextureTra
|
|
|
102
104
|
if (textureTransformNode)
|
|
103
105
|
textureTransformNodes .push (textureTransformNode);
|
|
104
106
|
}
|
|
107
|
+
|
|
108
|
+
if (!textureTransformNodes .length)
|
|
109
|
+
textureTransformNodes .push (this .getBrowser () .getDefaultTextureTransform ());
|
|
105
110
|
},
|
|
106
111
|
getCount: function ()
|
|
107
112
|
{
|
|
108
|
-
return Math .min (this .
|
|
113
|
+
return Math .min (this .maxTextureTransforms, this .textureTransformNodes .length);
|
|
109
114
|
},
|
|
110
115
|
getTextureTransformMapping: function (textureTransformMapping)
|
|
111
116
|
{
|
|
112
117
|
const
|
|
113
118
|
textureTransformNodes = this .textureTransformNodes,
|
|
114
|
-
length = Math .min (this .
|
|
119
|
+
length = Math .min (this .maxTextureTransforms, textureTransformNodes .length);
|
|
115
120
|
|
|
116
121
|
for (let i = 0; i < length; ++ i)
|
|
117
122
|
textureTransformNodes [i] .getTextureTransformMapping (textureTransformMapping, i);
|
|
118
123
|
},
|
|
119
|
-
setShaderUniforms:
|
|
124
|
+
setShaderUniforms: function (gl, shaderObject)
|
|
120
125
|
{
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
{
|
|
125
|
-
const
|
|
126
|
-
textureTransformNodes = this .textureTransformNodes,
|
|
127
|
-
length = Math .min (shaderObject .x3d_MaxTextures, textureTransformNodes .length);
|
|
128
|
-
|
|
129
|
-
for (let i = 0; i < length; ++ i)
|
|
130
|
-
textureTransformNodes [i] .setShaderUniformsToChannel (gl, shaderObject, i);
|
|
131
|
-
|
|
132
|
-
if (length)
|
|
133
|
-
{
|
|
134
|
-
const last = textureTransformNodes .at (-1);
|
|
126
|
+
const
|
|
127
|
+
textureTransformNodes = this .textureTransformNodes,
|
|
128
|
+
length = Math .min (this .maxTextureTransforms, textureTransformNodes .length);
|
|
135
129
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
else
|
|
140
|
-
{
|
|
141
|
-
for (let i = length, l = shaderObject .x3d_MaxTextures; i < l; ++ i)
|
|
142
|
-
gl .uniformMatrix4fv (shaderObject .x3d_TextureMatrix [i], false, matrixArray);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
})(),
|
|
130
|
+
for (let i = 0; i < length; ++ i)
|
|
131
|
+
textureTransformNodes [i] .setShaderUniforms (gl, shaderObject, i);
|
|
132
|
+
},
|
|
146
133
|
transformPoint: function (texCoord)
|
|
147
134
|
{
|
|
148
|
-
|
|
149
|
-
return this .textureTransformNodes [0] .transformPoint (texCoord);
|
|
150
|
-
|
|
151
|
-
return texCoord;
|
|
135
|
+
return this .textureTransformNodes [0] .transformPoint (texCoord);
|
|
152
136
|
},
|
|
153
137
|
});
|
|
154
138
|
|
|
@@ -138,7 +138,7 @@ TextureCoordinateGenerator .prototype = Object .assign (Object .create (X3DSingl
|
|
|
138
138
|
{
|
|
139
139
|
array .push (0, 0, 0, 1);
|
|
140
140
|
},
|
|
141
|
-
|
|
141
|
+
setShaderUniforms: function (gl, shaderObject, channel = 0)
|
|
142
142
|
{
|
|
143
143
|
gl .uniform1i (shaderObject .x3d_TextureCoordinateGeneratorMode [channel], this .mode);
|
|
144
144
|
gl .uniform1fv (shaderObject .x3d_TextureCoordinateGeneratorParameter [channel], this .parameter);
|
|
@@ -77,15 +77,9 @@ X3DSingleTextureCoordinateNode .prototype = Object .assign (Object .create (X3DT
|
|
|
77
77
|
},
|
|
78
78
|
getTextureCoordinateMapping: function (textureCoordinateMapping, channel = 0)
|
|
79
79
|
{
|
|
80
|
-
|
|
81
|
-
textureCoordinateMapping .set (this ._mapping .getValue (), channel);
|
|
80
|
+
textureCoordinateMapping .set (this ._mapping .getValue () || channel, channel);
|
|
82
81
|
},
|
|
83
|
-
setShaderUniforms: function (gl, shaderObject)
|
|
84
|
-
{
|
|
85
|
-
for (let i = 0, length = shaderObject .x3d_MaxTextures; i < length; ++ i)
|
|
86
|
-
this .setShaderUniformsToChannel (gl, shaderObject, i);
|
|
87
|
-
},
|
|
88
|
-
setShaderUniformsToChannel: function (gl, shaderObject, channel = 0)
|
|
82
|
+
setShaderUniforms: function (gl, shaderObject, channel = 0)
|
|
89
83
|
{
|
|
90
84
|
gl .uniform1i (shaderObject .x3d_TextureCoordinateGeneratorMode [channel], 0);
|
|
91
85
|
},
|
|
@@ -71,15 +71,9 @@ X3DSingleTextureTransformNode .prototype = Object .assign (Object .create (X3DTe
|
|
|
71
71
|
},
|
|
72
72
|
getTextureTransformMapping: function (textureTransformMapping, channel = 0)
|
|
73
73
|
{
|
|
74
|
-
|
|
75
|
-
textureTransformMapping .set (this ._mapping .getValue (), channel);
|
|
74
|
+
textureTransformMapping .set (this ._mapping .getValue () || channel, channel);
|
|
76
75
|
},
|
|
77
|
-
setShaderUniforms: function (gl, shaderObject)
|
|
78
|
-
{
|
|
79
|
-
for (let i = 0, length = shaderObject .x3d_MaxTextures; i < length; ++ i)
|
|
80
|
-
this .setShaderUniformsToChannel (gl, shaderObject, i);
|
|
81
|
-
},
|
|
82
|
-
setShaderUniformsToChannel: function (gl, shaderObject, channel = 0)
|
|
76
|
+
setShaderUniforms: function (gl, shaderObject, channel = 0)
|
|
83
77
|
{
|
|
84
78
|
gl .uniformMatrix4fv (shaderObject .x3d_TextureMatrix [channel], false, this .matrixArray);
|
|
85
79
|
},
|