Skip to content

Commit dd5fe5d

Browse files
authored
Added default uv clip
1 parent cd465fa commit dd5fe5d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/ModelViewer.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function ModelViewer(container) {
7070
// append viewer
7171

7272
this.element.appendChild(this.renderer.domElement)
73-
73+
7474

7575
// view methods
7676

@@ -350,7 +350,14 @@ function ModelViewer(container) {
350350
* JsonModel
351351
*****************************/
352352

353-
function JsonModel(name, rawModel, texturesReference) {
353+
function JsonModel(name, rawModel, texturesReference, clipUVs) {
354+
355+
356+
// set default clip value to true
357+
358+
if (clipUVs === undefined) {
359+
clipUVs = true
360+
}
354361

355362

356363
// parent constructor
@@ -694,8 +701,21 @@ function JsonModel(name, rawModel, texturesReference) {
694701

695702

696703
// check
697-
698-
uv.forEach(function(e, pos) {if (typeof e != 'number' || e + 0.00001 < 0 || e - 0.00001 > 16) throw new Error('The "uv" property for "' + face + '" face in element "' + index + '" is invalid (got "' + e + '" at index "' + pos + '").')})
704+
705+
if (clipUVs) {
706+
uv.forEach(function(e, pos) {if (typeof e != 'number') throw new Error('The "uv" property for "' + face + '" face in element "' + index + '" is invalid (got "' + e + '" at index "' + pos + '").')})
707+
uv.map(function(e) {
708+
if (e + 0.00001 < 0) {
709+
return 0
710+
} else if (e - 0.00001 > 16) {
711+
return 16
712+
} else {
713+
return e
714+
}
715+
})
716+
} else {
717+
uv.forEach(function(e, pos) {if (typeof e != 'number' || e + 0.00001 < 0 || e - 0.00001 > 16) throw new Error('The "uv" property for "' + face + '" face in element "' + index + '" is invalid (got "' + e + '" at index "' + pos + '").')})
718+
}
699719

700720
uv = uv.map(function(e) {return e/16})
701721

0 commit comments

Comments
 (0)