Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search

CSTO and materials

Author
Message
  Topic Search Topic Search
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Topic: CSTO and materials
    Posted: 2017 Dec 19 at 6:00am
In my CSTO function I use a new document to copy my object to.
However, when I do so, the materials used are not copied to the new document and thus the result of the CSTO has no material information, displaying a question mark.

What can i do in order not to loose the material information.

        newDoc = c4d.documents.BaseDocument()
        newDoc.InsertObject(obj)

        objList = c4d.utils.SendModelingCommand(
            command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,
            list = [obj],
            mode = c4d.MODELINGCOMMANDMODE_ALL,
            doc = newDoc,
            flags = c4d.MDATA_CURRENTSTATETOOBJECT_INHERITANCE)

        if objList == False:
            print "error CSTONewDoc."
                    
        obj.Remove() 

Back to Top
gr4ph0s View Drop Down
Member
Member


Joined: 2015 Jul 07
Location: France
Online Status: Offline
Posts: 437
Direct Link To This Post Posted: 2017 Dec 19 at 6:05am
Technical lover.
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2017 Dec 19 at 7:06am
So, I use it to copy my object to a new document and using that document i do a csto.

After that, do I have to copy (how) the resulting object back to my original document?

The code below gives me still the question marks, indicating that the materials were not found.

        newDoc = c4d.documents.IsolateObjects(doc, [obj])
        
        objList = c4d.utils.SendModelingCommand(
            command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,
            list = [obj],
            mode = c4d.MODELINGCOMMANDMODE_ALL,
            doc = newDoc)
            #flags = c4d.MDATA_CURRENTSTATETOOBJECT_INHERITANCE)
        if objList == False:
            print "error CSTONewDoc."
                    
        obj.Remove() 
return objList[0]



Edited by pgrooff - 2017 Dec 19 at 7:17am
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1143
Direct Link To This Post Posted: 2017 Dec 20 at 5:20am
Hi Pim,

Where are you using the posted code? Inside GetVirtualObjects()? What's obj in it?

If a temporary document is created for CSTO then the command loses track of the materials.
And IsolateObjects() copies the passed object so you don't know the object that has to be used for CSTO.

It is recommended to pass a clone of the object to apply CSTO on. So you can pass obj.GetClone().
The document for CSTO can simply be obj's document - obj.GetDocument().
CSTO should keep materials with these changes.


Note SendModelingCommand() flags parameter only accepts either MODELINGCOMMANDFLAGS_0 or MODELINGCOMMANDFLAGS_CREATEUNDO.
The settings for a modeling command have to be passed to bc parameter.



MAXON
Developer Support
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2017 Dec 20 at 5:49am
Hi Yannick,

Yes it is inside GetVirtualObjects() and after GetAndCheckHierarchyClone().

Obj is a null with a smoothing deformer en a polygon object as child's.
The polygon object has a texture tag and a weight tag.

I do not fully understand your sentence
"It is recommended to pass a clone of the object to apply CSTO on. So you can pass obj.GetClone().
The document for CSTO can simply be obj's document - obj.GetDocument().
CSTO should keep materials with these changes."

- I do not see a difference when using a clone, but I will try again.
- If I use the current document, obj.GetDocument(), the weight setting in the smoothing deformer is lost.
If I use a new document, the weight setting in the smoothing deformer is ok.
But then the material is lost due the new document.

That is why I want to know how to keep the mat information when using csto and e new document.

-Pim
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1143
Direct Link To This Post Posted: 2017 Dec 21 at 3:26am
Hi Pim,

Ok, I believe you use the code posted in the other thread Vertex map is not correctly filled?

You can't get both the weight and material shown as expected.
The vertex map is created on a cache object and is not part of the document, while the material is.

So the solution is to add the vertex map to the child's polygon object of your generator, instead of creating it virtually.
Also this way it would give more freedom to define the vertex map, for instance with the Paint Tool.


And about passing a clone to CSTO, you're right it's not needed.



MAXON
Developer Support
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2017 Dec 21 at 3:33am
Sorry, I do not fully understand.

I am adding the vertex weight to the polygon object.
Then I copy this weight tag into the Stiffness map field of the Smoothing deformer object.
Both are placed under a Null and that null must be CSTOed.

Could you give an example?

- Pim

Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1143
Direct Link To This Post Posted: 2017 Dec 21 at 8:43am
Originally posted by Yannick Puech

Hi Pim,
So the solution is to add the vertex map to the child's polygon object of your generator, instead of creating it virtually.
I mean the vertex map should be manually added to the generator's child, not virtually to the child's clone inside GetVirtualObjects().
Then access the vertex map with GetTag() on the child from GetVirtualObjects().
Finally CSTO should be performed with the generator's document, not with a temporary one. 

This changes the workflow but is there a strong reason to generate the vertex map inside your generator?



MAXON
Developer Support
Back to Top
pgrooff View Drop Down
Member
Member


Joined: 2010 Nov 05
Online Status: Offline
Posts: 817
Direct Link To This Post Posted: 2017 Dec 21 at 9:13am
Ok, i see, but yes, the vertex map is generated inside getvirtualobjects().
IT is based on csto’s Before.
The generator can hold numerous children.

But if this is the only way, then we must think about the workflow.

Thanks, Pim

Back to Top

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.