1
$\begingroup$

how to export particles into xml ,l want to use standalone cycles render particles but l do not know how to do ,l think standalone cycles can render particles but the xml api interface can`t read particles data.what can l do ?

$\endgroup$
2
  • 1
    $\begingroup$ You can get the details of a particle system via Python. What format XML file are you trying to get? Can you provide an example of the final result? $\endgroup$ – Rich Sedman Dec 8 '17 at 8:23
  • $\begingroup$ sorry ,l don`t know ,l read standalone cycles source code and found classes like particle and particlesystem,so l think standalone cycles can render particles ,but the xml api not provide method that read particle data, $\endgroup$ – 方刘军 Dec 9 '17 at 6:41
2
$\begingroup$

You can extract the particle coordinates using Python. I don't know what format XML you require but the following python code will extract the locations from the first particle system on the object named 'Cube' in the current scene and generate a fragment of XML defining each particle :

import bpy

object = bpy.context.scene.objects['Cube']
particles = object.particle_systems[0].particles

bpy.ops.text.new()

for p in particles:
    bpy.data.texts[-1].write("<particle x='"+str(p.location[0])+"' y='"+str(p.location[1])+"' z='"+str(p.location[2])+"'/>\n")

Simply open a Text Editor window, click 'New' to create a new text block and paste the above code. Amend the 'object = ...' line to change 'Cube' to the object owning the particle system and click 'Run Script'. This will generate a new text block (viewable in the Text Editor window) containing something like the following :

<particle x='-1.0000001192092896' y='-0.590164840221405' z='-0.06581293791532516'/>
<particle x='0.44954031705856323' y='0.9999999403953552' z='-0.2284814417362213'/>
<particle x='-0.7184286713600159' y='-0.7630156874656677' z='-1.0'/>
<particle x='0.20344652235507965' y='0.9787259697914124' z='-1.0'/>
<particle x='-0.9999999403953552' y='0.39420998096466064' z='0.5528056025505066'/>
<particle x='0.9186654686927795' y='-0.5270229578018188' z='1.0000001192092896'/>
<particle x='-0.21842864155769348' y='-0.7690218091011047' z='-1.0'/>
<particle x='0.34407132863998413' y='-0.6609137654304504' z='-1.0'/>
<particle x='1.000000238418579' y='0.7620397210121155' z='0.39064347743988037'/>
<particle x='-0.31608468294143677' y='1.0000001192092896' z='-0.07232522964477539'/>
<particle x='1.0' y='-0.04655367508530617' z='-0.9907378554344177'/>
<particle x='0.06282128393650055' y='-0.8771299719810486' z='-1.0'/>
<particle x='-0.3629598319530487' y='-0.36061328649520874' z='-0.9999999403953552'/>
<particle x='1.000000238418579' y='0.5745397210121155' z='0.3185715079307556'/>
<particle x='-0.384637713432312' y='-0.23795989155769348' z='1.0'/>
<particle x='0.16828972101211548' y='-1.0000001192092896' z='0.44469761848449707'/>
<particle x='0.9999998211860657' y='-0.12467917054891586' z='0.9131660461425781'/>
<particle x='0.19794464111328125' y='-0.7613976001739502' z='1.0'/>
....

Change the 'write' statement to change the format of the generated XML to whatever you require (currently it outputs each particle as a node with attributes of 'x', 'y', 'z').

Code for Blender 2.82a

$\endgroup$

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.