NewtonMesh

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: NewtonMesh

Postby Stucuk » Wed Nov 18, 2009 3:36 pm

Julio Jerez wrote:but I do not think it is nessesary.


Each Vertex of a Face in my map editor has the basic UV coordinates but the face has extra Scale/Shift/Rotation parameters which the user can change. When rendering the FinalUV is worked out:

Code: Select all
if Assigned(FTexture) then
   begin
    FVects[X].FinalU := (FVects[X].U + (FShiftX / TTexture_Basic(FTexture).GetWidth));
    FVects[X].FinalV := (FVects[X].V + (FShiftY / TTexture_Basic(FTexture).GetHeight));
   end
   else
   begin
    FVects[X].FinalU := (FVects[X].U);
    FVects[X].FinalV := (FVects[X].V);
   end;
   if FRotation <> 0 then
   RotateTexCoord(FRotation,FVects[X].FinalU,FVects[X].FinalV);

   FVects[X].FinalU := FVects[X].FinalU * FScaleX;
   FVects[X].FinalV := FVects[X].FinalV * FScaleY;


My plan is to Send the Basic UV coords to the NewtonMesh and then after doing a boolean operation copy the Scale/Shift/Rotation of the Old Object's Faces to the New Object's Faces that were the same.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Wed Nov 18, 2009 4:05 pm

I see you are using the materail ID as like a texture operator, That will work fine.

say you have a cube and each face haev and ID for 0 to 5
if you have another cube with face form 10 to 15

if you make a subtration the the face in the intesetion in teh contouer will have Id form 0 to 5 and teh face in teh intersetion will ha teh Id form 10 to 15 form teh oteh cube.
In adition the UV will be calculate corretly,

then you can ge the face and applu you editor formulas to any of the faces. I do no see any complcations It should work fine everywere.

How far alone are you in this editor, I hope I see some demos?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Wed Nov 18, 2009 7:59 pm

Julio Jerez wrote:How far alone are you in this editor, I hope I see some demos?


Not as far along as your expecting. Other things have been getting in the way(Spent most of this year not working on it). The only things you can currently do is load 3DW files (Leadwerks should know what they are :wink: ), move objects about, change there texture scale/shift/rotation as well as change the texture. The Align to Face/World that can be seen on the screenshots below does nothing, same with the Replace button and all the Justify buttons.

- fme1.png
- fme2.png
- fme3.png

P.S The Scrollbars are missing the Scroll bit in the middle... not coded that yet :P
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby JernejL » Wed Nov 18, 2009 8:13 pm

Your editor is coming up nicely.. i am seriously thinking to use this for TDC, it would enable much more variety than my current "cube map".
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: NewtonMesh

Postby Stucuk » Fri Nov 20, 2009 5:40 am

When i use the NewtonMeshClip the top and bottom mesh's don't contain any faces or vertexs.

Code: Select all
procedure TFME_Map.ClipObject(MapObject : TMapObject);
var
 NM1,NM2,
 TopMesh,
 BottomMesh : TNewtonMesh;
 M : TMatrix4;
 MObject : Pointer;
begin
 NM1 := SizeToTNewtonMesh(SetVector(100,100,100));
 NM2 := TNewtonMesh.CreatePlane(@IdentityMatrix[0][0],100,100,-1,@IdentityMatrix[0][0]);

 TopMesh    := TNewtonMesh.Create(Nil);
 BottomMesh := TNewtonMesh.Create(Nil);

 M := IdentityMatrix;
 NM1.Clip(NM2.Mesh,@M[0,0],TopMesh.Mesh,BottomMesh.Mesh);

 MObject := TNewtonMeshToTMapObject(TopMesh,MapObject);
 If Assigned(MObject) then
 AddObject(MObject);
 MObject := TNewtonMeshToTMapObject(BottomMesh,MapObject);
 If Assigned(MObject) then
 AddObject(MObject);

 NM1.Free;
 NM1 := Nil;
 NM2.Free;
 NM2 := Nil;
 TopMesh.Free;
 TopMesh := Nil;
 BottomMesh.Free;
 BottomMesh := Nil;
 Update;
end;


I know the SizeToTNewtonMesh and TNewtonMeshToTMapObject work fine as i have tested them without the clip. When TopMesh.Free; is called the Application crashes with Access violation at address 00E01F1A, the TopMesh.Free is calling NewtonMeshDestroy.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Fri Nov 20, 2009 8:18 am

mak esur ethe plane do cut the mesh.
when the cutting plane do no pass trught the mesh no cut is done and teh two pointers to poinets are NULL
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Fri Nov 20, 2009 11:56 am

