Drawing polygon(s)



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/03/2012 at 05:30, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   12 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hi folks,
     
    I'm doing some simple experiments on object plugins and am getting stuck on one in particular. I have a basic object that holds polygon/point data and am wanting to view that in the editor view. But I'm not sure where I should draw it from, or how.
     
    So far, I can select the polygons, points, edges and can use Cinema's tools with it. Data is stored in Tpoint and Tpolygon tags, and renders out fine. But I can't seem to get them to show up in the editor viewport unless I mouse over them in one of the tool modes (such as polygon mode).
     
    Might this have something to do with GetCache() and/or GetDeformCache()? Is it possible to use Draw() or DrawPolygon() (or another type?) to get the tag data and draw the object into the viewport?
     
    How does a simple editable polygon work/how is it drawn into the viewport?
     
    Kind regards, WP.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/03/2012 at 08:38, xxxxxxxx wrote:

    Not easy to answer, without seeing your code...
    Did you have a look at the example plugins of the SDK?
    In general you don't need to explicitly paint the polygons into viewport. Did you post the MSG_UPDATE (have a look at roundedtube.cpp in SDK examples)? Assuming you're creating an object generator (not sure, as you're writing about tags as well), you'd probably want to post the upadte message in the end of GetVirtualObjects().

    For basic stuff, you don't need to mess with the cache at all. And Draw() is indeed for drawing into the viewport, but rather to paint handles and stuff...



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/03/2012 at 16:38, xxxxxxxx wrote:

    i guess it is the same request as on cgtalk, so he isn't writing a object generator plugin, but some own polygon handling class.

    http://forums.cgsociety.org/showthread.php?f=182&t=1026867



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/03/2012 at 17:20, xxxxxxxx wrote:

    Thanks to both of you for your replies - appreciated!
     
    Yep - that's my post over on CGTalk too. I'm quite new (few months) to this c++ plugin and coding business so not sure where to make posts at the moment. I certainly don't expect any responses but any are welcome =)
     
    I've got a ObjectData plugin I'm fiddeling about with in an attempt to learn plugin making. And I 'thought' I'd have a go at making just a simple editable polygon. But it's proving more difficult that I thought. Oddly enough I seem to recall somewhere that this might not be possible (Maxon maybe keep this info hidden??), but can't for the life of me remember where I saw such a thing - if at all.
     
    Re: code example - I'm a bit unsure where any of this should be executed from so not really sure what I can paste. However - I thought that since I have access to a Tpoint and Tpolygon tag that maybe I could use a DrawPolygonObject and iterate through the points/polygons and draw my 'mesh' based on the tag data available. Would such a feat be possible? Would this way effect viewport speed at all?
     
    In short, I can copy polygons over to my model, and it holds them - and renders them - but they just don't show in the viewport itself. I'm effectively working blind until I hit render. I can however, manually draw objects but they're not editable. I would paste a screen shot but I can't seem to upload anything here. The CGTalk link does have an image of my dilema if needed.
     
    Any ideas?
     
    WP.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/04/2012 at 00:08, xxxxxxxx wrote:

    Hi Peeps,
     
    I've managed to get this to work, and my plugin now draws the object in the viewport. However, the viewport runs incredibly slow compared to a native Polygon object of the same poly count. It seems that the Draw() function gets refreshed everytime the mouse moves. Is there a way to prevent this from happening?
     
    Once I get above 12,000 polys the viewport starts to run very slowly. If I then place this object under a HN it almost fails to do anything at all, and switches to the viewport box display mode. Whereas that same object in a normal Cinema Polygon runs freely at far more polys than that.
     
    Is Draw() just very slow? Or is there something I'm missing to this?
     
    WP.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/04/2012 at 01:00, xxxxxxxx wrote:

    I'm a bit confused about what you're trying to do. Are you trying to return actual geometry? If so, you need to override GetVirtualObjects. Draw() is then only used for stuff like draw handles or any other editor-only things you need. You certainly don't draw the actual polygons of your object. If you did that, it probably would be very slow.

    Or maybe you're trying something else?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/04/2012 at 01:17, xxxxxxxx wrote:

    Hi spedler,
     
    showing my complete lack of plugin knowledge here...!
     
    What I've got is an object plugin which has the Tpoint and Tpolygon tags on it. The object resides in the viewport, I know this because I can put it into polygon mode and select polys, but you can't actually see them (selecting the polys is done purely by guessing where they are!!). As I couldn't see them I thought (probably stupidly!) I'll draw them! So that's where I'm at. So I can now see them, but they're not like the native Cinema polygon (and things get slow from 12,000 polys+). 
    I did initially start trying to get them from GVO but couldn't get it to work, hence partly also why I went to the Draw() method.
     
    So it sounds like I should be asking how to return the polygons through GVO instead?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/04/2012 at 01:37, xxxxxxxx wrote:

    Absolutely. If you are creating geometry, you have to do it in GVO. It isn't difficult to do (it's unfortunate that the SDK example isn't as clear and simple as it could be) and it's very fast. Don't try to draw your polys though, it just won't work.

    If I get time I might run up a quick tutorial on producing an object plugin for my site (I've got one now, but it's for a spline, which is different). But don't wait for that to appear - it could be a while :-)

    Steve



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/04/2012 at 01:56, xxxxxxxx wrote:

    I must admit - I feel a bit embarrased! All that effort and I wasn't even in the right function ha!! Ohwell - I can now draw objects based on the poly info through the Draw() function. No idea what that could be used for but it's there! One for the scrap book!
    My plugin's at the stage where I'd like to see what is there before I take it any further, which is why I'm trying to sort this out! I'm kind of excited about it as I think others would get a kick out of this plug. It's just a shame I've not coded before, it'd probably be much more advanced by now!
     
    I'll have to go back to GVO! Thanks Steve!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/04/2012 at 03:40, xxxxxxxx wrote:

    GVO is really nice because you simply create the geometry within that function and then return the final PolygonObject that you created.  For example if you wanted to create a single polygon you could do it like this.

      
      PolygonObject *polyObj = PolygonObject::Alloc(4,1);     //Allocate a Polygon Object with 4 points and 1 polygon  
      if (!polyObj) return NULL;  //Check to make sure the pointer is valid if not return NULL, prevents crashing  
      
      Vector *padr=NULL;         //Declare a Vector array to hold the points  
      
      CPolygon *vadr=NULL;        //Declare an array of CPolygons to hold the polys  
      
      padr = polyObj->GetPointW();       //assign the points array to your polygon object points array  
      
      vadr = polyObj->GetPolygonW();    //assign the polygon array to your polygon object's poly array  
      
      padr[0] = Vector(0,-400,-400);        //place your points at your desired locations.  
      padr[1] = Vector(0,-400,400);  
      padr[2] = Vector(0,400,400);  
      padr[3] = Vector(0,400,-400);  
      
      vadr[0] = CPolygon(0,1,2,3);   // Assign the 4 points to a CPolygon  
      
      return polyObj;      //return your final object  
      
    

    Just drop that code in to GVO without anything else and see what it does.

    Also if you want to create primitives such as a cube.  You would do something like this.

      
      
    BaseObject*  cube = BaseObject::Alloc(Ocube);  
    if(!cube) return NULL;  
      
    return cube;  
      
    

    basically because PolygonObject is derived from BaseObject, you can return either a BaseObject or a PolygonObject and it will show up through GVO.

    Hope that helps.

    ~Shawn



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/04/2012 at 05:02, xxxxxxxx wrote:

    Hi Shawn,
    thanks for those examples. Just in the last hour or so I've been able to draw some things into the viewport using a similar style to the first example. I've previously drawn a spline in GVO as well which I'm using to get some length data.
     
    Here's the trixy bit I'm losing myself on though. I'm using the CopyPastePlugin to copy polygons over to my plugin object. So the data is there in the tags, I just don't know how to draw it in the viewport. That's where I went to the Draw() function to have a go. So it's just getting the polys to display that's my issue.
     
    I'm guessing from here I could probably just iterate through the tag info like I did in the Draw but inside GVO and maybe that's all I need to do? Or is there a way to just return what's already in memory?
     
    In simple terms, I just want my own polygon plugin that I can edit etc using Cinema's tools, but with my own AM gui elements and sliders etc.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/04/2012 at 05:15, xxxxxxxx wrote:

    It's really a matter of using the BaseContainer of the object to access your AM parameters.  and using the values your get from there to edit or manipulate the geometry you create in GVO..

    so for example since you would be working from GVO,  you would get the basecontainer of your object by doing

    BaseContainer* bc = op->GetDataInstance();

    then if you want to access your attributes from there you would do something like,

    Real myParam = bc->GetReal(MY_PARAMETER_NAME);

    then let's say you wanted to manipulate the point count of your polygon,   you would do,

    PolygonObject* obj = PolygonObject::Alloc(myParam, myParam/4);

    in that way you could dynamically manipulate the polygonobject you are creating.

    :)

    ~Shawn



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/04/2012 at 19:24, xxxxxxxx wrote:

    Hi Shawn,
     
    thanks again! I've been able to get gui elements to do things which is great (though only simple things thus far). Customgui elements seem to be a bit more difficult, but I'm fumbling my way through them!
     
    I've started the GVO loop for the polys. But there's a bit of wind outside so I might have to go for a windsurf first and come back to it later!!!
     
    One thing I should ask though - if I'm drawing polys through GVO that are being obtained through the Tpolygon tag data, does my plugin need to be registered as an OBJECT_GENERATOR? Or can I just have OBJECT_POLYGON and OBJECT_POINT there?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/04/2012 at 01:33, xxxxxxxx wrote:

    It needs to be OBJECT_GENERATOR because you're generating a new object. You don't need OBJECT_POLYGONOBJECT or OBJECT_POINTOBJECT. In some cases, like the HyperNURBS or the Array object, you would also need OBJECT_INPUT indicating that the generator takes a child object and generates something from it.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/04/2012 at 02:20, xxxxxxxx wrote:

    Hm, I just did a few builds with just the GENERATOR but I can't seem to copy polygons over to it. It seems to only let me copy polys to it if I have the POLYOBJECT and POINTOBJECT in there as well. I'm guessing that it won't matter too much if they stay..?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 28/04/2012 at 03:58, xxxxxxxx wrote:

    Hi folks,
     
    my apologies for being such a pest about this. =)
     
    I've had a think about this GVO function stuff and the GENERATOR registration flag, and I think there's something I need to know a bit more about. 
     
    If I don't have the OBJECT_GENERATOR flag in the registration, then GVO won't run/work will it? If that's the case, then how does Cinema's editable polygon meshes work? They must not work through GVO? They don't have the green tick..? 
     
    Pest out...
     
    WP.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 28/04/2012 at 06:46, xxxxxxxx wrote:

    If the flag is not set, nothing will be generated (is my understanding). You have to distinguish between a parametric object, which has various parameters you can change like width, height, etc. and an editable polygon object.

    The C4D primitives are parametric objects which are generators - so in the Cube object, if you could see its source code, it would have OBJECT_GENERATOR set. But once you make it editable you lose the generator and it's just another poly object. These don't have the OBJECT_GENERATOR flag set.

    I've just written a very basic object generator as an example, and it and the accompanying tutorial will be on my site later today. I'll post a link here when done so you can see how it works.

    Steve



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 28/04/2012 at 09:43, xxxxxxxx wrote:

    Okay, this new tutorial is up on my site and you can find it at http://www.microbion.co.uk/graphics/c4d/create_plugins6.htm



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 29/04/2012 at 03:54, xxxxxxxx wrote:

    Hi Steve,
    firstly - thanks for the tutorial link. I hope you didn't rush that out for my part! There's some very useful and easy-to-understand info there. I'll spend a few days having a play, and to mix 'n' match things into my own experimental object. I'm already seeing parts that I can build on to utilise in my plugins! I suggest other capital N Newbies like myself out there take a look if you're following this thread.
     
    Second - going back to your first post of the latest two has got me wondering. You mention that primitives are parametric objects, which are in turn generator objects. What I'm trying to make however sounds like it's not a generator object, as what I'm trying to achieve is just a plain editable polygon object. If we use the cube as an example, instead of it being a Cinema parametric Ocube with fillet options etc, I want the cube to be just a plain editable polygon object (as if the Ocube has been made editable). That way I can use Cinema's modelling tools on it. I'll see if I can upload a video showing what my dilema is, it might explain it better than what my words can =)
     
    Thanks for the tutorial link again. Simple examples like these are very useful to turn too!
     
    WP.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 29/04/2012 at 05:46, xxxxxxxx wrote:

    Alrighty, here's a poorly made 1 minute video showing what happens when my plugin is in a scene. The link is one of those annoying download sites but I haven't got anywhere else to put it. For this one off it'll unfortunately have to do. I've never screen-captured or made a video downloadable before (oddly enough). Might have to consider YouTube uploads. Anyway, it should be enough to show visually inside Cinema where my plugin falls short, and may help to decipher what code elements I'm missing/needing.
     
    Polygon Display Video
     
    WP.


Log in to reply