Delgine 3D Tools & Content DeleD Community Edition
Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Torque Exporter
Goto page Previous  1, 2, 3, 4  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Plugins
View previous topic :: View next topic  
Author Message
Jeroen
Site Admin


Joined: 07 Aug 2004
Posts: 5332
Location: The Netherlands

PostPosted: Mon Mar 07, 2011 12:26 pm    Post subject: Reply with quote

I haven't studied smooth normals so I can't help out here. I still think it's a responsibility of the 3d engine to calculate those normals, not the editor. But again, as I haven't studied this, I might be talking nonsense here. Wink

Fik, you're doing an excellent job helping out. I really hope you and harper will find a solution.

Chronozphere, I know you're busy, but if you got some spare time to work on this too, it would be great.
_________________
Check out Figuro, our online 3D app! More powerful 3D tools for free.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fik
Member


Joined: 11 Oct 2006
Posts: 303

PostPosted: Mon Mar 07, 2011 5:37 pm    Post subject: Reply with quote

Did you try the .dae file I sent you? What does that look like in Torque?
I have no other solutions as looks ok when I export models into torgue but then I haven't set up scene etc so maybe that effects it or scale ? Think maybe only answer will be exporter being added to.
Back to top
View user's profile Send private message
chronozphere
DeleD PRO user


Joined: 20 Jun 2006
Posts: 1010
Location: Netherlands

PostPosted: Tue Mar 08, 2011 8:32 am    Post subject: Reply with quote

Hah.. this topic has grown tremendously. Smile

Quote:

Don't know how far chronozphere has got with the exporter but maybe I will give it a go as well.


Havent been able to do anything yet, to be honest. I'll have a quick look this evening. Smile
Back to top
View user's profile Send private message
harper
Member


Joined: 19 Jul 2007
Posts: 283
Location: Hamburg, Germany

PostPosted: Tue Mar 08, 2011 10:00 am    Post subject: Reply with quote

Oh my god - no !
No, i don't tried your .dae-model. It's perfect! How did you make it???

Back to top
View user's profile Send private message Visit poster's website
Jeroen
Site Admin


Joined: 07 Aug 2004
Posts: 5332
Location: The Netherlands

PostPosted: Tue Mar 08, 2011 11:18 am    Post subject: Reply with quote

fik wrote:

Edit 2 --
Found why won't import to blender. It's the blender importer, you have to open file in a text editor and change the line near top
<up_axis>Y_UP</up_axis>
to
<up_axis>Z_UP</up_axis>
This will rotate models and may cause problems with rotaion when exported and imported back into torque.Doing oposite when exported from blender should solve this.
Don't you just love how all programs deal with same file format in their own way Rolling Eyes


Did you try this, harper?
_________________
Check out Figuro, our online 3D app! More powerful 3D tools for free.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
chronozphere
DeleD PRO user


Joined: 20 Jun 2006
Posts: 1010
Location: Netherlands

PostPosted: Tue Mar 08, 2011 1:57 pm    Post subject: Reply with quote

Hah. very good. But I guess there is still need for this feature in the Collada exporter? Smile

btw, how can I test any exported collada model? Is there a simple program available that allows me to view the exported model + lighting. I don't have a whole Collada-based toolchain here, so I need you to help me with that. Wink
Back to top
View user's profile Send private message
chronozphere
DeleD PRO user


Joined: 20 Jun 2006
Posts: 1010
Location: Netherlands

PostPosted: Tue Mar 08, 2011 4:24 pm    Post subject: Reply with quote

I've located the normal generation code:

Code:

// Calculates the normals, taking the crease angle in account.
procedure DDPrimitiveT.CalculateNormals( const aCreaseAngle: single = 0 );
var
   i, j: Integer;
   polygon: DDPolygonT;
   normal: DDVector3T;
begin
   if aCreaseAngle <> 0 then
   begin
      raise Exception.Create( 'Crease angle not yet supported.' );
   end;

   for i := 0 to NumPolygons - 1 do
   begin
      polygon := Polygons[i];

      normal := NormalForPolygon( polygon );

      for j := 0 to polygon.NumVertices - 1 do
      begin
         polygon.AddNormalForProperties( normal.X, normal.Y, normal.Z );
      end;
   end;
