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

    Make editable an object generated by GetVirtualObjects()

    Cinema 4D SDK
    python
    3
    19
    2.6k
    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.
    • ferdinandF
      ferdinand
      last edited by ferdinand

      Hi,

      no need to be sorry, I am / was not offended. I was just trying to be very clear about the implications of your approach.

      1. If you want to have a statically generated object, ObjectData is not the correct base class for you, as its whole purpose is to provide a dynamically generated object when you overwrite GVO.
      2. Loading an object from a preset file is quite an unusal thing to do for the ObjectData type. The more common thing to do, would be to construct your rig procedurally within your GVO. Which would probably also (apart from performance benefits) alleviate the problems you have shown in the video.
      3. Also noteworthy is, that a python scripting tag also calls the draw() function of your script, which you could use to draw / react to to handles with your original xpresso and user data steup.

      Cheers
      zipit

      MAXON SDK Specialist
      developers.maxon.net

      mfersaouiM 1 Reply Last reply Reply Quote 1
      • mfersaouiM
        mfersaoui @ferdinand
        last edited by mfersaoui

        @zipit
        Hi,
        Thank you, I'm trying to rebuild all my rig inside the GVO and I think I will using C++.
        is it better to use c++?

        Cheers
        Mustapha

        ferdinandF 1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand @mfersaoui
          last edited by

          Hi,

          @mfersaoui said:

          is it better to use c++?

          I think the answer to that is highly subjective. Both SDKs and languages have their strengths. As your plugin probably is neither going to be computationally expensive, nor will be in need of any of the more advanced features only the C++ SDK does offer, I would say, Python wins this cost/gain comparison by a long shot.

          But that is subjective 😉

          Cheers
          zipit

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 0
          • S
            s_bach
            last edited by s_bach

            Hello,

            just to make some things clear:

            • The purpose of GetVirtualObjects() is to fill a cache with virtual objects.
            • It is NOT the purpose of GetVirtualObjects() to modify the document / the scene graph.
            • It is forbidden to edit the scene graph from within the scene execution pipeline e.g. from within GetVirtualObjects().
            • One must only edit the scene graph in reaction to some user interaction e.g. after the user pressed some button in the UI or used a tool.
            • One must never call GetActiveDocument() in a NodeData based function. The active document is the document currently displayed in the viewport; but there is no reason to think that this is the document that hosts the object.
            • Consequentially, one must never call EventAdd() in a NodeData based function; especially not from within the execution pipeline.
            • If you want your generator to load a given scene file, you can load that scene with LoadDocument() and just COPY the content into the cache.
            • The Python API is an incomplete wrapper around the C++ API. So some functions may be missing in the Python API.

            best wishes,
            Sebastian

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            mfersaouiM 2 Replies Last reply Reply Quote 1
            • mfersaouiM
              mfersaoui @s_bach
              last edited by

              @s_bach said in Make editable an object generated by GetVirtualObjects():

              GetVirtualObjects()

              Hello,
              Thank you, I decided to use C++ to do that, I just post new topic "MAXPORTS GraphView Flags - Description Resource" is a continuity of this topic.

              1 Reply Last reply Reply Quote 0
              • mfersaouiM
                mfersaoui @s_bach
                last edited by

                @s_bach said in Make editable an object generated by GetVirtualObjects():

                LoadDocument()

                Hello,
                I gave up the idea to merge objects from scene file, I had generate my object and all her sub-objects inside the GetVirtualObjects(). But now I'm searching how to assign materials to my sub-objects, I would imagine that is the same as objects, should I use the LoadDocument()? if yes are there examples? and then can I change these materials proprieties from the object description resource or I must to use CommandData dialog?
                Thank you.

                1 Reply Last reply Reply Quote 0
                • S
                  s_bach
                  last edited by

                  Hello,

                  a generator (GetVirtualObjects()) cannot create materials. You must generate materials in reaction to user-interaction (Material Manual). Then you can assign materials to your (virtual) objects using a TextureTag (TextureTag Manual).

                  for example, you could detect when your generator object is created from the UI by listening to the MSG_MENUPREPARE message in NodeData.Message(). Then you can create all the materials you want to use later.

                  best wishes,
                  Sebastian

                  MAXON SDK Specialist

                  Development Blog, MAXON Registered Developer

                  mfersaouiM 1 Reply Last reply Reply Quote 2
                  • mfersaouiM
                    mfersaoui @s_bach
                    last edited by mfersaoui

                    @s_bach
                    Hello,
                    Thank you, As you explained, I create all materials in NodeData.Message() and then I called them in the GVO. I just want to know if is it allowed to edit the called material parameters inside the GVO or not? see example bellow:

                    BaseObject* MyObject::GetVirtualObjects(BaseObject* op, HierarchyHelp* hh) {
                            ...
                            BaseObject* container = BaseObject::Alloc(Onull);
                    	if (!container)
                    		return BaseObject::Alloc(Onull);
                    
                    	container->SetName("Container");
                    
                    	BaseMaterial* material = doc->SearchMaterial("my_material");
                    	if (material) {
                    		// create the texture tag
                    		TextureTag* const textureTag = static_cast<TextureTag*>(container->MakeTag(Ttexture));
                    		if (textureTag == nullptr)
                    			return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
                    
                    		const Float Brightness = data->GetFloat(MYOBJECT_LIGHT_INTENSITY);
                    		
                    		// Is the following action allowed inside GVO:
                    		material->SetParameter(DescID(MATERIAL_LUMINANCE_BRIGHTNESS), Brightness, DESCFLAGS_SET_0);
                    
                    		textureTag->SetMaterial(material);
                    	}
                            ...
                    }
                    

                    Best,
                    Mustapha

                    mfersaouiM 1 Reply Last reply Reply Quote 0
                    • mfersaouiM
                      mfersaoui @mfersaoui
                      last edited by mfersaoui

                      I think this is not allowed. I've just seen the list of the Forbidden Functions and "Make any changes to materials." is inside.

                      1 Reply Last reply Reply Quote 0
                      • S
                        s_bach
                        last edited by

                        Hello,

                        as said before, it is not the purpose of GetVirtualObject() to edit the scene or to edit elements of the scene; this includes materials.

                        MAXON SDK Specialist

                        Development Blog, MAXON Registered Developer

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