Tagged: snap to grid
- This topic has 10 replies, 4 voices, and was last updated 3 years, 9 months ago by Petro.
-
AuthorPosts
-
2020-06-10 at 6:08 am #28609GLiFTeKCustomer
Hi,
I’m just brainstorming the best way to have my draggable object “Snap” to a grid.Was first inclined to have a grid of empties, put them in a list, and loop through to find whichever is closest to the dragged object,(besides the previous location’s empty) then snap to its coords.
Is there a less complex method of doing this anyone might know of, possibly with a short equation?
Thanks!
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2020-06-11 at 7:22 am #28684GLiFTeKCustomerWell the array of empties was way too large of a list (1000+) to loop through every frame…
I’m tracking the dragged object’s coords, comparing them to its previous position coords.
If if that difference between those 2 x/y coords land within a buffer value k area +/- around the next virtual grid space, then the dragged object snaps to those coords.
Wish I retained all that trigonometry grin school. Probably would be simpler using x/y vector comparisons with those new numbers puzzles features.
Gonna try to drag a “ghost” empty that gets resolved to tell the stationary object to snap…
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2020-06-11 at 10:21 am #28710GLiFTeKCustomerconclusion:
meh.. screw all that noise..just found a JS script that did the job.
did it once on the X once on the Y. job done.snapToGrip = function(val,gridSize){ var snap_candidate = gridSize * Math.round(val/gridSize); if (Math.abs(val-snap_candidate) < 2) { return snap_candidate; } else { return null; } };
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2020-06-11 at 12:19 pm #28716Mikhail LuzyaninStaffYes, it’s a good way. I think this can be implemented with puzzles, but I’ve failed to do this few times then leave this attempts .
Co-founder and lead graphics specialist at Soft8Soft.
2020-06-11 at 7:23 pm #28745GLiFTeKCustomerit works great. can scale the gridSize var too.
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2020-06-15 at 12:31 pm #28850yasseCustomerHello dear GlifTek.
I Hope you doing good :) please i have been playing with the snap to grid function but it didn’t worked as it was supposed to be, but I’m wondering if it worked for you ?
please could you check the screenshot of the execution which certainly a mistake I have made,
thank you so much :)
2020-06-16 at 6:25 am #28868GLiFTeKCustomerHello dear GlifTek.
I Hope you doing good please i have been playing with the snap to grid function but it didn’t worked as it was supposed to be, but I’m wondering if it worked for you ?
please could you check the screenshot of the execution which certainly a mistake I have made,
thank you so muchHi Yasse.
First thing is that your JS Call puzzle should go AFTER your move puzzle, because it’s snapping your object to what info you give it, which would be the coords it gets after you dragged something, which i’ll show here…
So here’s what my basic setup is:
This is taking the x and y coordinates of your dragged object and then processing them through the script according to your grid size and whether snapping is on/off. (holding down the “z” key. (maybe make it a different key since that messes with undo sometimes)My puzzles are like this:
And I’m using this in the (yourApp).js file’s prepareExternalInterface portion:
app.ExternalInterface.snapToGrid = function(val,gridSize){ var snap_candidate = gridSize * Math.round(val/gridSize); if (Math.abs(val-snap_candidate) < 2) { return snap_candidate; } else { return null; } };
Where I got that script from was using “griP” with a “p” so i made it a “d”. (you still have that “p” and that might cause unseen issues if you use “d” in the JS Call puzzle’s name, which you didn’t but I am, so just pointing that out.)
Note that i just copied the puzzles over to a different part of my screen to show you their basic arrangement, not all intertwined into my project, so they may be a bit more understandable, directly copying them may not work per your 3d app file etc.. but it’s a basic layout.
I found I had to use ’round’ twice, though i most likely will go over that and find away to make it back to only once. (was issues with how fast the user would interact)
I’ll post a zip file in tutorials with it all setup and working in it’s own app folder for people to make their own changes on in a few days, with some other very useful “database query”, “print to console toggle” and “dictionary factory” puzzle setups I’ve been meaning to share.
I hope this helps!
-GlifTekVisit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2020-06-16 at 6:34 am #28869GLiFTeKCustomeri’m not gonna dare edit that post because it might get erased.
so EDIT: also, you’d just put your own object in the “when dragged over” and “drag move” puzzles,
then the get x/y position puzzles
and the set position puzzle in the other bottom procedures.when i post the zip in tutorials it will all be simplified. just thought i’d get back to you on this quick so you can move forward.
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2021-01-15 at 4:32 pm #37423PetroCustomerHi GlifTek. Thank you for sharing. Did you post the zip file you mentioned ?
2021-01-15 at 10:51 pm #37426GLiFTeKCustomerHi GlifTek. Thank you for sharing. Did you post the zip file you mentioned ?
Hmm that was awhile ago.
Can’t find that specific zip..
Should have posted it back then, but got sidetracked with other work.However, I’m making it into a custom puzzle for sale I’ll be premiering in a few days.
In the meantime, what part of the script are you having trouble with? Maybe I can help you to get it to work.
(Try using it in Ann exec script puzzle?)EDIT: odd that my puzzles image above is going. Maybe I can find that.
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2021-02-08 at 2:08 pm #38204PetroCustomer:) I did manage to make work many aspects… I am configuring furniture objects in a kitchen by dragging them… The most annoying part is it sometimes you need to insist to touch the wall edge with the dragging. I am thinking of a way to place as you suggested somewhere else some invisible spots on the floor where the object can be placed. Thx
-
AuthorPosts
- You must be logged in to reply to this topic.