Meh, my code was wrong(As usual i can't find flaws with your code). Needed to send the TopMesh and BottomMesh pointers err address or whatever. (The & sign in C++ before a variable which turns it into a pointer)

Julio Jerez wrote:mak esur ethe plane do cut the mesh.
when the cutting plane do no pass trught the mesh no cut is done and teh two pointers to poinets are NULL


So its impossible for it to for example hollow out the centre of a cube?
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Stucuk » Fri Nov 20, 2009 1:07 pm

Simple Demo: FME_NewtonMeshClip.rar
Screenshot: fme_NewtonMeshClip.png

Usage:

Right click on the main window bit (Bit with the 3d view + 3 Grids) and select NewtonClipTest. You can move the 3D View around by moving the mouse over it and then pressing Z, that will activate the "move around mode thingy"™ (Im great at coming up with names for things). You can use the WSAD keys to move around once the "move around mode thingy"™ is activated, moving the mouse aims the camera. Press Z again to exit the "move around mode thingy"™. You can move the 2 objects around by clicking on one and then dragging it.

Note: "move around mode thingy"™ is not a registered trademark.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Fri Nov 20, 2009 2:05 pm

to hollow a piece you can use th subtract operation I think, clip is for cutting

In the demo I see a cube and when I move away I see a small cube in red but is is not hollow unless it is shwo teh outside and inside place.,
in side view seems to be hollowed bu in 3d it is maybe showing the two pieces.


I do no think i will make a hole in a box, I have not tried, but if for exampel you take a cube and place inside anoteh cube, then teh object suface will no touche and no bollion will be possible.
Thes boollean si topological not volumetrial.
as you start using it you will see tha it is not that much of a limitation, I hope.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Fri Nov 20, 2009 3:12 pm

Julio Jerez wrote:to hollow a piece you can use th subtract operation I think, clip is for cutting


I don't see any subtract in the header. The Difference and Intersection seem to be the same as Clip but just returning either the TopMesh or the BottomMesh.

Julio Jerez wrote:as you start using it you will see tha it is not that much of a limitation, I hope.


For 99% of the things people would use it for it will be perfect. Apart from hollowing out a object, which is not used much(Generally only "tought" to people so they can make a room in a map editor "Easier") there isn't any other situations that i can think of where you would need to not touch the outer edges of the object. One odd thing i noticed is that if you try to use it on a NewtonMesh which is the same as the clipperMesh the faces become inverted.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Fri Nov 20, 2009 3:20 pm

it is call NewtonMeshDifference
you can use it to do carving, for example you can take a Big Box, and a thin long Box.
the difference will remove the interstion between the Big Box and the thin Box for the Big Box, of viseverse depending on the order of the parameters
When you fill teh need you will see the difference.

Stucuk wrote:For 99% of the things people would use it for it will be perfect. Apart from hollowing out a object, which is not used much(Generally only "tought" to people so they can make a room in a map editor "Easier") there isn't any other situations that i can think of where you would need to not touch the outer edges of the object. One odd thing i noticed is that if you try to use it on a NewtonMesh which is the same as the clipperMesh the faces become inverted.

you can make teh hollwe room fution by dowin a series of Cut of a Cube, in fact wi eteh clip along you xcna to teh king of all of eth Quake/Unreal/Hallike bollean operations.

The Bollean in NetwonMesh are true Bollean Operation the type you find in editor like 3dMax, or Maya. it does not go by dowing Plane clipping they do a topological cliipping to produce a single Mesh, instead of an array of convex Meshes like the Game editors bolleans.


The face are invertes because the operation is

A - B

when A is a NewtonMesh and B is another Newton Mesh, the clipped faces of B that becomes part of A are inverted because if the negative sign in fron of B.
you controll teh face by controlling hwo teh face are place in teh mesh.
for example if the clipper Mesh is inverted then you can just flierp the texture matrix when you create the clipper mesh, an dteh it will be correct.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Fri Nov 20, 2009 5:55 pm

Demo 2: FME_NewtonMeshClip2.rar

This one works differently, it gives you more control over how to clip the object. You right click and select Add Object, which creates a 100x100x100 cube. You can then left click and drag to create a "selection" rectangle. Then you can right click and select Newton Clip Test and it will Clip the First Object in the map based on the bounds of the selection. You can clip the object as meny times as you like.

Would it be possible to get the Polygonize procedure to generate the same polygons on the top and bottom of the Mesh? The top of the mesh has only 2 faces, but the bottom has 4 faces even tho there the same shape. Screenshot: FME_TopBottomFaces.png


Julio Jerez wrote:you can make teh hollwe room fution by dowin a series of Cut of a Cube, in fact wi eteh clip along you xcna to teh king of all of eth Quake/Unreal/Hallike bollean operations.


Could you elaborate? I assume you mean that if i carve holes through the middle along each axis and then add them together i can get a mesh that is hollowed. If thats what your meaning then it doesn't work. The holes are cut perfectly through the center along each axis. Union just doesn't add them together properly.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: NewtonMesh

Postby Julio Jerez » Fri Nov 20, 2009 6:16 pm

Stucuk wrote:Would it be possible to get the Polygonize procedure to generate the same polygons on the top and bottom of the Mesh? The top of the mesh has only 2 faces, but the bottom has 4 faces even tho there the same shape.

Image
Isn't that cool? this kind of tool really give some teeth to an editor.

to get consistent poligonal faces you can call ConvertToPoLgon and the solid will be converted to a Polygonal model with of Optimal convex faces.
The optimization critiria is maximize the Surface Area, and penalizee extreme aspect ratios.
In the image if you call ConvertToPolygon then the Top and bottom face you get the same topology.
it does not always give you the same topolgogy in similar faces because the optization is a heustiric, but it does do a good job.

Stucuk wrote:
Julio Jerez wrote:you can make the hollwe room function by doing a series of Cut of a Cube, in fact wi eteh clip along you xcna to teh king of all of eth Quake/Unreal/Hallike bollean operations.

Could you elaborate? I assume you mean that if i carve holes through the middle along each axis and then add them together i can get a mesh that is hollowed. If thats what your meaning then it doesn't work. The holes are cut perfectly through the center along each axis. Union just doesn't add them together properly.


I mean you can just make six Cuts, and around the surface and trown out the interir part.
then what you get is 6 solids walls that form an empty room.
or you can use two boxes and subtract one small box for and the place a top the way you get a room made of just two solids.
Once you have the editon and navagation capability in teh editor teh possibility seems to take a life of his own.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Julio Jerez » Fri Nov 20, 2009 6:32 pm

Oh I see you are calling Polgonoze already, an dsoem hwo teh face on teh bottom is not optimal.
I will take a look maybe I can see some defficenetcy or a bug in teh algorithm that is making to select a bad polygonization for the lower face.

It is good you are using it because visualization help to see those deficiencies.
are you sure you are converting it to polygon, because the lower face seems to be a planar triangulated face?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMesh

Postby Stucuk » Fri Nov 20, 2009 7:23 pm

Julio Jerez wrote:Isn't that cool? this kind of tool really give some teeth to an editor.


To be honest i never imagined id be able to get a Boolean operation into the editor, as its defiantly beyond my capabilities (I s.uck at understanding the maths equations on websites and in maths articles). Its defiantly a cool feature.

Julio Jerez wrote:are you sure you are converting it to polygon, because the lower face seems to be a planar triangulated face?


Its one of the first things that gets called after the NewtonMeshDifference. Mesh.Polygonize is just the same as NewtonMeshPolygonize(). If its not called then its all made up of triangles. With FME you can change the 3d view to wireframe by first clicking anywhere in the 3D View (so it becomes the active window) and then clicking on the Wireframe button at the top left of the screen (Under the menu).

Code: Select all
function TNewtonMeshToTMapObject(Mesh : TNewtonMesh; OriginalObject : TMapObject) : TMapObject;
var
 I,V,
 FaceCount,
 IndexCount,
 VertexCount,
 Start           : Integer;
 FaceIndexCount,
 FaceMaterial,
 FaceIndexArray  : Array of Integer;
 m_vertex,
 m_normal        : Array of TVec3;
 m_uv            : Array of TVec2;
 Face            : TMapFace;
begin
 Result := Nil;
 if not Assigned(Mesh) then Exit;
 if not Assigned(Mesh.Mesh) then Exit;

   Mesh.Polygonize;
   FaceCount   := Mesh.GetTotalFaceCount;
   IndexCount  := Mesh.GetTotalIndexCount;
   VertexCount := Mesh.GetVertexCount;

   if FaceCount < 1 then Exit;
   if IndexCount < 1 then Exit;
   if VertexCount < 1 then Exit;


   SetLength(m_vertex,VertexCount);
   SetLength(m_normal,VertexCount);
   SetLength(m_uv,VertexCount);
   Mesh.GetVertexStreams(SizeOf(TVec3), @m_vertex[0][0], SizeOf(TVec3), @m_normal[0][0], SizeOf(TVec2), @m_uv[0][0]);

   SetLength(FaceIndexCount,FaceCount);
   SetLength(FaceMaterial,FaceCount);
   SetLength(FaceIndexArray,IndexCount);

   Mesh.GetFaces(@FaceIndexCount[0],@FaceMaterial[0],@FaceIndexArray[0]);

   Result := TMapVisualFaceObject.Create(Nil,FME_Map);
   Start := 0;
   for I := 0 to FaceCount-1 do
   begin
    if faceIndexCount[I] > 0 then
    begin
     Face   := TMapVisualFaceObject(Result).AddFace;
     for V := 0 to faceIndexCount[I]-1 do
     face.AddVector(m_vertex[faceIndexArray[Start+V]],m_uv[faceIndexArray[Start+V]][0],m_uv[faceIndexArray[Start+V]][1]);
    end;
    Inc(Start,FaceIndexCount[I]);
   end;

   TMapVisualFaceObject(Result).FinaliseObject;

   SetLength(FaceIndexCount,0);
   SetLength(FaceMaterial,0);
   SetLength(FaceIndexArray,0);
   SetLength(m_vertex,0);
   SetLength(m_normal,0);
   SetLength(m_uv,0);
end;


Julio Jerez wrote:I mean you can just make six Cuts, and around the surface and trown out the interir part.
then what you get is 6 solids walls that form an empty room.
or you can use two boxes and subtract one small box for and the place a top the way you get a room made of just two solids.


Ah right. Time to try that.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron