Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / cut or slice objects into parts

Author
Message
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 11th Aug 2018 12:18 Edited at: 11th Aug 2018 12:29
how would i go about cutting an object into parts?
say i wanted to slice a box in 2 based on where it was hit by a sword for example, what would be the easiest method to do so?

i'm thinking something like this
- create a box (we'll call it box A)
- hit the box
- determine where the box is hit
- create 2 new boxes (box B and box C)
- resize box B and C depending on the location of the hit to box A and to match the size of box A when combined
- delete box A

this is what i have so far (p.s. tier 1 please)


this will only work for straight cuts though and i'm unsure how to determine which axis the cut should be applied (or if this matters?)
so my question is.... is there a better way that works more reliably?
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 12th Aug 2018 22:23
Wow, that's a tough ask. There was that one fame that did it, and on paper it looked super impressive......but actually there was only a limited number of cuttable objects. Still mega impressive though.

To do this I think your into memblock territory.....you'd also need to set the same texture for each of the two boxes, but also set the UV coords for both as well to display the correct part of the texture. Not impossible, but far from easy, and more complex shapes would be a nightmare as you'd have to forcibly add new planes across some solid parts.
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 13th Aug 2018 01:09 Edited at: 13th Aug 2018 03:57
I think this was called CSG operation back in DBP times and was some sort of awesome.
I think your best run would be to create pre-sliced objects, as AppGameKit does not support fast mesh cutting operations.
Doing it in Memblocks would work somehow, but still too slow for real-time use. Maybe a combination would work best.
Pre-sliced objects based on a mesh memblock algorythm.

I am looking forward this, because it would enable binary space partitioning.

Greetings, Jack

[/url]
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 13th Aug 2018 01:47 Edited at: 13th Aug 2018 01:48
I do this for my tree animations. I created the 3d object. Split it into two objects that were not connected added an armature and animated it.



StabintheDark also has done some very cool stuff using his physics engine. You might want to search the forums.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 13th Aug 2018 11:03
I only plan to use this for simple objects / shapes such as cubes and cylinders and the textures would be nice and simple so I won't have to worry about the missing texture.

I will look into memblocks and see if I can get a cube to cut like my example, hopefully they will hold the answer to doing non-straight cuts.

There will only be 1 (maybe 2) cuts made at a time so I think agk can handle it (PC only)

I don't think it'll work with animation as I would not be able to determine where the cut would be in advance... Too many possible outcomes to predetermine even in a cube but the idea of set shapes made in advance could work as a backup plan and will work to some extent (just not quite as impressive)
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 13th Aug 2018 14:54
ok had a play with memblocks and i'm not getting it...
as memblocks are made up of 3 points (to make a poly or triangle) i figured the best method would be to find the vertex that is closest to the mouse click location and then move that...
i think my theory is ok but i'm missing something or it's just not quite correct... i think the angle of the objects aren't being accounted for?
anyone with better understanding of the maths involved can help point out what is wrong please?

life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Aug 2018 18:41
It's possible to do boolean operations with memblocks. It would require adding/removing vertices after determining where the other object's polygons intersect. Off the top of my head, the hardest part I think would be keeping the proper order of the new verts.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
puzzler2018
User Banned
Posted: 13th Aug 2018 18:57 Edited at: 13th Aug 2018 19:07
The construction in memblocks for a cube is

3 x points to make a triangle and 3 x points to make another - building a face x 6 faces

so should be quiet easy to chop a cube in have, by adding two faces to the intersection point one face to close one cube and one face to close the othe cube next to it.

Cylinders on the other hand are more cumbersome - the are structured by 2 cones and faces that join the two cones together - to chop a cylinder in have.

I think you will have to construct the cylinder a different way instead of AGKs version and not to use the cones. but having

1 face for the top - say constructed with 8 edges and the triangle points meet in the centre in a circle
1 face for the other size (length of the cylinder) - - say constructed with 8 edges and the triangle points meet in the centre in a circle

- multiple of faces that join the top and bottom on the 8 edges according to the length of the cylinder - then find the intersection point of where the mouse is and add a top and bottom face to that location one to the top cylinder and one to the
bottom makeshift cylinder

Thats my theory anyway.

I ll have a go at something this week along these lines
puzzler2018
User Banned
Posted: 13th Aug 2018 20:09
For example

Contstruct two planes for top and bottom (cylinder.png) attached

Seperate these two for the length of the cylinder

Join the two seperated triangle meshs together with 6 rectangles - similar to cylinder2.png (also attached)

Attachments

Login to view attachments
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 14th Aug 2018 12:39
thanks guys but currently i'm struggling with the fact it doesn't return the expected vertex, i didn't realise you can't see my mouse in the previous video so i didn't really explain that very well, sorry about that, i've been playing around with it again today but still not getting it, uploaded a new video to better see the problem though
i found the issue is that the memblock isn't getting the new positions if i rotate the box, i (re)create the memblock each time an object is clicked but it appears it is still using the original location or perhaps it simply ignores rotation?
i assume i'm doing something wrong but i can't see what it is...




i will get to the cutting part after i figure out the above issue
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
puzzler2018
User Banned
Posted: 14th Aug 2018 12:56 Edited at: 14th Aug 2018 13:00
Im confused on your goal.

Do you want to simply chop objects in half to then multiply them at a certain intersection point of where the mouse is? cause you could simply SetObjectSize on the object to the point of intersection and create an instance of it to "double" the object?

or do you want chop little chunks out of it when you click anywhere on them? this is memblock work.


But if you cut the object when the object is rotated at some odd angle - then it will look and feel better if cut it at that angle.


Could you please advise.

Which ever the case, i think this will be a very tough one to tackle. But please don't give in...
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 14th Aug 2018 13:40 Edited at: 14th Aug 2018 13:42
the end goal is to cut the object into 2
i.e. or do you want chop little chunks out of it when you click anywhere on them? this is memblock work.
but it won't technically be when clicked, i will swipe through the object eventually, the clicking is only for testing the initial impact - i assume i can just do the same at the point of last impact to get the exit point and then work out the new face from the 2 combined

and yh the method of simply replacing the object into 2 objects is how i did it originally (see first post) but that only works for straight cuts, not odd shapes (such as cutting a box in a diagonal which isn't from the corners etc).
i'm currently just trying to figure out how to determine the nearest vertex because we will need that to determine where to join the newly created point (from the cut point given at point of impact) to, right?

either way the nearest vertex is only being returned correctly if the object is in it's original rotation but not if we rotate the object.

but if you have a better method then please feel free to correct me, i'm completely new to this and rather lost in the depths
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
puzzler2018
User Banned
Posted: 14th Aug 2018 19:14 Edited at: 14th Aug 2018 19:14
Wow - thats what I thought - my brother is a games player since he was about 5 too in his later 30s now, so quiet a lot of years and he hasnt ever seen a game that does this.

There are games out there which has certain object breaks in them, but not a very very precise method to split an object in 2 regarding the angle hitting it at etc

This will be one of its kind if we can master this cause no one has ever been able to accumplish this, not even the more experienced game industry developers.

Like said, dont stop till we get there with this one..
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 14th Aug 2018 20:14
it's certainly rare but it has been done

life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
puzzler2018
User Banned
Posted: 14th Aug 2018 20:18
Some very cool examples - its rare because of the difficulty to do..

I would say out of 100 that the difficulty to acheive this is super advanced and 99 out of 100 to achieve.

But once achieve it and worked it out then im sure you could work at Rockstar

Im still pondering on the idea still lol

puzzler2018
User Banned
Posted: 14th Aug 2018 20:28 Edited at: 14th Aug 2018 20:30
It certainly will be achievable, but not this minute though - cause its a very tough one, but please dont give up hope in achieving it.

Ill certainly have this in mind and once i can figure it out the best course for this then will give you a nudge.

Like Santman and various others suggest - its a quiet challenging puzzle for proramming.

Cause it could help minecraft of a new technique to chopping blocks up or trees down.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 14th Aug 2018 21:58
A 3D object is just a bunch of points interconnected by a bunch of line segments. It would seem to me that all you need to do is iterate over all the segments of the 3D object and test if each segment is intersected by a plane. If it does intersect, get the point of intersection. Since the intention is to bifurcate the object, you could maybe create a box on one side of the cutting plane to encompass a portion of the object. Then, you can iterate over all the vertexes and test if they are within the box. Only the vertexes in the box goes to a new memblock. The rest go into another new memblock.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 14th Aug 2018 22:05
Those examples are a different problem... Fruit Ninja is 2d I think and uses sprites. I have seen many tutorials in Unity and others about how to make your own FN style game. The other one looks like it is a "canned" fx simply spawning the appropriate new models after the original has been sliced.

Odds are though this has been covered in other game engines / frameworks most things have by this point. So a look at those might be helpful.
puzzler2018
User Banned
Posted: 14th Aug 2018 22:08 Edited at: 14th Aug 2018 22:12
no. they are based on triangles points - 3 points makeof a triangle and 3 to make the other half to make that cube face. So if you click at one point, ok we may find that vertice. but destroying just that vertice will mess up that triangle - which is causing the effects your experiencing.


we need to like phealax says - have something to remember vertices

but what we do with those remembered vertices - begs the questiion
puzzler2018
User Banned
Posted: 14th Aug 2018 22:20
If you can figure it out before anyone else - then patent the code lol cause seriously its magical
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 14th Aug 2018 23:12
fruit ninja vr is 3D, 2D in VR wouldnt work, though yes the original game is 2D and of course this would be far simpler with 2D images
beat saber definitely doesn't use pre-made assets or fx to hide the new shapes - if you slow down the video you can see the cuts are matching the swipes - i.e. not straight cuts etc.

Quote: "Since the intention is to bifurcate the object, you could maybe create a box on one side of the cutting plane to encompass a portion of the object. Then, you can iterate over all the vertexes and test if they are within the box. Only the vertexes in the box goes to a new memblock. The rest go into another new memblock."

a solid plan, thanks but it still doesn't answer why the memblock doesn't take the rotation of the objects into account - i guess it wouldn't matter for a game like beat saber where the boxes are fixed rotation but it wouldn't work for fruit ninja where the fruit can rotate freely.


Quote: "no. they are based on triangles points - 3 points makeof a triangle and 3 to make the other half to make that cube face. So if you click at one point, ok we may find that vertice. but destroying just that vertice will mess up that triangle - which is causing the effects your experiencing."

i understand that but the problem i have is that it is still believing the vertex are in the shapes 0,0,0 rotation rather than it's current rotation, it's hard to explain but in the last video it is always selecting vertex 0 when i click the top left, regardless of the boxes rotation because the data in the memblock is treating the box as being at 0,0,0 rotation .

reading your replies and i just remembered we can fix the object's rotation with FixObjectPivot, then if i recreate the memblock it will hopefully give the correct vertex data.... this may well be the answer i'm looking for, i'll test it tomorrow, don't worry, i'll continue to share my findings
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
puzzler2018
User Banned
Posted: 14th Aug 2018 23:16
Forget rotation for a minute - you need to understand how cubes and others are constructed - i think your bypassing me.

good luck with this project
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 15th Aug 2018 01:16 Edited at: 15th Aug 2018 04:40
Quote: "it still doesn't answer why the memblock doesn't take the rotation of the objects into account"


It could be that the memblock only handles the raw object data and the AppGameKit physics engine handles rotation. You may need to create an array of points and then rotate them to match the object's vertex positions. Although, this sounds like it would be way to slow for real time use but maybe not.
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 15th Aug 2018 08:35 Edited at: 15th Aug 2018 10:16
Raiden's solo Metal Gear Solid outing did actual real-time boolean operations. \



This was the huge selling point for the game, the trailer was literally a demo of Raiden cutting up watermelons. In any other game, they create pre-sliced objects which replace the whole object when sliced. This is the recommended method of slicing 3d objects, obviously to save on memory and GPU usage.

In this case you'd want to look into A not B + AB Intersection Boolean operation. There's basically 6 steps involved,

1) search for intersected triangle-pairs(octree search algorithm)
2) calculate intersection line for each pair(moller-trumbore intersection algorithm)
3) merge and update surface meshes(basically make a new mesh with all combined vertices+renumbered)
4) create intersection loops(basically connect into closed or open loops from step 2)
5) create sub-surfaces(based on closed loops and all triangles within)(each sub-surface can be used to create your desired output shape, based on the type of boolean operation)
6) assemble sub-blocks based on boolean type wanted(using closed loops from step 4)

Ehhhh, tried to summarize a bit of the process, seems complicated but after reading over my Game Developer Guru book and a couple articles on the subject, it might not be that difficult to implement. Think I'll look into this some more, maybe have a go at it in AGK.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 15th Aug 2018 10:10
Quote: "Forget rotation for a minute - you need to understand how cubes and others are constructed - i think your bypassing me.
good luck with this project"

not at all, merely pointing out that without fixing the rotation issue i would be cutting blindly, i didn't want to move on to the cutting part until i knew for sure it was possible to get the desired location otherwise cutting the objects would be pointless as it wouldn't suit my needs,

good news is that fixing the pivot does indeed fix the issue so now i can move on to improving the cutting method - i expect this part is going to get super confusing



Quote: " In any other game, they create pre-sliced objects which replace the whole object when sliced"

this would work very nicely for spheres and is actually very simple for them - you simply place the hidden spheres at the target sphere location and then rotate the half (cut) spheres to match the direction of the swipe (/cut) to fake the cut being at the correct angle - though of course it makes all cuts look like a clean cut in half it is fine for most uses... for other shapes it will be much less effective due to the different combination of possible outcome shapes.
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 15th Aug 2018 11:41
Do you need a solid face on the side you are cutting or can you use my clipping shader from the shader pack ?
I know it seven posible to render a solid face on the cutting side but i dont have that in place yet.
P.s. I made a 2D slicing game: Slice Wise
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 15th Aug 2018 12:57
making progress - i think - completely destroys/corrupts the other shapes but it works pretty well for the cubes at least - i'm happy with that



