Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions src/systems/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var registerSystem = require('../core/system').registerSystem;
var THREE = require('../lib/three');
var utils = require('../utils/');
var isHLS = require('../utils/material').isHLS;
var setTextureProperties = require('../utils/material').setTextureProperties;

var bind = utils.bind;
var debug = utils.debug;
Expand Down Expand Up @@ -317,37 +318,6 @@ function loadImageTexture (src, data) {
}
}

/**
* Set texture properties such as repeat and offset.
*
* @param {object} data - With keys like `repeat`.
*/
function setTextureProperties (texture, data) {
var offset = data.offset || {x: 0, y: 0};
var repeat = data.repeat || {x: 1, y: 1};
var npot = data.npot || false;

// To support NPOT textures, wrap must be ClampToEdge (not Repeat),
// and filters must not use mipmaps (i.e. Nearest or Linear).
if (npot) {
texture.wrapS = THREE.ClampToEdgeWrapping;
texture.wrapT = THREE.ClampToEdgeWrapping;
texture.magFilter = THREE.LinearFilter;
texture.minFilter = THREE.LinearFilter;
}

// Don't bother setting repeat if it is 1/1. Power-of-two is required to repeat.
if (repeat.x !== 1 || repeat.y !== 1) {
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(repeat.x, repeat.y);
}
// Don't bother setting offset if it is 0/0.
if (offset.x !== 0 || offset.y !== 0) {
texture.offset.set(offset.x, offset.y);
}
}

/**
* Create video element to be used as a texture.
*
Expand Down
34 changes: 34 additions & 0 deletions src/utils/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@ var COLOR_MAPS = new Set([
'specularMap'
]);

/**
* Set texture properties such as repeat and offset.
*
* @param {object} data - With keys like `repeat`.
*/
function setTextureProperties (texture, data) {
var offset = data.offset || {x: 0, y: 0};
var repeat = data.repeat || {x: 1, y: 1};
var npot = data.npot || false;
// To support NPOT textures, wrap must be ClampToEdge (not Repeat),
// and filters must not use mipmaps (i.e. Nearest or Linear).
if (npot) {
texture.wrapS = THREE.ClampToEdgeWrapping;
texture.wrapT = THREE.ClampToEdgeWrapping;
texture.magFilter = THREE.LinearFilter;
texture.minFilter = THREE.LinearFilter;
}

// Don't bother setting repeat if it is 1/1. Power-of-two is required to repeat.
if (repeat.x !== 1 || repeat.y !== 1) {
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(repeat.x, repeat.y);
}
// Don't bother setting offset if it is 0/0.
if (offset.x !== 0 || offset.y !== 0) {
texture.offset.set(offset.x, offset.y);
}
}
module.exports.setTextureProperties = setTextureProperties;

/**
* Update `material` texture property (usually but not always `map`)
* from `data` property (usually but not always `src`)
Expand Down Expand Up @@ -118,6 +149,9 @@ module.exports.updateDistortionMap = function (longType, shader, data) {
if (texture && COLOR_MAPS.has(slot)) {
rendererSystem.applyColorCorrection(texture);
}
if (texture) {
setTextureProperties(texture, data);
}
material.needsUpdate = true;
handleTextureEvents(el, texture);
}
Expand Down