2
$\begingroup$

I get my location of all particles with this script.

ps = bpy.data.objects["Cube"].particle_systems["ParticleSystem"]
ps.particles[0].hair_keys[5].co
-> Vector((0.4008302092552185, -0.8442497253417969, 1.4897942543029785))

The location is not in Unit Scale centimeter 0.01. How can I use and calculate the unit scale?

$\endgroup$
1
$\begingroup$

With a function like this one:

def get_unitscale(scene):
    unit_settings = scene.unit_settings

    if unit_settings.system in {"METRIC", "IMPERIAL"}:
        # The units used in modelling are for display only. 
        # Behind the scenes everything is in meters.
        return unit_settings.scale_length
    else:
        # No unit system in use
        return 1

By multiplying with the scale value, you get coordinates in meters:

scale = get_unitscale(bpy.context.scene)
co = ps.particles[0].hair_keys[5].co
# Assuming the unit system is set to meters
co_in_meters = co * scale

By the way, there is also the co_hair() method for getting hair coordinates: https://docs.blender.org/api/2.79/bpy.types.ParticleSystem.html?highlight=co_hair#bpy.types.ParticleSystem.co_hair

And if you want to retrieve coordinates of the hair with final render settings, you will have to call set_resolution() first: https://docs.blender.org/api/2.79/bpy.types.ParticleSystem.html?highlight=co_hair#bpy.types.ParticleSystem.set_resolution

$\endgroup$
  • $\begingroup$ Thank you for your information. I have exported an FBX in 20cm x 20cm. I exported the particles as apx. Unfortunately, the particles are 100x smaller than the fbx. Then I noticed that the direction is wrong. I have adjusted my export settings in blender for UE4. Forward: X Forward. Up: Z Up. How can I include them in that direction? But first, only the scale is important to me. $\endgroup$ – DjEKI Sep 27 '18 at 16:39
  • $\begingroup$ The unit value 0.1 seems to have the right size, but 0.01 is set for centimeters, but that's too small. $\endgroup$ – DjEKI Sep 27 '18 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.