I have a very simple python script to generate planes in the scene. I want to generate 50000 planes in a scene, to compensate for unavailability of POINT primitive, so that i can render a point cloud. It runs at a good pace till 2000 th plane is added , then starts slowing down, and gets very slow. My computer's config is - i7 3.4 GHz, 16GB RAM, GeForce 9800 GTX graphic card.

here is the python script-

import bpy 
from math import *
import random

for i in range(2000):
    x=random.uniform(0,100)
    y=random.uniform(0,100)
    z=random.uniform(0,100)
    bpy.ops.mesh.primitive_plane_add(location=(x,y,z))
    #bpy.context.active_object.scale=(100,100,100)
    print("\n",i)

Any Help on why it is slowing down? How can this be fixed ? Any alternate approach to render point cloud in blender? would be much appreciated...

Thanks for your time and attention

  • It would be better to use Instances, which use less memory (and may run faster too, but I haven't tested this). Probably the best way to do is by using Dupliverts to instance a tri to a point cloud object made up of verts. – gandalf3 Mar 7 '14 at 7:30
up vote 6 down vote accepted

Dupli objects

Try using Dupliverts (instances):

  1. Create/import the point cloud as a mesh with only vertices:

    enter image description here

  2. Create a single tri by adding a plane (ShiftA> Mesh > Plane) and merging one edge with AltM:

    enter image description here enter image description here

  3. Parent the tri to the point cloud by selecting both objects with the point cloud active (last selected) and pressing CtrlP.

  4. With the point cloud active, enable Verts in Properties > Object > Duplication:

    enter image description here

  5. Add a track to constraint to the tri with the camera object as the target so that all the tris face the camera:

    enter image description here

This has performed fine for me with point/vertex clouds of over 7000 vertices. This will work with both BI and Cycles.

Halos

Another method for rendering point clouds is to use a Halo Material:

  1. Create/Import a point cloud as vertex only mesh (no edges or faces):

    enter image description here

  2. Create a Halo material:

    enter image description here

Note that this only works for BI.

The python script that i used earlier used a function call inside the loop

bpy.ops.mesh.primitive_plane_add(location=(x,y,z))

As a result of which the blender was updating the scene by iterating over all the previously existing objects in the scene in each loop iteration. Below link explains the problem and gives the solution.

Python performance with Blender operators

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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