Skip to main content
added 19 characters in body
Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106

This is a workaround and I hope there is (or will eventually be) an easier way to access point cloud data in the API.

enter image description here

In your GN tree add an Instance on Points node, plug in a Mesh Line or a Points node set to a Count of 1 to get a single vertex at $(0, 0, 0)$.

enter image description here

In theory we should be able to access the vertices' geometry but for now the geometry is not "real". We need to realize the instances with a Realize Instances node.

enter image description here

Then, we need to access the evaluated mesh, after the GN modifier has been evaluated. For that we can use the context dependency graph.

import bpy
import numpy as np

depsgraph = bpy.context.evaluated_depsgraph_get()
obj = bpy.context.active_object.evaluated_get(depsgraph)

coords = np.zeros(len(obj.data.vertices) * 3, dtype=float)
obj.data.vertices.foreach_get("co", coords)

print(coords)  # This is a flattened array

coords = coords.reshape(len(obj.data.vertices), 3)

print(coords)  # This is a 3D array

Result :

enter image description here

This is a workaround and I hope there is (or will eventually be) an easier way to access point cloud data in the API.

enter image description here

In your GN tree add an Instance on Points node, plug in a Mesh Line set to a Count of 1 to get a single vertex at $(0, 0, 0)$.

enter image description here

In theory we should be able to access the vertices' geometry but for now the geometry is not "real". We need to realize the instances with a Realize Instances node.

enter image description here

Then, we need to access the evaluated mesh, after the GN modifier has been evaluated. For that we can use the context dependency graph.

import bpy
import numpy as np

depsgraph = bpy.context.evaluated_depsgraph_get()
obj = bpy.context.active_object.evaluated_get(depsgraph)

coords = np.zeros(len(obj.data.vertices) * 3, dtype=float)
obj.data.vertices.foreach_get("co", coords)

print(coords)  # This is a flattened array

coords = coords.reshape(len(obj.data.vertices), 3)

print(coords)  # This is a 3D array

Result :

enter image description here

This is a workaround and I hope there is (or will eventually be) an easier way to access point cloud data in the API.

enter image description here

In your GN tree add an Instance on Points node, plug in a Mesh Line or a Points node set to a Count of 1 to get a single vertex at $(0, 0, 0)$.

enter image description here

In theory we should be able to access the vertices' geometry but for now the geometry is not "real". We need to realize the instances with a Realize Instances node.

enter image description here

Then, we need to access the evaluated mesh, after the GN modifier has been evaluated. For that we can use the context dependency graph.

import bpy
import numpy as np

depsgraph = bpy.context.evaluated_depsgraph_get()
obj = bpy.context.active_object.evaluated_get(depsgraph)

coords = np.zeros(len(obj.data.vertices) * 3, dtype=float)
obj.data.vertices.foreach_get("co", coords)

print(coords)  # This is a flattened array

coords = coords.reshape(len(obj.data.vertices), 3)

print(coords)  # This is a 3D array

Result :

enter image description here

added 210 characters in body
Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106

This is a workaround and I hope there is (or will eventually be) an easier way to access point cloud data in the API.

enter image description here

In your GN tree add an Instance on Points node, plug in a Mesh Line set to a Count of 1 to get a single vertex at $(0, 0, 0)$.

enter image description here

In theory we should be able to access the vertices' geometry but for now the geometry is not "real". We need to realize the instances with a Realize Instances node.

enter image description here

Then, we need to access the evaluated mesh, after the GN modifier has been evaluated. For that we can use the context dependency graph.

import bpy
import numpy as np

depsgraph = bpy.context.evaluated_depsgraph_get()
obj = bpy.context.active_object.evaluated_get(depsgraph)

printcoords = np.zeros([vlen(obj.codata.vertices) for* v3, indtype=float)
obj.data.vertices.foreach_get("co", coords)

print(coords)  # This is a flattened array

coords = coords.reshape(len(obj.data.vertices]vertices), 3)

print(coords)  # This is a 3D array

Result :

enter image description here

This is a workaround and I hope there is (or will eventually be) an easier way to access point cloud data in the API.

enter image description here

In your GN tree add an Instance on Points node, plug in a Mesh Line set to a Count of 1 to get a single vertex at $(0, 0, 0)$.

