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

    Retrieving particle positions for Multi-Instance

    Cinema 4D SDK
    c++ r20
    2
    3
    647
    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.
    • P
      peterakos
      last edited by

      Hello.

      I need to retrieve the particle positions from the object used in INSTANCEOBJECT_MULTIPOSITIONINPUT parameter of Multi-Instance.

      The documentation says it supports Mograph Matrix, Emitter and Thinking Particles.
      I retrieve the positions from Mograph Matrix using ID_MOTAGDATA tag.

      How can I do the same with Emitter and Thinking Particles ?

      Thank you for your time !

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by Manuel

        hello,

        so you want to retrieve the positions of particles (from particles object or TP) ?

        About Thinking Particles you have information here, don't forget to use InitThinkingParticles before using it.

        For Particles Object you have this page and this is pretty straight forward.

        For example :

                // Retrieves Particles Object
        
        	BaseObject *selObj = doc->GetActiveObject();
        	
        	
        	if (selObj == nullptr || !selObj->IsInstanceOf(Oparticle))
        	{
        		MessageDialog("Need to select a particle object"_s);
        		return maxon::OK;
        	}
        
        
        	// cast object to ParticleObject
        	ParticleObject* partObj = static_cast<ParticleObject*>(selObj);
        	if (partObj == nullptr)
        		return maxon::NullptrError(MAXON_SOURCE_LOCATION);
        
        	const maxon::Int32 cnt = partObj->GetParticleCount();
        
        	// Retrieves the particle tag that is invisible.
        	ParticleTag* partTag = static_cast<ParticleTag*>(partObj->GetTag(Tparticle));
        
        	for (maxon::Int32 i = 0; i < cnt; i++)
        	{
        		const Particle* myParticle = partObj->GetParticleR(partTag, i );
        		// Check particle's age before output position
        		if (myParticle->t > 0)
        			DiagnosticOutput("particle position @ have age @", myParticle->off, myParticle->t);
        	}
        
        
        	
        	// Creates particles in TP
        
        	// Retrieves the TP Master
        	BaseSceneHook* hook = doc->FindSceneHook(ID_THINKINGPARTICLES);
        	if (hook == nullptr || hook->GetType() != ID_THINKINGPARTICLES)
        		return maxon::NullptrError(MAXON_SOURCE_LOCATION);
        
        	TP_MasterSystem* tpmaster = static_cast<TP_MasterSystem*>(hook);
        
        	if (tpmaster == nullptr)
        		return maxon::NullptrError(MAXON_SOURCE_LOCATION);
        
        	// Alloc 10 particles 
        	maxon::Int32 ids[10];
        
        	if (tpmaster->AllocParticles(10, ids) == NOTOK)
        		return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
        
        	// Changes position of particles and retrieves it to output it.
        	for (auto pid : ids)
        	{
        		tpmaster->SetPosition(pid, Vector(pid * 50));
        		Vector pos = tpmaster->Position(pid);
        		DiagnosticOutput("position of particle @ is @", pid, pos);
        	}
        
        
        	EventAdd();
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 2
        • P
          peterakos
          last edited by

          Thank you for your help !

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