Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  import and export blueprint property values in script
#2
Hi there,

The included functions to read/write properties from/to textures can only be used in-editor, since they rely on writing/reading assets directly which cannot be done at runtime. If you're writing an editor script, you will find these functions in ObiMeshBasedActorBlueprintEditor:

Code:
ReadParticlePropertyFromTexture(Texture2D source, Action<int, Color> onReadProperty);
WriteParticlePropertyToTexture(string path, int width, int height, int padding);

Reading takes a texture as input, and an action that gets called for each particle in the actor. The two parameters passed to this callback are the particle index and the texel Color value read from the texture.

Note it is trivial to write your own method that reads an existing texture at runtime, outside of the editor. All you need to do is iterate over all vertices in the mesh, read the texel value at the vertex uv coordinate, and then map the value to any property/range you need. For instance:

Code:
void Read(Texture2D input, ObiMeshBasedActorBlueprint blueprint)
{
            Vector2[] uvs = blueprint.inputMesh.uv;

            // Iterate over all vertices in the mesh reading back colors from the texture:
            for (int i = 0; i <  blueprint.inputMesh.vertexCount; ++i)
            {

                    int particleIndex = blueprint.topology.rawToWelded[i];
                    var color = input.GetPixelBilinear(uvs[i].x, uvs[i].y));

                   // map the color to any property you want:
                   blueprint.principalRadii[particleIndex] = color.r  * 10;
            }
}
Reply


Messages In This Thread
RE: import and export blueprint property values in script - by josemendez - 13-09-2021, 12:38 PM