Dynamic tiling -> effect of 'no stretch' despite scaling

I want to make an effect of a wood pattern starting at the same point and redardless of dynamic scaling, the texture restrains from stretching … no matter what.

Project: PlayCanvas | HTML5 Game Engine

As such I;

  1. need to control the absolute starting point of the texture-upon-the-object
  2. need to know how much the texture needs to be scaled on the U/V coordinates in relation to fit the ‘rendered result’ texture.

A nice place to start regarding the scale, would be to use Math.pow(getScaler, 2), where getScaler is my top scaling entity in the heirarchy.

Here is my code:


var ScaleChecker = pc.createScript('scaleChecker');

// initialize code called once per entity

ScaleChecker.prototype.initialize = function() {

this.gser = this.app.root.findByName("Scaler");

};

// update code called every frame

ScaleChecker.prototype.update = function(dt) {

var getScaler = this.gser.getLocalScale().x; //console.log("gs; "+getScaler);

var power = Math.pow(getScaler,2);

var box=this.app.root.findByName("FuldPlanke");

box.render.material.diffuseMapOffset=new pc.Vec2(power,0.1);

box.render.material.update();

console.log("gs; "+power);

var box2=this.app.root.findByName("FuldPlanke2");

box2.render.material.diffuseMapOffset=new pc.Vec2(1.5/getScaler,1.5);

box2.render.material.update();

var box3=this.app.root.findByName("FuldPlanke3");

box3.render.material.diffuseMapOffset=new pc.Vec2(6.5,6.5/getScaler);

box3.render.material.update();

};

Video of dynamic scaling, where scaling works ‘consoled’ but does not update correctly:

Hi @Thomas_Due_Nielsen,

Not sure if I follow your logic, your example project throws an error (temper not defined) when running it. Does tiling work, but not as expected or doesn’t work at all?

my bad - went back to it and I am now debugging myself anyway :frowning:

[hvae now made a scaleChecker2 script, that I play with in another scene]

ps: please refresh; as the original ‘scaleChecker’ should work again
pps: I have at least discovered that I had to use ‘maptiling’ and not ‘mapOffset’

Here are my tries (and as close as it gets for me right now) { the tries: if interest the outcommented}

var ScaleChecker2 = pc.createScript('scaleChecker2');

// initialize code called once per entity

ScaleChecker2.prototype.initialize = function() {

this.gser = this.app.root.findByName("Scaler");

};

// update code called every frame

ScaleChecker2.prototype.update = function(dt) {

var getScaler = this.gser.getLocalScale().x; //console.log("gs; "+getScaler);

var power =Math.pow(getScaler,0.75); //Math.sqrt(getScaler)*1.23;///2;// Math.pow(getScaler,1);

if(power>1){power= 2-power;}

var box=this.app.root.findByName("FuldPlanke");

box.render.material.diffuseMapTiling.x =getScaler; var tmper =box.render.material.diffuseMapTiling.x/2;// Math.abs(1-(box.render.material.diffuseMapTiling.x -(box.render.material.diffuseMapTiling.x/2))); //Math.floor(box.render.material.diffuseMapTiling.x)));

//tmper=box.render.material.diffuseMapTiling.x-0.5;

box.render.material.diffuseMapOffset = new pc.Vec2(-power, 0);

box.render.material.update();

console.log("tiling: "+box.render.material.diffuseMapTiling.x+" gs; "+power);

var box2=this.app.root.findByName("FuldPlanke2");

box2.render.material.diffuseMapTiling.x =power;

box2.render.material.update();

var box3=this.app.root.findByName("FuldPlanke3");

box3.render.material.diffuseMapOffset=new pc.Vec2(6.5,6.5/getScaler);

box3.render.material.update();

};