Customise scaling of height and width
See original GitHub issueHi, I was wondering if we can do customise scaling of the height and width for the 3d model indivdually, i have tried adding threefingermove and fourfingermove for customising the width and height respectively. However, it seems like not working due to the scaling calculation for the change of model size.
This is the part for the init:
init: function () {
this.customScaleHorizontal = this.customScaleHorizontal.bind(this);
this.customScaleVertical = this.customScaleVertical.bind(this);
this.handleScale = this.handleScale.bind(this);
this.handleRotation = this.handleRotation.bind(this);
this.initialScale = this.el.object3D.scale.clone();
this.scaleFactor = 1;
},
This is the part for updating the eventlistener:
update: function () {
if (this.data.enabled) {
this.el.sceneEl.addEventListener("onefingermove", this.handleRotation);
this.el.sceneEl.addEventListener("twofingermove", this.handleScale);
this.el.sceneEl.addEventListener("threefingermove", this.customScaleHorizontal);
this.el.sceneEl.addEventListener("fourfingermove",this.customScaleVertical);
} else {
this.el.sceneEl.removeEventListener("onefingermove", this.handleRotation);
this.el.sceneEl.removeEventListener("twofingermove", this.handleScale);
this.el.sceneEl.removeEventListener("threefingermove", this.customScaleHorizontal);
this.el.sceneEl.removeEventListener("fourfingermove", this.customScaleVertical);
}
},
This is the part for removing the eventlistener:
remove: function () {
this.el.sceneEl.removeEventListener("onefingermove", this.handleRotation);
this.el.sceneEl.removeEventListener("twofingermove", this.handleScale);
this.el.sceneEl.removeEventListener("threefingermove", this.customScaleHorizontal);
this.el.sceneEl.removeEventListener("fourfingermove", this.customScaleVertical);
},
This is the part for customizing the width:
customScaleHorizontal: function (event) {
this.scaleFactor *=
1 + event.detail.spreadChange / event.detail.startSpread;
this.scaleFactor = Math.min(
Math.max(this.scaleFactor, this.data.minScale),
this.data.maxScale
);
this.el.object3D.scale.x = this.scaleFactor * this.initialScale.x;
this.el.object3D.scale.y = this.el.object3D.scale.y;
this.el.object3D.scale.z = this.el.object3D.scale.z;
},
This is the part for customizing the height:
customScaleVertical: function (event) {
this.scaleFactor *=
1 + event.detail.spreadChange / event.detail.startSpread;
this.scaleFactor = Math.min(
Math.max(this.scaleFactor, this.data.minScale),
this.data.maxScale
);
this.el.object3D.scale.x = this.el.object3D.scale.x;
this.el.object3D.scale.y = this.scaleFactor * this.initialScale.y;
this.el.object3D.scale.z = this.el.object3D.scale.z;
},
And this is the only part i have changed for gesture-detector part:
getEventPrefix(touchCount) {
const numberNames = ["one", "two", "three", "four"];
return numberNames[Math.min(touchCount, 4) - 1];
}
I’m not sure whether is my logic wrong or what, please help me. Thank you!
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Scale a worksheet - Microsoft Support
In the Scale to Fit group, in the Width box, select 1 page, and in the Height box, select Automatic. Columns will now...
Read more >scale - CSS-Tricks
Get started with $200 in free credit! The scale property in CSS resizes an element's width and height in proportion. So, if we...
Read more >Set Custom Image Thresholds for Width and Height
So if you have an image that is taller than it is wide, it is going to scale down to a size that...
Read more >Custom Width and Height | WordPress.org
Since by simply scaling down the content according to the width, you can not really achieve good responsive results. Of course, if you...
Read more >Resolution Scale Calculator
Enter the original resolution width and height of your object, i.e., 1920 x 1080. Input the percentage by which you want to scale...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You are calculating the current value of x correctly:
this.el.object3D.scale.x
. Could you try adding the scale factor instead of multiplying it? At least this whay it will always increase x by the same value on each iteration. I’m not sure how good it will be but worth trying 😃Other option could be reducing the impact of finger movement on the scale factor, which could be different depending on how many fingers you use for the gesture event. Something like
this.scaleFactor *= 1 + (event.detail.spreadChange/event.detail.startSpread) * 0.5;
.I think the issue with using the current x value is that if we multiply it by some factor, it will increase or decrease too fast since gesture events are too sensitive and could run multiple times for a single touch.
Finally, just in case you want to dig deeper, in three.js scale is a Vector3, so you have acces to all this properties/functions: https://threejs.org/docs/#api/en/math/Vector3
Hope this helps!
This one: https://modelviewer.dev/
Hope it helps