Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Copy properties and groups from one blueprint to another
#1
Bombilla 
Hi Jose,

I'm writing to you again, because we have this situation:

We have an original 3D mesh with blendshapes and its blueprint configured (with its own properties and particle groups).

At one point the blendshapes change once, and then we bake the mesh with the updated blendshapes, to have the "updated baked mesh".

With this baked mesh we generate its new blueprint, which has exactly the same number of particles as the original blueprint.


Code:
bakedMesh = new Mesh();
originalMesh.BakeMesh(bakedMesh);

AssetDatabase.CreateAsset(bakedMesh, "Assets/bakedMesh.asset");
AssetDatabase.SaveAssets();

blueprint.inputMesh = bakedMesh;

yield return updatedBlueprint.Generate();

[Image: blueprint_obi.jpg]

How can we copy each property and particle group from the original blueprint to the new generated blueprint?

What is the right way to achieve this at runtime using scripts?

How should we go through the list of particles of the original blueprint, to read and copy each property and group?

Should we first generate the new blueprint for the updated baked mesh, and then edit the property and group of each particle?

We would appreciate your help in doing this.

Thanks in advance!

PD: Le agradeceremos muchísimo si por favor nos respondiera pronto, pues es lo único que nos falta para terminar el proyecto.
Reply
#2
Hi! I believe I just answered your original email, check it out and let me know if you have more questions.
Reply
#3
Bombilla 
Thank you very much for your rapid response, and for your kind willingness to help us.
We have found your response very helpful, as we did not know how to unlock this... Sonrisa Idea

We have sent you another e-mail with questions about how to save the generated blueprint in a different file, and about the correct way to reassign the new blueprint to the "SkinnedCloth" component, and force it to be reloaded.

Thanks in advance for your help!

Best regards!

PD: Nuevamente le agradeceremos poder recibir pronto su respuesta, pues esto es lo último que nos falta para terminar.  Gran sonrisa
Reply
#4
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.
Reply
#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
#6
(31-08-2022, 08:57 AM)josemendez Wrote: 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]);
  }
}

Thank you very much ! I'll try this out !
Reply