end;


I would need to adapt this method, so that it computes smooth normals.

The problem is that right now, a single normal is used for each polygon. I need to extend the data model (probably the polygon/primitive class) to support per-vertex polygons. Also, I need to get the polygon-adjacency information to compute the per-vertex normals. It won't be a trivial task, but it's doable. Smile

Also, what exactly should creaseAngle be? It's not implemented. Confused
Back to top
View user's profile Send private message
fik
Member


Joined: 11 Oct 2006
Posts: 303

PostPosted: Tue Mar 08, 2011 6:02 pm    Post subject: Reply with quote

Harper: Glad that was working. I made it as I said exported from Deled with these settings note the normals not checked.

Then I did the Convert to fbx and back again this seems to build smooth normals if there are none prescent.

chronozphere- You could use Assimp viewer http://assimp.sourceforge.net/lib_html/index.html
Glad you found time to work on this. The converter needs to have the option to export Face normals as it does, or vertex normals which can be smooth. Crease angle would be used in vertex normals. Is that code from the collada exporter as it seems to be creating vertex normals for each poly (the same one as the polygon normal) which is odd as the exporter I dont think exports vertex normals Confused

Jeroen- Yes I do think Torque should handle the normals smooting like other engines do, if they are not avaliable on imported models, but then torque may have/ be more popular if it imported more model formats. its a pity it doesn't as seems quite a good engine especially at its current price. But then UDk is same price till you make 50,000 although you don't get acess to source for this.
Back to top
View user's profile Send private message
chronozphere
DeleD PRO user


Joined: 20 Jun 2006
Posts: 1010
Location: Netherlands

PostPosted: Tue Mar 08, 2011 7:20 pm    Post subject: Reply with quote

Hi all,

Seems like it will be more work than expected. This is because the uScene.pas, that is used by the exporter is also used by all other plugins in the repository. That means that I have to add the feature to all plugins or break the other plugins. As I'm not a fan of hacks, I have to take more time for this, to see how I can fit this feature in without doing damage. It should be possible and doable, but still..

The good news is that, once I've written that piece of code, the Torque- and Milkshape plugins can also make use of it. Smile
Back to top
View user's profile Send private message
harper
Member


Joined: 19 Jul 2007
Posts: 283
Location: Hamburg, Germany

PostPosted: Tue Mar 08, 2011 7:25 pm    Post subject: Reply with quote

Thanks fik, the illness seems to affect my eyes. Didn't see you unchecked the normals-export. Now everything works fine.

And thanks chrono! Seeing you looking on this makes me happy to wait for a better exporter!

You all are great!
Phew - so i have to continue my work; okay....


Last edited by harper on Wed Mar 09, 2011 6:53 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
chronozphere
DeleD PRO user


Joined: 20 Jun 2006
Posts: 1010
Location: Netherlands

PostPosted: Tue Mar 08, 2011 7:52 pm    Post subject: Reply with quote

@harper: Yes I noticed that there are still some people like you who would be really happy with some extra functionality in the plugins. I don't have time to spend alot of time on deled anymore, but if I can make you happy by spending one or two hours of my time on it, I probably will. Wink

And I have some good news again. After finding this nice little piece'a code I have the feeling that this feature was allready implemented but never made usable. Very Happy

Code:

procedure TPrimitive.CalculateNormals( const aCreaseAngle: single = 0 );
var vertexToPolygons: TObjectList;
    index, polygonIndex, vertexIndex: integer;
    polygon, sharingPolygon: TPolygon;
    sharingPolygons: TObjectList;
    cosAngle: single;
    normal, smoothNormal, sharingPolygonNormal: TVector3;
    sharingPolygonIndex: integer;

