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.

DarkBASIC Professional Discussion / Splitting 1 object into 2 along a plane

Author
Message
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 26th Mar 2011 16:49 Edited at: 26th Mar 2011 17:15
I'm working on a technique that splits an object into 2 objects along an imaginary plane. To do this I would take the object and call up a function that takes 10 parameters, the first is the object number, the last 9 are the points that make up the plane that intersects the object. At the key points of intersection, 2 sets vertices are created, half of them for one side of the split, half for the other. Then faces are created to make the new halves solid on both ends. Then a random number multiplied by some factor is applied to the new pairs of vertices giving a jagged edge. After that, one half forms a new object to result in a broken in half object.
Now I need help first of all with the vertex commands, i have never used them before. Although I have experience with memblocks. So which one is better for this task?
Also I need help with Calculating major intersection points. Should I just calculate them where the plane intersects and edge? This gets into plane-line intersection which I do not know much about.

IBOL
Retired Moderator
22
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 26th Mar 2011 21:48
Quote: "Spiting 1 object into 2 along a plane"

we would be happy to spite that object for you!

Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 26th Mar 2011 21:54 Edited at: 26th Mar 2011 21:58
I think he meant "spritz" the object.





Sorry, Madscientist, I couldn't resist. I have no idea how to do what you ask. I've played around with the csg commands, but I don't think they quite cover what you are trying to do.

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 26th Mar 2011 23:43 Edited at: 26th Mar 2011 23:44
xD What I'd do is... well... first, I'd need to solve for the "edge loop" - all the points that belong both to the plane and the object (basically, all the points where the plane intersects an edge, with a special case if the whole edge lies on the plane)

Then, I'd need to construct two objects - one with data on one side of the plane (with the edge lines being the same as the edge loop) and another with data on another side of the plane (again, using the edge loop).

Now the data is separated. To fill the face of the polygon (formed by the edge loop), use an algorithm like this:
http://www.siggraph.org/education/materials/HyperGraph/scanline/outprims/polygon1.htm


So... It's a bit of a project xD
I'd be happy to help you with the math. But... in order to do this in any reasonable amount of time... I think you'd need some sort of optimization, like what's used in collision or physics plug-ins. Plus I'm not totally sure how you'd get the points in the right order...

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 27th Mar 2011 20:09 Edited at: 27th Mar 2011 20:18
Yeah, I know that its a lot (more like a ton). But I guess the first step is to solve the geometric part 1st. So I need to first be able to create a plane from 3 points and find the equation of that plane. Then find the vertices that are connected by an edge that are on both sides of the plane. Then find the equations of the lines of the edges that intersect the plane. After that, solve for that equation to get our new points.
ATM I am busy so when I get back I'll work on posting some basic code that I have so far.... I don't want you to think that I just want the answers and code literally handed to me.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 28th Mar 2011 02:59 Edited at: 28th Mar 2011 04:02
Update: I got a plane equation working! Got help from this video:
http://www.youtube.com/watch?v=0MECmEjR2WU&feature=related


Now I need help with creating an equation of a 3d line. Given 2 points in 3 dimensional space, how can I have an equation with x,y,and z multiplied by a factor to equal a number?

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 28th Mar 2011 05:29 Edited at: 28th Mar 2011 09:02
Very nice! Yeah, if you know vector algebra, the equation of a plane is easy.

[edit]sorry that the following post is horrible to look at! That's just due to lack of formatting/me being too lazy to type all the equations up and save/upload them as images[/edit]

This is because the dot product of two vectors has a special value:
A.B=Ax*Bx+Ay*By+Az*Bz=|A|*|B|*cos(θ[/b])

Where...
A.B is the dot product of vectors A and B
|A| is the length of vector A
Ax is the x component of vector A (etc.)
aand θ is the angle between the two vectors