enter image description here

In theory we should be able to access the vertices' geometry but for now the geometry is not "real". We need to realize the instances with a Realize Instances node.

enter image description here

Then, we need to access the evaluated mesh, after the GN modifier has been evaluated. For that we can use the context dependency graph.

import bpy

depsgraph = bpy.context.evaluated_depsgraph_get()
obj = bpy.context.active_object.evaluated_get(depsgraph)

print([v.co for v in obj.data.vertices])

Result :

enter image description here

This is a workaround and I hope there is (or will eventually be) an easier way to access point cloud data in the API.

enter image description here

In your GN tree add an Instance on Points node, plug in a Mesh Line set to a Count of 1 to get a single vertex at $(0, 0, 0)$.

enter image description here

In theory we should be able to access the vertices' geometry but for now the geometry is not "real". We need to realize the instances with a Realize Instances node.

enter image description here

Then, we need to access the evaluated mesh, after the GN modifier has been evaluated. For that we can use the context dependency graph.

import bpy
import numpy as np

depsgraph = bpy.context.evaluated_depsgraph_get()
obj = bpy.context.active_object.evaluated_get(depsgraph)

coords = np.zeros(len(obj.data.vertices) * 3, dtype=float)
obj.data.vertices.foreach_get("co", coords)

print(coords)  # This is a flattened array

coords = coords.reshape(len(obj.data.vertices), 3)

print(coords)  # This is a 3D array

Result :

enter image description here

Update for GN fields
Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106

This is a workaround and I hope there is (or will eventually be) an easier way to access point cloud data in the API.

enter image description here

Instead of instancing points, create a new object, eg. a cube, go into edit mode, select everything and right click > Merge Vertices > At Center. That way you have an object with a single vertex at world origin.

In your GN tree add aan Point InstanceInstance on Points node and choose your, plug in a Mesh Line set to a Count of 1 to get a single vertex objectat $(0, 0, 0)$.

enter image description here

In theory we should be able to access the vertices' geometry but for now the geometry is not "real". We need to trickrealize the modifier into creating real geometry. There are multiple nodes for which it will work. I pluggedinstances with a default and blank Attribute MathRealize Instances node before the modifier output.

enter image description hereenter image description here

Then, we need to access the evaluated mesh, after the GN modifier has been appliedevaluated. For that we can use the context dependency graph.

import bpy

depsgraph = bpy.context.evaluated_depsgraph_get()
obj = bpy.context.active_object.evaluated_get(depsgraph)

print([v.co for v in obj.data.vertices])

Result :

enter image description here

This is a workaround and I hope there is (or will eventually be) an easier way to access point cloud data in the API.

enter image description here

Instead of instancing points, create a new object, eg. a cube, go into edit mode, select everything and right click > Merge Vertices > At Center. That way you have an object with a single vertex at world origin.

In your GN tree add a Point Instance node and choose your single vertex object.

enter image description here

In theory we should be able to access the vertices' geometry but for now the geometry is not "real". We need to trick the modifier into creating real geometry. There are multiple nodes for which it will work. I plugged a default and blank Attribute Math node before the modifier output.

enter image description here

Then, we need to access the evaluated mesh, after the GN modifier has been applied. For that we can use the context dependency graph.

import bpy

depsgraph = bpy.context.evaluated_depsgraph_get()
obj = bpy.context.active_object.evaluated_get(depsgraph)

print([v.co for v in obj.data.vertices])

Result :

enter image description here

This is a workaround and I hope there is (or will eventually be) an easier way to access point cloud data in the API.

enter image description here

In your GN tree add an Instance on Points node, plug in a Mesh Line set to a Count of 1 to get a single vertex at $(0, 0, 0)$.

enter image description here

In theory we should be able to access the vertices' geometry but for now the geometry is not "real". We need to realize the instances with a Realize Instances node.

enter image description here

Then, we need to access the evaluated mesh, after the GN modifier has been evaluated. For that we can use the context dependency graph.

import bpy

depsgraph = bpy.context.evaluated_depsgraph_get()
obj = bpy.context.active_object.evaluated_get(depsgraph)

print([v.co for v in obj.data.vertices])

Result :

enter image description here

Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106
Loading