Python Generator + Phong Tag



  • On 07/11/2017 at 14:48, xxxxxxxx wrote:

    Hi,

    I'm stumbling a bit over a new problem. :)  I'm using a Python Generator to generate a polygon object. It all works well and the object's mesh is nicely generated. The only problem I have is that the object doesn't seem to have a proper Phong setup. Adding the Phong tag to the "Python Generator" object doesn't do anything.

    import c4d
      
    def main() :
        
        # [cut] 
        # ... some working code...
        # [cut]
    	
        polyobj = c4d.BaseObject(c4d.Opolygon)
        polyobj.ResizeObject(vertexcnt,polycnt)
      
        # [cut]  
        #  ... some more working code here (polyobj.SetPoint() and .SetPolygon() calls)
        # [cut]
      
        polyobj.SetPhong(True, True, c4d.utils.Rad(80))
        
        return polyobj
    

    After quite some searching I found out about the SetPhong() function. Adding it (see above code) seems to fix the visuals at least (the object now as a proper Phong setup), but the added Phong tag still doesn't do a thing.

    How would one add proper handling of the Phong tag in this situation? Do I need to manually look up the tag, read its options and apply those values via the SetPhong method? Or is there a better recommended method?



  • On 08/11/2017 at 02:48, xxxxxxxx wrote:

    Hi,

    as the result of the Python Generator you are basically returning the cache of the generator. This is not visible or accessible in the Object Manager. So the Phong tag you create on the resulting object does it's work, but it is not in any way related to the Phong tag visible on the Python generator.

    But you could do something like this:

    def main() :
        phong = op.GetTag(c4d.Tphong) # check for phong tag on python generator
        if phong is None:
            phong = op.MakeTag(c4d.Tphong) # create one, if non-existent (careful with such operations, make sure, the tag is only created once)
        result = c4d.BaseObject(c4d.Osphere)
        if phong is not None:
            result.InsertTag(phong.GetClone()) # important to insert a clone of the original phong tag
        return result
    

    Or you keep your code and just set the angle from the Phong tag created on the Python generator.



  • On 09/11/2017 at 08:57, xxxxxxxx wrote:

    Thanks! Yes, this seems to work nicely as workaround. Of course, it's now impossible to delete the tag (though not a real practically problem since one can disable the Phong via the tag itself :) )

    On a related note I also noticed that this "Python Generator" object is completely ignorant of any kind of dynamics, e.g. adding a "Rigid Body" tag to it does nothing in regards to collision handling (the object is still affected by gravity though).

    I'm currently in the process of converting everything into an actual external plugin for the fun of it (also should fix the dynamics problem). A whole lot new to learn and tons of new questions. I'm getting there! :)

    Ideally I want it to act like a normal primitive ("Cube", "Sphere", etc.) in the end: when the user adds the object to the scene it should get a default "Phong" tag which the object reacts on properly; but the user should also be able to freely delete it, if wanted. The "Py-RoundedTube" example doesn't seem to support this either. I'll see how it goes (currently need to solve some other things first ;) ) and then report back.


Log in to reply