So, if cos(θ[b]
)=0, then A.B=0. As we know, the cos(90°)=cos(-90°)=0, and a normal vector, by definition, is at a 90 degree angle to the rest of a plane.
Since this operation is defined about the origin (three points in the angle, A, B, and the origin), you need to pick a point and set it to be the origin (to do so, with P1, P2, and P3, you say a vector N is either N=P1, N=P2, or N=P3, and you take P1-N,P2-N,P3-N, so that you're left with two vectors and a zero vector)

Aaaaand then the cross product is used to find a vector that is perpendicular to the plane.

This is where I found what I believe to be an error in the code, though it works in this particular place:



you subtract x1 from x2, but then you subtract x2 from x3? In my head... I can't really come up with a visualization to why you would do it, and though it works in this case, I'm not sure that it works in every case (Errm, I don't particularly want to work through the math... xD)
I'd replace this line with one of these three:


Also, there's a typo in that video, in the top right of the board , for vector V. He says V=PR=(2-1,2-1,0-1)=(1,1,1). He meant V=PR=(2-1,2-1,0-(-1))=(1,1,1).

Sooo I hope that clears up any confusion you might have had. Basically what you're saying, is that given vectors A, B, and C, the equation of a plane perpendicular to those vectors, where N=(x,y,z) (the variables), ((B-A)x(C-A)).(N-A)=0 (Yknow, AxB is cross product, A.B is dot product)
(notice how vector notation sums everything up very nicely )


So... Now for the line. For a line from points A to B, I usually se a parametric line. Say you have vectors A and B, and you want to find a point that lies on that line, V. You can say
V=(B-A)*t+A
t is a scalar number (meaning NOT a vector). As you can see, if T=0, then the equation becomes V=(B-A)*0+A=A. If T=1, then V=(B-A)+A=B. In other words - as t varies from 0 to 1, V varies from A to B.

So, tying everything together...

Vectors Q, W, and E, define a plane.
Vectors A and B define a line.
N is a variable vector, so N=(x,y,z).

We first say:
((W-Q)x(E-Q)).(N-Q)=0

And this defines N to lie on plane QWE

Next we say that, for any number t:
N=(B-A)*t+A

which defines N to lie on line AB. So, all points that satisfy the two vector equations:
N=(B-A)*t+A
((W-Q)x(E-Q)).(N-Q)=0

belong to both plane QWE and line AB. First thing's first: Solve for t. If 0<=t<=1, then the point of intersection of line AB and plane QWE is in between A and B. (Meaning it lies on the line segment in question).

Now, you can solve for T by solving the equation:
((W-Q)x(E-Q)).((B-A)*t+A-Q)=0

Notice... There is no inverse dot product. You actually do have to multiply everything out. (you don't have to multiply out the annoying cross product term, just say they're equal to some vector (d,e,f) or whatever)

So, it's an annoying equation to solve for. There are also indeterminant solutions for t. For example, if your line AB NEVER intersects with plane QWE, how can you solve for the point of intersection? Obviously you can't, and the equation returns an indeterminant answer (like 1/0).

So, summarizing everything above this post, the algorithm to find the intersection of a line AB and plane QWE, would go something like this:
(I just used - marks for tabs, because lack of indentation kills me xD)


pictionaryjr
17
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 28th Mar 2011 05:42
why would you need to do this. I'm just curious.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 28th Mar 2011 20:13 Edited at: 29th Mar 2011 04:23
With the whole X subtraction thing, It doesnt matter what the two coordinates are subtracted since it's just finding 2 vectors lying on the surface so any coordinates can be used.
Also I've pretty much tried learning about vectors just now since I haven't needed then until now. I havn't even gone over them yet in school. Which makes your explanation very hard for me to understand.
So anyways I also worked on an equation for figuring out the point on a line, its more of an algebraic equation.
Now for a line, we have the points X1,Y1,Z1 to X2,Y2,Z2 and the formula <X1,Y1,Z1>+FL*<X3,Y3,Z3>
where <X1,Y1,Z1> is the position vector of the first point, FL is the a factor of the line that is multiplied with the vector and the <X3,Y3,Z3> is the direction vector from x1,y1,z1 to x2,y2,z2.
This simplifies to the vector that lies on the plane
<X1+FL(X3),Y1+FL(Y3),Z1+FL(Z3)>
Now since this point lies on the plane it can be plugged into the plane equation
PFX(X1+FL(X3))+PFY(Y1+FL(Y3))+PFZ(Z1+FL(Z3))=PR
Where PFX,PFY, and PFZ are factors by which the point on the plane is multiplied by to equate to PR.
We have all values except for FL which once we solve for, finding the point on the line is easy.
So I took this equation and simplified it to
`````PR-(PFX(X1)+PFY(Y1)+PFZ(Z1))
FL`=`------------------------------
`````PFX(X3)+PFY(Y3)+PFZ(Z3)

Then using this you have FL to find the point of intersection with.

<X1+FL(X3),Y1+FL(Y3),Z1+FL(Z3)>

So that's how I choose to do it since thats as far as I figured out so far. But I'd also like to know how the method you posted works.

EDIT/UPDATE: Ok so I coded it in but came up with inexplicable results that were wrong.


And also @pictionaryjr
Its to make the entire environment in my game destructable, so say you have several trees blocking your view, just place a pack of C4 and problem solved.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 29th Mar 2011 19:40
Whoops, I just relized that I'm doing exactly what you said after reading your post several times
So i still cant figure out whats wrong with the equation...

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 30th Mar 2011 02:49 Edited at: 1st Apr 2011 23:39
:S So... I tried to write up the function... and it's not working. I have no idea why it's not working... Basically, a function calculates "t", and then I plug t into the parametric line equation, and I get a point that lies off the line. I have a feeling that DBPro just can't handle anything math-intensive using user defined types...

this is the code I'm using:

Errm... I may be doing something wrong... but it really makes no sense that the return point wouldn't lie on line AB! my solution to this problem has been to switch to c++ :S

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 30th Mar 2011 05:28
Wow, I get that exact same result with my code, t (I use PELF#) for some reason is negative and not at the intersection point in my example when my line is in a positive location . And mine is the alternative to using UDTs, using plain old simple equations to solve it. So idk what to try now since we both tried 2 different ways....

And also you said you would use c++ as an alternative but that wouldnt quite help me since (although I know enough c++ to make a 2d platformer) my game is in dbpro and would take a TON more time to learn enough in c++ to make the game that I have capabilities of coding in dbpro.

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 30th Mar 2011 10:43 Edited at: 30th Mar 2011 10:45


I bashed dbpro for no reason. i had a typo of an equals mark instead of a minus. Replace the equals with a minus and it works fine.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 30th Mar 2011 23:32
I got mine to work also, I don't know what was happeneing before. Mine looks a little cleaner and is a little easier to follow since the line intersect equation didn't need any vector math once I worked it all out.


So now that we got that out of the way, we need to now figure out how to efficiently loop through all of the edges being intersected by the plane and find the intersection. Now this is a little more difficult since you don't want to loop through every vertice and chech it with all other vertices. How do you even check if 2 vertices are connected?

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 1st Apr 2011 20:52
Does no one know how to connect 3 vertices to form a face or even check if 2 vertices are connected? I really need help with this because the search button didnt come up with what I was looking for and the dbpro help files gave me no help.

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 1st Apr 2011 22:49 Edited at: 1st Apr 2011 22:49
Quote: "Does no one know how to connect 3 vertices to form a face"

Required steps:
1. lock vertexdata for limb to which you want to add a new face
2. add 3 vertices to locked vertexdata
3. set the position, normal and uv data of the newly added vertices
4. add 3 indices to locked vertexdata
5. set the values of the newly added indices to the values of the 3 vertices you added in step 2
6. unlock the veretxdata

how to add a vertex to locked vertexdata?
Steps:
1. create the object box
2. delete all the vertices from the newly created object except 3
3. delete all the indices from the newly created object except 3
4. create a mesh out of the object created at step 1
5. delete the object created at step 1
NOW if you want to add a face to a locked vertexdata you just add a mesh from step 4 to the locked vertexdata


Quote: "or even check if 2 vertices are connected?"

Every face in the object has 3 indices, let's call them i1, i2 and i3
Every face has 3 edges:
edge 1: is between i1 and i2
edge 2: is between i2 and i3
edge 3: is between i3 and i1

To check if 2 vertices are connected you have to loop through all the object faces and for every face check if vertex1=i1 and vertex2=i2 or vertex1 i2 and vertex2=i3 or vertex1=i3 and vertex2=i1
In all of the above 3 cases vertices would be connected.

THe other way to check if vertices are connected is using hash tables->much faster, but probably impossible in db pro

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 2nd Apr 2011 00:49
:S
Brendyboy, is there a good tutorial on vertices and what indices and everything are? I'm a bit lost on the subject.

Quote: " Mine looks a little cleaner and is a little easier to follow since the line intersect equation didn't need any vector math once I worked it all out."

I thought mine looked cleaner! xD Oh well, to each his own!

Also, I figure this: only try to find the point of intersection of the edge (formed by two vertices) if the two vertices lie on opposite sides of the plane. I found this awesome article http://mathworld.wolfram.com/Point-PlaneDistance.html. if the signs (+ or -) of the dividend in equation (10) are the same for both points, then the points lie on the same side of the plane.

Going with my naming/vector convention for things, I get this function:

where WQxEQ is a vector that is the cross product between vectors (W-Q) and (E-Q), where W, Q, and E are three different points on the plane. MdotQ is the dot product of vectors (W-Q)x(E-Q) and Q. So MdotQ=((W-Q)x(E-Q)).Q

This program runs until the points are on the same side of the plane. If they are, you can press space to choose another point.




you miiiight notice that "crossdotaq" in function findIntersection() is equal to "posnum#" in pointsOnSameSideOfPlane(). After everything was figured out it'd be best to condense those to one function, to save "posnum" and get rid of "vecQ", saving a couple multiplications/subtractions.

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 2nd Apr 2011 00:59
Quote: "Brendyboy, is there a good tutorial on vertices and what indices and everything are? I'm a bit lost on the subject."

i don't know

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 2nd Apr 2011 14:19
So how are indices identified? Are the're indices for each face having the index value 1-3 for each face or does the indice number go for each vertex so having vertices 1-100 will have indices 1-100?

Jimpo
21
Years of Service
User Offline
Joined: 9th Apr 2005
Location:
Posted: 2nd Apr 2011 19:37
Indices are not unique to each face, they are for the whole object. The only thing the indices do is point to vertices. Think of each vertex as a point in space, not connected to anything. Each pair of 3 indices tell you which 3 vertices should connect to form a triangle. This allows you to reuse/share vertices. For example, a single vertex can be used to form multiple faces.

You don't even need to use indices to make an object. Instead, every 3 vertices will be a face. This means you can't reuse a vertex, and will often have multiple vertices in the same exact location. This is obviously troublesome for editing an object, but it is useful for texturing, as some shapes can't be uv mapped with shared vertices. For example, a cube.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 3rd Apr 2011 04:08 Edited at: 3rd Apr 2011 04:17
Ok thanks, I understand how indices work now. But do vertex ids go from 0 to total vertices-1 or 1 to total vertices?
Edit: I also just realized that if i'm splitting up an object and have to check every edge and its a high poly object, 5,000 for example, we would have to check with 124,925,010,000 loops, (5000*4999*4998), A tad to large. So there must be a better way to do it.

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 3rd Apr 2011 04:28
Quote: "But do vertex ids go from 0 to total vertices-1 or 1 to total vertices?"

Quote: " from 0 to total vertices-1"


Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 3rd Apr 2011 04:43
Quote: " I also just realized that if i'm splitting up an object and have to check every edge and its a high poly object, 5,000 for example, we would have to check with 124,925,010,000 loops, (5000*4999*4998), A tad to large. So there must be a better way to do it."


That's to check every possible triangle that could be formed by 5000 points... 5000 triangles, 3 edges per triangle = 15000 edges = 15000 pairs of points. Less if there are indices.
so like I said: To do this well in real time, you'd probably need some good optimization like what is used in collision engines (I don't know what). Other than that, the best I could come up with is first check if the points lie on the same side of the plane, and if they don't, calculate the intersection.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 3rd Apr 2011 17:46
But problem is still that we don't know how to check only the edges intersecting the plane. Otherwise we need to check every edge.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 6th Apr 2011 15:09
Ok so I worked out how indices work sort of... Now Im trying to figure out what get vertexdata index count returns and the command get indexdata. And also what the Index Number is and how do I relate it to vertices. Is it just in order of vertices so vertex 1 goes with index 1? I need to be able to have indices 0-2 and know which vertice goes with which inice.

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 7th Apr 2011 22:45 Edited at: 7th Apr 2011 22:47
Quote: "Now Im trying to figure out what get vertexdata index count returns"

number of indices in the locked mesh

Quote: "get indexdata"

returns the indice value at the specified index

Quote: "And also what the Index Number is"

every triangle has 3 indices. Indices tell you which 3 vertices are a a part of a specified triangle

Quote: "Is it just in order of vertices so vertex 1 goes with index 1?"

no

Quote: "I need to be able to have indices 0-2 and know which vertice goes with which inice."

there's no particular ruel for that. It's up to you to set 3 vertices for each triangle.

Example:
lets say that you have a mesh with the following data:
Vertex buffer:
v[0].x=0.0 v[0].y=0.0 v[0].z=0.0
v[1].x=1.0 v[1].y=10.0 v[1].z=3.0
v[2].x=-1.0 v[2].y=20.0 v[2].z=-2.0
v[3].x=2.0 v[3].y=-10.0 v[3].z=12.0
v[4].x=4.0 v[4].y=2.0 v[4].z=14.0

Index buffer:
i[0]=0 \
i[1]=2 | first triangle
i[2]=1 /
i[3]=0 \
i[4]=3 | second triangle
i[5]=4 /

In this very simple case command GET VERTEXDATA VERTEX COUNT() would return 5 because the vertex buffer contains 5 vertices which only have position data.

Command GET VERTEXDATA INDEX COUNT() would return 6 (This number is always triangle_count*3)

The first triangle is made out of these 3 vertices: 0, 2 and 1
The second triangle is made out of these 3 vertices: 0, 3 and 4

The command GET INDEXDATA(3) would return 0
The command GET INDEXDATA(4) would return 3
The command GET INDEXDATA(5) would would return 4, and so on...

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 14th Apr 2011 00:46
Ok, I know its been a while but I finally got to work on the code. Thanks Brendyboy, that helped a lot. So anyways, I got some code that detects edges however it isn't quite working all the way. It returns 1 more edge than there's supposed to be. I've looked at the code over and over and can't see the problem. Am I just reading the results wrong?


Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 14th Apr 2011 01:52 Edited at: 14th Apr 2011 01:53
you have a few "for-to loops" in the code that go like this:
For i1=0 to VertexTotal

It should be:
For i1=0 to VertexTotal-1

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 15th Apr 2011 01:56
Ok I fixed those, there were only 2 in the InitEdge function. It still is not working unless I missed one.


Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 15th Apr 2011 03:41
this:
ArrayID1=1 to MainVertexTotal
should be changed to this:
ArrayID1=0 to MainVertexTotal-1

Why? Because vertexdata starts at index 0 and end at index MainVertexTotal-1

if you try to access the vertexdaat at index MainVertexData you will get incorrect data -> but i'm not sure if that's why it doesn't work right

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 15th Apr 2011 05:25
Ohhhhh. I see what you are saying. Okay, fixed that but still doesn't work.


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Apr 2011 01:07 Edited at: 16th Apr 2011 01:08
Madscientist

Only just looked at this thread. I'm rather puzzled by your last snippet. What are the "edges" you are referring to? When I run your snippet it lists, correctly, 8 main vertices. It also lists 9 edges. Why 9?

If I've understood/read your code correctly then vertices 16 to 19 form one side of the cube and 20 to 23 form the other, with the opposite pairs being 16-20, 17-23, 18-22 and 19-21. The cube has 12 edges. The polygons making up the cube have 36 edges, with each edge repeated twice, making just 18 different edges in total, i.e. the 12 edges of the cube plus the six diagonal edges, one for each of the cube's 6 faces. Where does your figure of 9 (or 8?) fit into all this?

[Sorry if this is made clear earlier in the thread - but if you're trying to split an object along a plane then you need to split each polygon that crosses the plane giving three new polygons in place of each original crossing polygon. Perhaps I've misunderstood what you're trying to do? ]
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 16th Apr 2011 04:38
I see your confusion, I know that its not returning the right amount which is 12. I just cant figure out why it's not working.

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 16th Apr 2011 06:24
Quote: "I see your confusion, I know that its not returning the right amount which is 12."

It would have 12 edges if all vertices were shared, but they aren't. If they were shared there would be only 8 vertices but there isn't 8 but 24. My Landscape & Map Creator reports 30 edges in dbpro cube.

And here is a functional code that will list all 30 edges:


Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 16th Apr 2011 06:51
I mean 12 distinct edges where none of them coincide.

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 16th Apr 2011 07:23
Quote: "I mean 12 distinct edges where none of them coincide"

me to

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 16th Apr 2011 14:23
But where are those edges? There are the 4 edges on each side and 4 that connect them. If 1 side is added for each triangle on each side, that leaves 18 edges in total.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Apr 2011 15:35
Quote: "There are the 4 edges on each side and 4 that connect them. If 1 side is added for each triangle on each side, that leaves 18 edges in total."


Yes, I agree. However, Brendy Boy's figure of 30 edges seems to come from the fact that each face has four vertices and 5 edges - the diagonal edge is used twice and faces are not welded to each other. But vertices within a face are welded so you get a total of 6x5 = 30 edges in the model. Some of them coincide of course so the question is probably which of these 30 model edges does your code detect?

I haven't looked closely at your code to see where the problem occurs. Will try to find time later.
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 16th Apr 2011 19:32
Quote: "Sorry, Madscientist, I couldn't resist. I have no idea how to do what you ask. I've played around with the csg commands, but I don't think they quite cover what you are trying to do."


I've managed to produce something similar though:



To split the object into two objects, you can clone the object first, and then clip twice with inverted normals.

Cheers!
Sven B

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 17th Apr 2011 04:45
Ok, so I modified my code to loop through every vertice, not just the ones in the MaintVertex array. It returned 30 like yours so my edge detection isn't wrong. It's detecting the edges properly. I think I've actually found the problem with my code but don't know how to fix it. The code searches through the vertices until it reaches one that there are no proceding vertices with the same position. Then this vertice is stored into the MainVertex array. However the indices connecting the set of 4 edges on each side of the cube reference vertices not in the MainVertex array. So how do I tell which vertices belong to the indices for the main edges?

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 20th Apr 2011 04:36 Edited at: 20th Apr 2011 05:34
I DID IT!!!
I figured it out and fixed it. BrendyBoy, your code made me realize the flaws in mine, thanks!
So to fix it I made it check if an edge with the same endpoint positions was already there before adding a new edge to the array. I also made the index search that finds the edges step 3 so that each face is checked at once and not each individual index, that's why there were duplicates with the old code. So here it is!


Now its time to figure how to add vertices to a mesh...

EDIT: Ok, I updated the code to now support multiple objects and cleaned up some of the text.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 28th Apr 2011 13:57
Ok, It's been a while but I've gotten back to this project. So I'm wondering how to subdivide an edge. Can you add indices to the index buffer through vertex data commands? Or would I have to use memblocks to do this?

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Apr 2011 14:22
This would be a great bit of code if you can get it working!

I think you can add indices using those commands yes. I haven't got any code but I believe it should be possible.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 28th Apr 2011 15:18
The only command is Set Indice index, vertex but if you set a index thats greater than Get Vertexdata Index COunt will it add another index to that?

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Apr 2011 15:27
Quote: "The only command is Set Indice index, vertex but if you set a index thats greater than Get Vertexdata Index COunt will it add another index to that?"

Not sure but that sounds logical enough... I'll try looking for more info.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 28th Apr 2011 19:59
Ok, I tested that and it didnt work. It just ignors it if its outside the original index count. So I have a different approach, make a triangle object and convert it to a mesh, then just add it to the original mesh. I have't tried it yet though.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Apr 2011 21:43
(Basically agreeing with your idea of using a triangle mesh) ...

You can increase the number of vertices and/or indices of a mesh/limb by adding a new mesh with the correct number, or adding a mesh with a greater number (ADD MESH TO VERTEXDATA) and then either removing the excess (DELETE MESH FROM VERTEXDATA) or simply telling DBPro not to display the excess (SET LIMB DRAW PRIMITIVES and SET LIMB DRAW VERTICES).

Another alternative is to create a new object with the correct number of vertices and indices, and to then fill out with your data (MAKE OBJECT NEW).

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 3rd May 2011 17:53
Ok, so it's been a while. I decided to use memblocks because they are quite fast to edit in real time. However how should I find the normals of a face by the normals of the surrounding faces?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd May 2011 19:39
Don't you want the normals of a face to be defined by the vertices of the same face? You could use neighbouring face normals but that could give odd results - and you'd need to identify the neighbours somehow.

Or do you mean you want the normals of a vertex rather than face?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd May 2011 20:14
[Sorry about the double post. ]

This code shows how to calculate a face's normal from the three vertices. The vertex normals are shown for comparison - for a simple triangle they will be the same as the face normal.

Login to post a reply

Server time is: 2026-07-10 19:49:29
Your offset time is: 2026-07-10 19:49:29