begin
    // First we build a map binding vertex to referencing polygons
    vertexToPolygons := TObjectList.Create(true);
    vertexToPolygons.Capacity := NumVertices;
    for index := 0 to NumVertices-1 do begin
        vertexToPolygons.Add(TObjectList.Create(false));
    end;

    for polygonIndex := 0 to NumPolygons - 1 do begin
        polygon := Polygons[polygonIndex];

        for vertexIndex := 0 to polygon.NumVertices - 1 do begin
            sharingPolygons := vertexToPolygons[fVertices.IndexOf(polygon.Vertices[vertexIndex].id)] as TObjectList;

            sharingPolygons.Add(polygon);
        end;
    end;

    // Then, per polygon per vertex, we average the normals of adjacent polygons (if angles are < CreaseAngle)
    cosAngle := Cos(DegToRad(aCreaseAngle));
    for polygonIndex := 0 to NumPolygons-1 do begin
        polygon := Polygons[polygonIndex];

        normal := VertexToVector(polygon.Normal);

        for vertexIndex := 0 to polygon.NumVertices - 1 do begin
            smoothNormal := normal;
            sharingPolygons := vertexToPolygons[fVertices.IndexOf(polygon.Vertices[vertexIndex].id)] as TObjectList;

            for sharingPolygonIndex := 0 to sharingPolygons.Count-1 do begin
                sharingPolygon := sharingPolygons[sharingPolygonIndex] as TPolygon;

                if sharingPolygon <> polygon then begin
                    sharingPolygonNormal := VertexToVector(sharingPolygon.Normal);
                    if VectorDotProduct(sharingPolygonNormal, normal) > cosAngle then begin
                        smoothNormal := VectorAdd(smoothNormal, sharingPolygonNormal);
                    end;
                end;
            end;

            smoothNormal := VectorNormalize(smoothNormal);
            polygon.AddNormalForProperties( smoothNormal.X, smoothNormal.Y, smoothNormal.Z );
        end;
    end;

    FreeAndNil(vertexToPolygons);
end;


All plugins call this method without the creaseAngle parameter, which results in non-smooth models. However, using a higher crease-Angle will make your model more smooth. I will need to add the per-vertex normals, but that is just some "work". The complex part seeems to be there allready. Smile

Update: Keeps gettin easier. The per-vertex normals are there too, allthough not that obvious since they were stored separately in TPolygon. Smile
Back to top
View user's profile Send private message
chronozphere
DeleD PRO user


Joined: 20 Jun 2006
Posts: 1010
Location: Netherlands

PostPosted: Tue Mar 08, 2011 8:51 pm    Post subject: Reply with quote

Seems like I have it working !! Very Happy

This is what the new exporter will look like:



I've added a combobox that allows you to select: "flat", "smooth" or "use crease angle" (the latter allows you to have objects that are partially smooth and partially flat).

I quickly created a dice shape to test it on. These are the results from "flat", "smooth" and "crease angle" respectively:







These examples aren't any good, because I could use only one light in the ASIMPP viewer (its all too dark now). I hope you can see that for this kind of shape, a crease angle of 30degrees is best, because it allows you to have smooth corners and flat sides. Smile

Hope this will fulfill your smoothing wishes for now. Smile

Update: The new plugin can be downloaded here.

I also commited my changes to the repository.
Back to top
View user's profile Send private message
Jeroen
Site Admin


Joined: 07 Aug 2004
Posts: 5332
Location: The Netherlands

PostPosted: Tue Mar 08, 2011 9:11 pm    Post subject: Reply with quote

This topic is a very nice example of what this community can do, if it sets its mind to something. Very Happy

Excellent work there, all of you! Cool
_________________
Check out Figuro, our online 3D app! More powerful 3D tools for free.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fik
Member


Joined: 11 Oct 2006
Posts: 303

PostPosted: Tue Mar 08, 2011 9:43 pm    Post subject: Reply with quote

Excellent Chronozphere It seems to work perfect. That was some very fast work Very Happy
Back to top
View user's profile Send private message
chronozphere
DeleD PRO user


Joined: 20 Jun 2006
Posts: 1010
Location: Netherlands

PostPosted: Tue Mar 08, 2011 9:57 pm    Post subject: Reply with quote

Quote:

That was some very fast work. Very Happy


Haha, well it took almost the whole evening to make it. But now I get this warm glowing feeling inside when reading your replies.. hmmm...Very Happy And it probably gets even better when harper reads this too. Wink
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Plugins All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum