Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Detecting direction of travel: Live?

    Scheduled Pinned Locked Moved SDK Help
    7 Posts 0 Posters 702 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

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

      On 26/03/2012 at 09:23, xxxxxxxx wrote:

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

      ---------
      I've been trying to figure out how to detect which direction a vertice is being dragged while sitting at frame zero. And not having much luck.

      The method I normally use of storing the previous vector position in a global variable is not working in this case. Because I'm not moving the timeline. And have no keys to use as a comparison.
      Because this is live polling done at frame zero. Every attempt I come up with using a temp variable to hold the previous point positions is being overwritten as fast as it it changes. And failing.

      Does anyone have any idea how to do this?

      -ScottA

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        On 26/03/2012 at 11:31, xxxxxxxx wrote:

        wouldn't work something like this ?

        real cache
          
        bool threshold (real value, real min)
        	if (cache == None) :
        		cache = value
        		return False
        	elif  (value - min < cache) :
        		cache = value
        		return True
        	else :
        		return False
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          On 26/03/2012 at 12:09, xxxxxxxx wrote:

          I'm not sure.
          I'm not using the ray collider. So I don't know.

          The main problem I'm having is that the vectors I save get overwritten when I don't want them to.
          With the timeline I have a means to stop recording the vectors. Then compare where they were vs. where they currently are. But without it the code runs all the time and my saved vectors are immediately overwritten and I have no old vectors to compare the current vectors to.

          I'm thinking maybe the left mouse down event might be a possible way to get around that problem. but not sure.
          This is one of those programming tongue twisters that I'm not experienced enough to figure out on my own.

          -ScottA

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

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

            On 26/03/2012 at 13:17, xxxxxxxx wrote:

            threshold is not meant to use ray collider, it is meant to limit the changes of the cache of your vector.
            unless the difference between mouse position and the cache isn't bigger than the threshold ignore
            the new value. if it is, do something with cache and the current value and then set the cache to 
            current value.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

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

              On 26/03/2012 at 14:10, xxxxxxxx wrote:

              Oh I see. It's custom method with the name threshold.
              Threshold is in he SDK and that's what confused me.
              I've tried using cache and dirty also. But the same problem occurs as if I lust try to save old position data to a variable. It gets updated upon the next cycle of the code. Becoming useless.

              Here's what I'm trying to do:
              I want to move a vertice on an object. Then determine what direction(x,y,z) it's being moved in.
              Once I've determined the direction. I want to toggle the menu's X,Y,Z locked options. Depending on that information.
              Since menu items can't be toggled from a tag plugin. I decided to try to do this from a Message plugin.
              Since a message plugin runs continuously. Any time I save the position of a vertice. whether through a variable or through the cache. That data gets set equal to the current position of the vertice the next time the code run through it's next pass.

              -I can get the selected vertice and it's position of the object just fine
              -I can toggle the menu items how I need them just fine
              But I can't figure out how to get the direction the vertice is being moved under this scenario. Because the Message plugin updates anything I try to use to hold the old vertice position data.

              -ScottA

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

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

                On 26/03/2012 at 20:08, xxxxxxxx wrote:

                I'd store the position of the point upon selection.

                Here's a quick test using a Python Tag with 'Reset on frame 0' unchecked. The same approach should work with a C++ plugin and member variables.

                ----------------------------------
                import c4d

                indexPrev = 0
                bsCntPrev = 0
                posStored = 0

                def main() :
                    global indexPrev, bsCntPrev, posStored
                    
                    obj = op.GetObject()
                    bs = obj.GetPointS()
                    bsCnt = bs.GetCount()   
                    
                    if bsCnt is not 1: return

                pointCnt = obj.GetPointCount()    
                    index = 0
                    
                    for x in xrange(pointCnt) :
                        if bs.IsSelected(x) : index = x
                       
                    points = obj.GetAllPoints()   
                    pos = points[index]
                    
                    if bsCnt is 1 and (bsCnt is not bsCntPrev or index is not indexPrev) :
                        posStored = pos
                       
                    indexPrev = index
                    bsCntPrev = bsCnt
                    
                    print "pos", pos
                    print "posStored", posStored
                ----------------------------------

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

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

                  On 26/03/2012 at 22:34, xxxxxxxx wrote:

                  Thanks David.
                  That's exactly the kind of thing I was looking for. I just changed it a little bit to work dynamically for any selected vertice.

                  Here's how I used it in my Message plugin:

                  posStored = c4d.Vector(0)     #Holds the vector value before it was moved by the user  
                  isSelPrev = False             #Used as a toggle  
                    
                  class MyMessage(plugins.MessageData) :  
                    
                  # This is neccessary since expressions are not allowed to call commands directly.  
                      
                    def CoreMessage(self,id,bc) :  
                    
                        global isSelPrev, posStored  
                        index = 0                      #This will eventually hold the index# of the selected point      
                      
                        doc = c4d.documents.GetActiveDocument()       
                        if not doc: return False  
                    
                        obj = doc.GetActiveObject()  
                        if not obj: return False                               #Error handling  
                        if obj.CheckType(c4d.Opolygon)==False: return False    #Error handling  
                        points = obj.GetAllPoints()  
                        pcount = obj.GetPointCount()  
                        bs = obj.GetPointS()  
                        for i in xrange(pcount) :  
                            if bs.IsSelected(i) :        #Look for selected points   
                                index = i               #Get the selected point's index#   
                    
                        selected = bs.IsSelected(index) #True/False depending if a point is selected  
                        pos = points[index]             #Gets the vector position of the selected point  
                      
                    
                        #If a point is selected so that "selected's" boolean value is True...  
                        #Set the posStored variable to current point's vector position  
                        if selected is True and selected is not isSelPrev:  
                            posStored = pos  
                         
                        isSelPrev = selected   #Toggles value from False to True  
                    
                        if pos.x != posStored.x:   
                            if c4d.IsCommandChecked(12154) : c4d.CallCommand(12154) #Y-Axis  
                            if c4d.IsCommandChecked(12155) : c4d.CallCommand(12155) #Z-Axis  
                    
                    
                        #...Do the other statements for Y and Z   
                    
                    
                       return True
                  

                  This is my first message plugin. But the SDK doesn't really explain how to use them in different scenarios. Especially one like I'm doing.
                  They're always on. Which not a good thing in this case. And I'd like to be able to turn it off/on like other plugin types.
                  The only reason I even went this route is because we can't toggle menu items from a tag or tool plugin(that's a horrible limitation). But it feels like a horrible hack job doing it this way.

                  I hope things like this are explained better in the future SDK's.
                  This just seems like the wrong way to do things.

                  -ScottA

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post