that's all for today
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 15th Aug 2018 13:19
https://youtu.be/cL-sjNZ7Bbw

Puzzler......it's been done and well.

Keep at it smallg, making awesome progress.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 15th Aug 2018 13:50 Edited at: 15th Aug 2018 13:59
ok i lied, 1 more quick fix to allow it to work on all 3 objects - i just didn't take into account the world offset of the objects when repositioning the vertexes
certainly not going to match the impressive style of MGS there but i'm pleased with the result considering it's completely new to me, now i just need to figure out if i can limit the stretching when you slice quickly

life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
puzzler2018
User Banned
Posted: 15th Aug 2018 20:52
Well done
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 15th Aug 2018 23:19 Edited at: 15th Aug 2018 23:25
Save object data in human readable form. Takes a memblock id and the name of the file to save as. I'm still pretty green when it comes to the 3d side of AGK. Wrote this to help me understand mesh memblocks. I think it's correct. I don't really know lol.




It's formatted like this:
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 16th Aug 2018 13:06 Edited at: 16th Aug 2018 13:07
I have no idea how this work, but cool it is!

What are you planning on doing with this? I could see lots of great use for it in VR

smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 16th Aug 2018 14:18
Quote: "I have no idea how this work, but cool it is!
What are you planning on doing with this? I could see lots of great use for it in VR"

