home |  downloads |  help  |  forum  |  contact us 
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 23, 2013, 06:10:18 AM

Login with username, password and session length
Search:     Advanced search
fragMOTION 1.2.2 Released!
2787 Posts in 689 Topics by 788 Members
Latest Member: cliffordbryant4145
* Home Help Search Login Register
+  Fragmosoft Forum
|-+  fragMOTION
| |-+  Scripting
| | |-+  Faces, vertex and UVs
« previous next »
Pages: 1 [2] Go Down Print
Author Topic: Faces, vertex and UVs  (Read 2463 times)
Richcat
Newbie
**
Posts: 32


View Profile
Re: Faces, vertex and UVs
« Reply #15 on: January 24, 2012, 07:37:05 AM »

Not had much luck with a script to select each group with vertex and faces individually and illerate through mesh (I just need to learn more) - anyone - any pointer or tips on this.
I was looking at IMesh2::SelectSelectionGroup.
Logged
fragmo
Administrator
Not A Newbie
*****
Posts: 10664



View Profile
Re: Faces, vertex and UVs
« Reply #16 on: January 25, 2012, 08:41:06 PM »

What's wrong with IMesh::SelectGroup  ?
Logged
Richcat
Newbie
**
Posts: 32


View Profile
Re: Faces, vertex and UVs
« Reply #17 on: January 27, 2012, 03:25:10 AM »

Thanks Fragmo- Thanks for being very patient

I tried that - but with my very limited understanding of how to implement things - I've had no luck.
How do you use below is where I think I'm going wrong. I persume you put them in the brackets, but do you put Group or the group ID or name etc.
Group* pgroup, 
BOOL bSelect, 
MultiSelect multi 

I'll go back and have another go.

I have been able to select the individual groups manually, using the Group Selection Tool with select vertices and select object ticked and then I can get the vertex and facecounts for each group, but I'm stuck on how the get a script to work throught the groups in the mesh to extract info per group.
editChar:ClearOutput();

local mesh = editChar:GetSelMesh();

local mesh1 = mesh:GetSelVertexCount();
local mesh2 = mesh:GetSelFaceCount();
print (mesh1);
print(mesh2);


This is where I'm at with the face extraction and textures uv and vertex, the problem is when I iterate through the faces I get too many texture uv coords and vertex points

editChar:ClearOutput();


local pAnim = IUserObject(editChar:GetSelAnimation());      --get pointer to the selected animation (IAnimation)
local mainModel = editChar:GetModel();

   
   myMesh = editChar:GetDefaultMesh();
   local verts, vert_count, faces, face_count = myMesh:LockMesh();

      allGroups = mainModel:GetGroups();
      currentGroup = allGroups:GetFirstChild();
      
      while currentGroup:isSet() do
            currGroupName = currentGroup.Name;
            print("["..currGroupName.."]");
   
            local tex =editChar:GetSelection();
            local texmap = tex:GetName();
            print("MAT "..texmap);
               
               local group = 0;
               for f = 0, face_count-1, 1 do
                  if faces[f].groupID == currentGroup:GetID() then
                  print("f".."["..faces[f].index[0]..","..faces[f].index[1]..","..faces[f].index[2].."]");

                     group = group + 1;
                  end
               end
               
               if group > 0 then
                  print("facecount "..group);
         for f = 0, face_count-1, 1 do
                  print("tv".."["..faces[f].uv[0].x..","..faces[f].uv[1].y..", 0]");
                  
end
                  local vertc = 0;
                  for i = 0, vert_count-1, 1 do
                  if faces[i].groupID == currentGroup:GetID() then
                          print("v".."["..verts[i].x..","..verts[i].y..","..verts[i].z.."]");
                          vertc = vertc + 1;
                        
                     end
                  end
                  
                  if vertc > 0 then
                  print("vertcount "..vertc);
                  
               end
         end
         
      
      
      
      currentGroup = currentGroup:GetNextSibling();
   
   end

   myMesh:UnlockMesh();   


Basically to get the exporter to work I need to extract the mats, textures, faces, texture verts, verts, normals, and smooth groups per group and animation mesh matrix per frame per group.
Long way to go yet but I'm in for the long run.  Smiley

« Last Edit: January 27, 2012, 03:53:34 AM by Richcat » Logged
Richcat
Newbie
**
Posts: 32


View Profile
Re: Faces, vertex and UVs
« Reply #18 on: August 29, 2012, 03:36:19 AM »

Hi still looking for help/inspiration/ pointers etc

8 months on and off and I'm still trying and trying to get a script to export a text file to import into Battle Academy. I'm basically stuck as I need to export the faces, verts, animation etc per group.

I'm still trying to iterate through a Mesh to extract the Faces and the Verts per group etc etc . The code below works perfectly for the faces and uvs but not the verts as I can't index these, and can't figure out a way to do it.
For example in the code in the post below above (EDIT) extracting info as groups for 2 Boxes - 12 faces and 8 verts each-  I get 12 faces as expected but 12 verts for Box and then 12 faces for Box1 and 4 verts. Is there any way to check the verts are not duplicates.

I have tried to used IMesh::SelectGroup, but what ever I have tried like

local mainModel = editChar:GetDefaultMesh();
local dmesh = mainModel:SelectGroup(Box);

or
local mainModel = editChar:GetDefaultMesh();
local dmesh = mainModel.SelectGroup;

