Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Set Xray in GetVirtualObjects()

    Cinema 4D SDK
    3
    6
    689
    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.
    • RenatoTR
      RenatoT
      last edited by RenatoT

      Hi all, i'm trying to generate an XRAY pyramid inside the GetVirtualObjects() without luck.
      Here my source code:

      		BaseObject* pyramid = BaseObject::Alloc(Ocone);
      		if (pyramid) {
      			BaseContainer* cone_bc = pyramid->GetDataInstance();
      			const Float pyra_height = 0.75;
      			const Vector v1 = Vector(0.0, 1.0, 0.0);
      			const Vector v2 = Vector(1.0, 0.0, 0.0);
      			const Vector v3 = Vector(0.0, 0.0, 1.0);
      			const Vector center = bot_pos + Vector(0.0, pyra_height, 0.0);
      
      			const Matrix mg = Matrix(center, v2, v1, v3);
      			pyramid->SetMg(mg);
      
      			cone_bc->SetFloat(PRIM_CONE_TRAD, mid_lower * supp_scale);
      			cone_bc->SetFloat(PRIM_CONE_BRAD, mid_lower * 2.0 * supp_scale);
      			cone_bc->SetFloat(PRIM_CONE_HEIGHT, pyra_height);
      			cone_bc->SetFloat(PRIM_CONE_HSUB, 1);
      			cone_bc->SetFloat(PRIM_CONE_SEG, subdivision);
      
      			cone_bc->SetBool(PRIM_CONE_CAPS, true);
      			cone_bc->SetInt32(PRIM_CONE_CSUB, 1);
      			cone_bc->SetInt32(PRIM_CONE_FSUB, fstep);
      
      			// Try to set Xray ---------------------------
      			ObjectColorProperties prop;
      			pyramid->GetColorProperties(&prop);
      			prop.xray = true;
      			pyramid->SetColorProperties(&prop);
      			pyramid->SetParameter(ID_BASEOBJECT_XRAY, GeData(TRUE), DESCFLAGS_SET_0);
      			pyramid->Message(MSG_UPDATE); 
      
      			// Try also with Container -------------------
      			cone_bc->SetBool(ID_BASEOBJECT_XRAY, true);
      			
      			doc->InsertObject(pyramid, ret, nullptr);
      		}
      

      Thanks in advance
      Renato T.

      1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn
        last edited by

        I just checked with a Python generator, and it works, so at least it is not a general problem in virtual objects

        def main():
            pyramid = c4d.BaseObject(c4d.Ocone)
            if pyramid == None: return None
            pyramid[c4d.PRIM_CONE_SEG] = 4
            pyramid[c4d.ID_BASEOBJECT_XRAY] = True
        
            return pyramid
        

        (but maybe I don't get your code; why are you inserting the object into the doc instead of returning it? I may be looking for the wrong context here)

        1 Reply Last reply Reply Quote 0
        • RenatoTR
          RenatoT
          last edited by RenatoT

          Thanks Cairyn for the test.

          Yes, is a right question 🙂 ... let me check.

          1 Reply Last reply Reply Quote 0
          • RenatoTR
            RenatoT
            last edited by

            Ok, I miss to use OBJECT_USECACHECOLOR. I found it on this older post:
            https://developers.maxon.net/forum/topic/6674/7275_setting-xray-for-virtual-objects/8

            1 Reply Last reply Reply Quote 0
            • r_giganteR
              r_gigante
              last edited by

              Hi @RenatoT thanks for reaching out us.

              By looking at the code it's clear that your intent is to change the visual appearance of a portion of the cache and this can only be done registering the ObjectData with OBJECT_USECACHECOLOR. This, at the same time, comes with the drawback that the user can't change anything about the visual appearance of the object from AM.

              Different could be to set the ID_BASEOBJECT_XRAYparameter's value intercepting the MSG_MENUPREPARE but in this case, while the user retains the option to change the visual appearance, the whole geometry of the cache is affected.

              	def GetVirtualObjects(self, op, hh):
              		res = c4d.BaseObject(c4d.Osphere)
              		if res is not None:
              			pyramid = c4d.BaseObject(c4d.Ocone)
              			if pyramid is not None:
              				pyramid.InsertUnder(res)
              
              		return c4d.BaseObject(c4d.Onull)
              
              	def Message(self, node, type, data):
              		if type==c4d.MSG_MENUPREPARE:
              			node[c4d.ID_BASEOBJECT_XRAY] = True
              		return True
              

              Last but not least, be aware that you're misusing the BaseDocument::InsertObject(): for the scope of inserting the pyramid under the object returned by the ObjectData::GetVirtualObjects() it's more appropriate to use GeListNode::InsertUnder()

              Cheers, R

              1 Reply Last reply Reply Quote 0
              • RenatoTR
                RenatoT
                last edited by

                Thanks R, the insert was an error, i already corrected. OBJECT_USECACHECOLOR work as expected 🙂

                Cheers
                Renato

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