Hi Marcus,

(First post 2006 ... Yay!)

Hi all! I hope you had a good holiday!

I'm having some problems merging chunk materials (more specifically, replacing one chunk with another).

This is what I do currently:

class MergeMaterialFunctor {
   ...
   void doEnter(ChunkMaterialPtr cm)
   ChunkMaterialPtr m_material;
}

void MergeMaterialFunctor::doEnter(ChunkMaterialPtr cm)
{
   const MFStateChunkPtr&  chunks = m_material->getChunks();
   const MFInt32&  slots = m_material->getSlots();

   CPEdit(cm, ChunkMaterial::ChunksFieldMask);
   for (unsigned int i = 0; i < chunks.size(); ++i) {
       int slot = i < slots.size() ? slots[i] : State::AutoSlotReplace;
       if (StateChunkPtr oldchunk = cm->find(chunks[i]->getType(), slot)) {
           cm->subChunk(oldchunk, slot);
       }
       cm->addChunk(chunks[i], slot);
   }
}

The problem is that the chunk returned by findChunk(), (that is, the oldchunk) sometimes (rarely, but repeatable) isn't found by subChunk(). It's probably a basic mistake, but I can't spot it and the chunk/slot-pairing semantics are a bit complex.

Can you try to add begin/endEditCP around the cm->subChunk and cm->addChunk perhaps this helps.

Any help welcome!

Best Regards,
/Marcus

P.S. In ChunkMaterial::find(), the ++index operation is inside the if-clause. Is that really correct?

No that's correct it is a special undocumented feature. If you have several chunks of the same type with a AutoSlotReplace slot in a material you can search these via index.

Example:

MaterialChunkPtr chunk1 = MaterialChunk::create();
TextureChunkPtr  chunk2 = TextureChunk::create();
BlendChunkPtr    chunk3 = BlendChunk::create();
TextureChunkPtr  chunk4 = TextureChunk::create();
TextureChunkPtr  chunk5 = TextureChunk::create();

ChunkMaterialPtr cm = ChunkMaterial::create();
beginEditCP(cm);
    cm->addChunk(chunk1);
    cm->addChunk(chunk2, 3);
    cm->addChunk(chunk3);
    cm->addChunk(chunk4);
    cm->addChunk(chunk5);
endEditCP(cm);

Now finding the texture chunk in slot 3 works as expected.

chunk2 == cm->find(TextureChunk::getClassType(), 3);

If you want to find a specific chunk with a AutoSlotReplace slot, the slot parameter is interpreted as a index.

chunk4 == cm->find(TextureChunk::getClassType(), 1);
chunk5 == cm->find(TextureChunk::getClassType(), 2);

Andreas


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to