it will not still not select an individual Group - I'm totally stumped.

Cheers Rich
« Last Edit: August 30, 2012, 07:50:32 AM by Richcat » Logged
Richcat
Newbie
**
Posts: 32


View Profile
Re: Faces, vertex and UVs
« Reply #19 on: August 30, 2012, 04:08:42 PM »

Another try  Cry. but no luck.

editChar:ClearOutput();
local mesh4 = editChar:GetDefaultMesh();
local mainModel = editChar:GetModel();
local  allGroups = mainModel:GetGroups();
local currentGroup = allGroups:GetFirstChild();
local nam = currentGroup.Name;
print(nam);

local meshs = mesh4:SelectGroup(nam);

I would really like to get this working and can supply the a 3sf. file which basically is a simple txt file, that is read by the game, if anybody can help.

I have experience of adapting an 3dmax exporter to Gmax exporter for this particular game - which is getting very popular on the ipad, but most people there have asked for a Fragmotion one, and after buying it and using it I can see why. Having tried so long I'm just stuck on the way to get the right number of verts per group, which may be a very straight forward thing that I just can't see. I would dearly luv to get it done, or please tell me it can't so I can get on a build an M26 for the game. and import in Gmax

Dave is there any way to have numerous meshes that make the turret, body, gun etc in the one file, as Gmax, and then iterate through these (I know previously you have said there is one mesh). At the moment I'm using Groups the same way. Just a thought.

Cheers Rich
Logged
fragmo
Administrator
Not A Newbie
*****
Posts: 10664



View Profile
Re: Faces, vertex and UVs
« Reply #20 on: August 30, 2012, 09:31:19 PM »

This code works for me:

local mesh = editChar:GetDefaultMesh();
local group = activeChar.Model.Groups:GetFirstChild();
mesh:SelectGroup(IGroup(group), true, selSingle);
viewer:Redraw(true);  -- not needed unless you want to see the selection change

I'm not sure I understand why you want to use SelectGroup though, this is more for visual editing.  The groupID is stored per triangle.  Get the id from the group by calling group:GetID()  <that's IUserObject::GetID>.  Then you can loop through the triangles in the mesh and compare fragTriangle::groupID to the groupID you're looking for.

Quote
is there any way to have numerous meshes that make the turret, body, gun etc in the one file, as Gmax, and then iterate through these (I know previously you have said there is one mesh). At the moment I'm using Groups the same way.

Groups can define a sub-mesh, the main limitation here is that you won't be able to have vertices that aren't referenced by a triangle since the group is simply a group of triangles
Logged
Richcat
Newbie
**
Posts: 32


View Profile
Re: Faces, vertex and UVs
« Reply #21 on: August 31, 2012, 03:25:12 AM »

Huge Thanks Dave - I don't know why I didn't ask sooner Smiley - just too stubborn and wanted to get to learn more about lua.

Quote
I'm not sure I understand why you want to use SelectGroup though, this is more for visual editing.

To get the Selected Vertex Count per group, as looping through the groups with script below was giving me the correct verts for one group, but if I then introduced more groups it wouldn't.
For example Create Box1 - run the script and I'd get 12 faces and 8 verts, but add another Box2 and I'd get 12 faces but 16 verts for Box1 and 12 Faces and 4 verts for Box 2.

Part of script were I'm having problems
 
Quote
  local vertc = 0;
                  for i = 0, vert_count-1, 1 do
                  if faces[i].groupID == currentGroup:GetID() then
                          print("v".."["..verts[i].x..","..verts[i].y..","..verts[i].z.."]");
                          vertc = vertc + 1;
                       
                     end
                  end
                 
                  if vertc > 0 then
                  print("vertcount "..vertc);
« Last Edit: August 31, 2012, 03:27:58 PM by Richcat » Logged
fragmo
Administrator
Not A Newbie
*****
Posts: 10664



View Profile
Re: Faces, vertex and UVs
« Reply #22 on: August 31, 2012, 06:30:29 PM »

Have you tried welding vertices?  If you import a file it's likely to have duplicated vertices which would cause what you're seeing.
Logged
Richcat
Newbie
**
Posts: 32


View Profile
Re: Faces, vertex and UVs
« Reply #23 on: September 01, 2012, 03:41:48 AM »

Thanks for suggestions Dave
I haven't tried welding vertices, or importing anything yet, just been using the create box in the tools menu so far.

Cheers Rich
« Last Edit: September 01, 2012, 04:51:15 AM by Richcat » Logged
Richcat
Newbie
**
Posts: 32


View Profile
Re: Faces, vertex and UVs
« Reply #24 on: September 04, 2012, 08:14:21 AM »

Thanks Dave

It seems I got the faces, uvs, and vertex exporting per group now, Grin thanks to you showing me how find a way to select one group at atime Wink. On ward and upward.
Now to extract the Matrix per group, per frame, and whole new area, bones are not exported only vertex animation.

local vertx = 0;
for i = 0, vert_count-1, 1 do
if  vertx+1 <= mesh2 then -- Compare on going vertex count with mesh2 - the GetSelVertexCount
print("v".."["..verts[i].x..","..verts[i].y..","..verts[i].z.."]");   
vertx = vertx + 1;
end

Cheers Rich
Logged
Pages: 1 [2] Go Up Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Fragmosoft Forum | Powered by SMF 1.0.8.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!