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;
- need to control the absolute starting point of the texture-upon-the-object
- 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: