Skip to content

Commit 5e4cd47

Browse files
committed
Respect Texture.repeat / offset for surface maps
1 parent 654c739 commit 5e4cd47

File tree

11 files changed

+405
-27
lines changed

11 files changed

+405
-27
lines changed

build/MathBox-bundle.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40192,14 +40192,26 @@ ThreeBox.preload.html = function (file, name, callback) {
4019240192
var match;
4019340193

4019440194
// Insert javascript directly
40195-
if (match = res.match(/^<script[^>]*type=['"]text\/javascript['"][^>]*>([\s\S]+?)<\/script>$/m)) {
40196-
var script = document.createElement('script');
40197-
script.type = 'text/javascript';
40198-
script.innerHTML = match[1];
40199-
document.body.appendChild(script);
40195+
while (match = res.match(/^(<script\s*>|<script[^>]*type=['"]text\/javascript['"][^>]*>)([\s\S]+?)<\/script>$/m)) {
40196+
try {
40197+
/*
40198+
var script = document.createElement('script');
40199+
script.type = 'text/javascript';
40200+
script.innerHTML = match[2];
40201+
document.body.appendChild(script);
40202+
*/
40203+
eval('(function () {' + match[2] + '})()');
40204+
}
40205+
catch (e) {
40206+
console.error(e);
40207+
console.error('While evaluating: ' + match[2]);
40208+
}
40209+
40210+
res = res.replace(match[0], '');
4020040211
}
40212+
4020140213
// Insert HTML via div
40202-
else {
40214+
if (res.replace(/\s*/g) != '') {
4020340215
var div = document.createElement('div');
4020440216
div.innerHTML = res;
4020540217
document.body.appendChild(div);
@@ -43937,9 +43949,16 @@ MathBox.Materials.prototype = {
4393743949
});
4393843950

4393943951
if (type == 'uniforms') {
43952+
var uniforms = material.uniforms;
4394043953
if (options.map !== undefined) {
43941-
if (material.uniforms.texture) {
43942-
material.uniforms.texture.value = options.map;
43954+
if (uniforms.texture) {
43955+
uniforms.texture.value = options.map;
43956+
}
43957+
if (uniforms.offsetRepeat) {
43958+
var offset = options.map.offset;
43959+
var repeat = options.map.repeat;
43960+
43961+
uniforms.offsetRepeat.value.set(offset.x, offset.y, repeat.x, repeat.y);
4394343962
}
4394443963
}
4394543964
if (options.lineWidth !== undefined) {

build/MathBox-bundle.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/MathBox-core.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,9 +1340,16 @@ MathBox.Materials.prototype = {
13401340
});
13411341

13421342
if (type == 'uniforms') {
1343+
var uniforms = material.uniforms;
13431344
if (options.map !== undefined) {
1344-
if (material.uniforms.texture) {
1345-
material.uniforms.texture.value = options.map;
1345+
if (uniforms.texture) {
1346+
uniforms.texture.value = options.map;
1347+
}
1348+
if (uniforms.offsetRepeat) {
1349+
var offset = options.map.offset;
1350+
var repeat = options.map.repeat;
1351+
1352+
uniforms.offsetRepeat.value.set(offset.x, offset.y, repeat.x, repeat.y);
13461353
}
13471354
}
13481355
if (options.lineWidth !== undefined) {

build/MathBox-core.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/MathBox.glsl.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,17 @@
312312
<script type="application/x-glsl" id="vertexOutput">
313313
// Vertex shader: set GL vertex properties and varyings
314314
uniform float pointSize;
315+
316+
uniform vec4 offsetRepeat;
315317
varying vec2 vUV;
318+
316319
varying vec3 vViewPosition;
317320

318321
void vertexOutput(in vec4 position, in vec3 viewPosition) {
319322
gl_Position = position;
320323
gl_PointSize = pointSize;
321324

322-
vUV = uv;
325+
vUV = uv * offsetRepeat.zw + offsetRepeat.xy;
323326
vViewPosition = viewPosition;
324327
}
325328
</script>

build/MathBox.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,14 +569,26 @@ ThreeBox.preload.html = function (file, name, callback) {
569569
var match;
570570

571571
// Insert javascript directly
572-
if (match = res.match(/^<script[^>]*type=['"]text\/javascript['"][^>]*>([\s\S]+?)<\/script>$/m)) {
573-
var script = document.createElement('script');
574-
script.type = 'text/javascript';
575-
script.innerHTML = match[1];
576-
document.body.appendChild(script);
572+
while (match = res.match(/^(<script\s*>|<script[^>]*type=['"]text\/javascript['"][^>]*>)([\s\S]+?)<\/script>$/m)) {
573+
try {
574+
/*
575+
var script = document.createElement('script');
576+
script.type = 'text/javascript';
577+
script.innerHTML = match[2];
578+
document.body.appendChild(script);
579+
*/
580+
eval('(function () {' + match[2] + '})()');
581+
}
582+
catch (e) {
583+
console.error(e);
584+
console.error('While evaluating: ' + match[2]);
585+
}
586+
587+
res = res.replace(match[0], '');
577588
}
589+
578590
// Insert HTML via div
579-
else {
591+
if (res.replace(/\s*/g) != '') {
580592
var div = document.createElement('div');
581593
div.innerHTML = res;
582594
document.body.appendChild(div);
@@ -4314,9 +4326,16 @@ MathBox.Materials.prototype = {
43144326
});
43154327

43164328
if (type == 'uniforms') {
4329+
var uniforms = material.uniforms;
43174330
if (options.map !== undefined) {
4318-
if (material.uniforms.texture) {
4319-
material.uniforms.texture.value = options.map;
4331+
if (uniforms.texture) {
4332+
uniforms.texture.value = options.map;
4333+
}
4334+
if (uniforms.offsetRepeat) {
4335+
var offset = options.map.offset;
4336+
var repeat = options.map.repeat;
4337+
4338+
uniforms.offsetRepeat.value.set(offset.x, offset.y, repeat.x, repeat.y);
43204339
}
43214340
}
43224341
if (options.lineWidth !== undefined) {

0 commit comments

Comments
 (0)