Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Copy properties and groups from one blueprint to another
#5
(31-08-2022, 08:47 AM)jbordas Wrote: Hi jose , I have the exact same problem right now, would it be possible to get a copy of the information you sent to nexar ?

Thank you.

Hi there,

Assuming both blueprint have the *exact* same topology (vertex count and triangle connectivity are identical) copying data is just a matter of iterating trough all particle arrays, constraint batches, and optionally particle groups:

Code:
// Copy particle data, except for positions, orientations and velocities:
for (int i = 0; i < blueprint.particleCount; ++i)
{
  blueprint.invMasses[i] = sourceBlueprint.invMasses[i];
  blueprint.phases[i] = sourceBlueprint.phases[i];
  blueprint.restPositions[i] = sourceBlueprint.restPositions[i];
  blueprint.principalRadii[i] = sourceBlueprint.principalRadii[i];
  blueprint.colors[i] = sourceBlueprint.colors[i];
}

// copy distance constraint batches. Other constraint types are copied in the exact same way, except that the data arrays are different depending on the type (check the API documentation for details).
for (int i = 0; i < blueprint.distanceConstraintsData.batches.count; ++i)
{
  var batch = blueprint.distanceConstraintsData.batches[i];
  var sourceBatch = sourceBlueprint.distanceConstraintsData.batches[i];
  for (int j = 0; j < batch.restLengths.count; ++j)
    batch.restLengths[j] = sourceBatch.restLengths[j];
  for (int j = 0;j < batch.stiffnesses.count; ++j)
    batch.stiffnesses[j] = sourceBatch.stiffnesses[j];
}

// copy particle groups:
blueprint.ClearParticleGroups();
for (int i = 0; i < sourceBlueprint.particleGroups.Count; ++i)
{
  var group = blueprint.AppendNewParticleGroup(sourceBlueprint.particleGroups[i].name);
  for (int j = 0; j < sourceBlueprint.particleGroups[i].particleIndices.Count;++j)
  {
    group.particleIndices.Add(sourceBlueprint.particleGroups[i].particleIndices[j]);
  }
}
Reply


Messages In This Thread
RE: Copy properties and groups from one blueprint to another - by josemendez - 31-08-2022, 08:57 AM