Hello José,
Again, we are very grateful for your help, because thanks to that we have almost ready the project.
But, we have this problem:
We are working with SkinnedCloth, and we need to copy all the properties seted on the original SkinnedClothBlueprint to a new SkinnedClothBlueprint that we generate by code, considering as inputmesh a bakedmesh of the same original mesh with applied blendshapes.
To copy all the properties of the reference SkinnedClothBlueprint to the new one (except the positions, rotations, and speeds), we have done this:
However, although we can generate correctly a new file of a SkinnedClothBlueprint, in the practice it is as if the properties of Skin were not being applied.
If we manually generate and edit the SkinnedClothBlueprint with the same properties, it works well, but when we create it with this code, it does not work as it should.
1) Is there anything that we are missing to copy all the properties of SkinnedClothBlueprint to the new one (except the positions, rotations, and speeds)?
2)- Is it necessary to update/re-calculate somehow the blueprint, after having modified its properties?
3) Is there a more efficient way to copy all the properties of a SkinnedClothBlueprint to a new one (except the positions, rotations, and speeds), but for a new bakedmesh as inputmesh?
4) Or do we have to use the "Bake Mesh" method from the Obi Skinned Cloth Renderer, to get a mesh with the skin?
5) We have realized that, if we just change the blendshapes of the SkinnedMeshRenderer component by code (even without modifying the original blueprint), even if it has the ObiSkinnedCloth component, we achieve what we wanted. Is there any problem in doing this once at the beginning of the program?
Thanks in advance!
PD: Le hemos enviado por e-mail estas mismas consultas. Muchas gracias por su ayuda al respecto!
Again, we are very grateful for your help, because thanks to that we have almost ready the project.
But, we have this problem:
We are working with SkinnedCloth, and we need to copy all the properties seted on the original SkinnedClothBlueprint to a new SkinnedClothBlueprint that we generate by code, considering as inputmesh a bakedmesh of the same original mesh with applied blendshapes.
To copy all the properties of the reference SkinnedClothBlueprint to the new one (except the positions, rotations, and speeds), we have done this:
Code:
public void BP_Process()
{
StartCoroutine(CopySkinnedClothBlueprint());
}
public IEnumerator CopySkinnedClothBlueprint()
{
skinnedBlueprintFinal = ScriptableObject.CreateInstance<ObiSkinnedClothBlueprint>();
// Creating a baked mesh with Blendshapes applied
bakedMesh = new Mesh();
meshReferencia.BakeMesh(bakedMesh);
AssetDatabase.CreateAsset(bakedMesh, "Assets/SkinnedClothBakedMesh.asset");
AssetDatabase.SaveAssets();
skinnedBlueprintFinal.inputMesh = bakedMesh;
yield return skinnedBlueprintFinal.Generate();
// Copying particles (except positions, rotations, and velocities)
for (int i = 0; i < skinnedBlueprintFinal.particleCount; ++i)
{
skinnedBlueprintFinal.invMasses[i] = skinnedBlueprintReferencia.invMasses[i];
skinnedBlueprintFinal.principalRadii[i] = skinnedBlueprintReferencia.principalRadii[i];
skinnedBlueprintFinal.phases[i] = skinnedBlueprintReferencia.phases[i];
skinnedBlueprintFinal.colors[i] = skinnedBlueprintReferencia.colors[i];
}
////// BEGIN COPYING CONSTRAINTS
// Distance
for (int i = 0; i < skinnedBlueprintFinal.distanceConstraintsData.batches.Count; ++i)
{
var batch = skinnedBlueprintFinal.distanceConstraintsData.batches[i];
var sourceBatch = skinnedBlueprintReferencia.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];
}
// Bend:
for (int i = 0; i < skinnedBlueprintFinal.bendConstraintsData.batches.Count; ++i)
{
var batch = skinnedBlueprintFinal.bendConstraintsData.batches[i];
var sourceBatch = skinnedBlueprintReferencia.bendConstraintsData.batches[i];
for (int j = 0; j < batch.restBends.count; ++j)
batch.restBends[j] = sourceBatch.restBends[j];
for (int j = 0; j < batch.bendingStiffnesses.count; ++j)
batch.bendingStiffnesses[j] = sourceBatch.bendingStiffnesses[j];
}
// Pin:
for (int i = 0; i < skinnedBlueprintFinal.pinConstraintsData.batches.Count; ++i)
{
var batch = skinnedBlueprintFinal.pinConstraintsData.batches[i];
var sourceBatch = skinnedBlueprintReferencia.pinConstraintsData.batches[i];
for (int j = 0; j < batch.pinBodies.count; ++j)
batch.pinBodies[j] = sourceBatch.pinBodies[j];
for (int j = 0; j < batch.offsets.count; ++j)
batch.offsets[j] = sourceBatch.offsets[j];
for (int j = 0; j < batch.restDarbouxVectors.count; ++j)
batch.restDarbouxVectors[j] = sourceBatch.restDarbouxVectors[j];
for (int j = 0; j < batch.stiffnesses.count; ++j)
batch.stiffnesses[j] = sourceBatch.stiffnesses[j];
for (int j = 0; j < batch.breakThresholds.count; ++j)
batch.breakThresholds[j] = sourceBatch.breakThresholds[j];
}
// Skin:
for (int i = 0; i < skinnedBlueprintFinal.skinConstraintsData.batches.Count; ++i)
{
var batch = skinnedBlueprintFinal.skinConstraintsData.batches[i];
var sourceBatch = skinnedBlueprintReferencia.skinConstraintsData.batches[i];
for (int j = 0; j < batch.skinPoints.count; ++j)
batch.skinPoints[j] = sourceBatch.skinPoints[j];
for (int j = 0; j < batch.skinNormals.count; ++j)
batch.skinNormals[j] = sourceBatch.skinNormals[j];
for (int j = 0; j < batch.skinRadiiBackstop.count; ++j)
batch.skinRadiiBackstop[j] = sourceBatch.skinRadiiBackstop[j];
for (int j = 0; j < batch.skinCompliance.count; ++j)
batch.skinCompliance[j] = sourceBatch.skinCompliance[j];
}
// Aerodynamics:
for (int i = 0; i < skinnedBlueprintFinal.aerodynamicConstraintsData.batches.Count; ++i)
{
var batch = skinnedBlueprintFinal.aerodynamicConstraintsData.batches[i];
var sourceBatch = skinnedBlueprintReferencia.aerodynamicConstraintsData.batches[i];
for (int j = 0; j < batch.aerodynamicCoeffs.count; ++j)
batch.aerodynamicCoeffs[j] = sourceBatch.aerodynamicCoeffs[j];
}
// Tether, Stretch Shear, Bend Twist, Shape Matching, Chain and Volume constraints generate null errors. Thats why they are not copied.
////// END COPYING CONSTRAINTS
// Creating Blueprint Asset File
if (!AssetDatabase.Contains(skinnedBlueprintFinal))
AssetDatabase.CreateAsset(skinnedBlueprintFinal, "Assets/newSkinnedBluePrint.asset");
// Particle Groups:
skinnedBlueprintFinal.ClearParticleGroups();
for (int i = 0; i < skinnedBlueprintReferencia.groups.Count; ++i)
{
var group = skinnedBlueprintFinal.AppendNewParticleGroup(skinnedBlueprintReferencia.groups[i].name);
skinnedBlueprintReferencia.groups[i].particleIndices.Count);
for (int j = 0; j < skinnedBlueprintReferencia.groups[i].particleIndices.Count; ++j)
{
group.particleIndices.Add(skinnedBlueprintReferencia.groups[i].particleIndices[j]);
}
AssetDatabase.AddObjectToAsset(skinnedBlueprintFinal.groups[i], skinnedBlueprintFinal);
}
// Save the Blueprint Asset
AssetDatabase.SaveAssets();
// Assign the new blueprint to the SkinnedCloth of the dress
dress_SkinnedCloth.skinnedClothBlueprint = skinnedBlueprintFinal;
}
However, although we can generate correctly a new file of a SkinnedClothBlueprint, in the practice it is as if the properties of Skin were not being applied.
If we manually generate and edit the SkinnedClothBlueprint with the same properties, it works well, but when we create it with this code, it does not work as it should.
1) Is there anything that we are missing to copy all the properties of SkinnedClothBlueprint to the new one (except the positions, rotations, and speeds)?
2)- Is it necessary to update/re-calculate somehow the blueprint, after having modified its properties?
3) Is there a more efficient way to copy all the properties of a SkinnedClothBlueprint to a new one (except the positions, rotations, and speeds), but for a new bakedmesh as inputmesh?
4) Or do we have to use the "Bake Mesh" method from the Obi Skinned Cloth Renderer, to get a mesh with the skin?
5) We have realized that, if we just change the blendshapes of the SkinnedMeshRenderer component by code (even without modifying the original blueprint), even if it has the ObiSkinnedCloth component, we achieve what we wanted. Is there any problem in doing this once at the beginning of the program?
Thanks in advance!
PD: Le hemos enviado por e-mail estas mismas consultas. Muchas gracias por su ayuda al respecto!