my method works by;
1.detecting if an object has been hit via raycast
2. creating 5 cut locations - initial cut impact (the first point the raycast returns true), last cut impact (constantly updated until the raycast returns false again) and then 3 points spread between those points based on the distance (i.e. 25%, 50% and 75%) - assuming a straight cut through the object this basically just plots 5 points along the blades path
3. check which direction the cut is going based on the position of the blade when it impacted the object vs when it stopped impacting the object
4. going through the objects vertex positions (via the created memblock) and comparing them to each of the cut locations and determining which is closest
5. depending on the direction of the cut we move the vertex to the location of the closest cut point - but only if it is to a specific side of the object (i.e. if cutting straight down we move the points left of the cut point to the right for creating 1 object and points on the right to left when creating the other object)
note: the above is not 100% accurate in my code as i only really need it for when i am in front of the objects, if you stand to the side (so you're looking at the side of the objects) the cuts are incorrect
6. the rest is just deleting the original object and creating the 2 new ones based on the memblock data we just adjusted

note2: it doesn't work well for complex shapes such as humanoid shapes unless you cut entire limbs (i.e. chop the head off)

i'm sure it could be done better and maybe somebody will be interested enough to take this further but it works well enough for me to play with it

and yep, currently working on a VR title similar to fruit ninja and beat saber combined - i.e. slicing objects to the rhythm of music, will share in the showcase when i have something to share
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 16th Aug 2018 17:45
for anyone playing along at home the VR version is in the works
https://forum.thegamecreators.com/thread/222789
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Arbrakan
14
Years of Service
User Offline
Joined: 10th Oct 2010
Location: Geneva
Posted: 17th Aug 2018 11:34
Very nice !
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 20th Aug 2018 06:42
Great stuff!!!
fubar

Login to post a reply

Server time is: 2024-11-23 18:00:38
Your offset time is: 2024-11-23 18:00:38