blender/scripts/startup/bl_ui/properties_data_pointcloud.py
Sergey Sharybin 6e18d7a3fd GSplat: Add type field to the PointCloud data-block
The type could be either "Point" or "3D Gaussian Splat".

It is defined in DNA, RNA, and exposed to the UI but does not actually
control anything yet. It is the first step towards native integration
of the 3D Gaussian Splat technique [kerbl3Dgaussians].

In the future the type will control the following aspects:
- Rendering algorithms
- Attribute handling to eventually support rigging of gaussian splats.

Attribute convention for the future IO and render engines integration:
- "scale" for the scale of the gaussian splat, stored as float3
- "rotation" gaussian splat rotation, stored as quternion
- "radiance:base" the base (DC) radiance of the splats, followed by
   opacity and stored as float4
- "radiance:sh_{index}" for the coefficients of the bands >= 1 of the
  spherical harmonics, stored as float3.

Note that the relation of scale and radius is not very trivial (meaning
storing scale as radius that would become float3 was considered but was
not accepted). The scale is used to define the covariance matrix, and
the gaussian splat is technically unbound. It is possible to calculate
a bounding radius for the splat using scale and a cut-off opacity, but
it is rather arbitrary.

[kerbl3Dgaussians] Kerbl, Bernhard et. al.
  "3D Gaussian Splatting for Real-Time Radiance Field Rendering" (2023)
  ACM Transactions on Graphics
  https://repo-sam.inria.fr/fungraph/3d-gaussian-splatting/

Ref #159470
2026-09-16 16:52:10 +02:00

193 lines
5.5 KiB
Python

# SPDX-FileCopyrightText: 2009-2023 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
from bpy.types import Menu, Panel, UIList
from rna_prop_ui import PropertyPanel
class DataButtonsPanel:
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
@classmethod
def poll(cls, context):
engine = context.scene.render.engine
return hasattr(context, "pointcloud") and context.pointcloud and (engine in cls.COMPAT_ENGINES)
class DATA_PT_context_pointcloud(DataButtonsPanel, Panel):
bl_label = ""
bl_options = {'HIDE_HEADER'}
COMPAT_ENGINES = {
'BLENDER_RENDER',
'BLENDER_EEVEE',
'BLENDER_WORKBENCH',
}
def draw(self, context):
layout = self.layout
ob = context.object
pointcloud = context.pointcloud
space = context.space_data
if ob:
layout.template_ID(ob, "data")
elif pointcloud:
layout.template_ID(space, "pin_id")
class POINTCLOUD_MT_attribute_context_menu(Menu):
bl_label = "Attribute Specials"
def draw(self, _context):
layout = self.layout
layout.operator("geometry.attribute_convert")
class POINTCLOUD_MT_add_attribute(Menu):
bl_label = "Add Attribute"
@staticmethod
def add_standard_attribute(layout, pointcloud, name, data_type, domain):
exists = pointcloud.attributes.get(name) is not None
col = layout.column()
col.enabled = not exists
col.operator_context = 'EXEC_DEFAULT'
props = col.operator("geometry.attribute_add", text=name)
props.name = name
props.data_type = data_type
props.domain = domain
def draw(self, context):
layout = self.layout
pointcloud = context.pointcloud
self.add_standard_attribute(layout, pointcloud, "radius", 'FLOAT', 'POINT')
self.add_standard_attribute(layout, pointcloud, "color", 'FLOAT_COLOR', 'POINT')
self.add_standard_attribute(layout, pointcloud, "id", 'INT', 'POINT')
self.add_standard_attribute(layout, pointcloud, "velocity", 'FLOAT_VECTOR', 'POINT')
layout.separator()
layout.operator_context = 'INVOKE_DEFAULT'
layout.operator("geometry.attribute_add", text="Custom...")
class POINTCLOUD_UL_attributes(UIList):
def filter_items(self, _context, data, property):
attributes = getattr(data, property)
flags = []
indices = [i for i in range(len(attributes))]
# Filtering by name
if self.filter_name:
flags = bpy.types.UI_UL_list.filter_items_by_name(
self.filter_name, self.bitflag_filter_item, attributes, "name", reverse=self.use_filter_invert,
)
if not flags:
flags = [self.bitflag_filter_item] * len(attributes)
# Filtering internal attributes
for idx, item in enumerate(attributes):
flags[idx] = 0 if item.is_internal else flags[idx]
# Reorder by name.
if self.use_filter_sort_alpha:
indices = bpy.types.UI_UL_list.sort_items_by_name(attributes, "name")
return flags, indices
def draw_item(self, _context, layout, _data, attribute, _icon, _active_data, _active_propname, _index):
data_type = attribute.bl_rna.properties["data_type"].enum_items[attribute.data_type]
split = layout.split(factor=0.75)
split.emboss = 'NONE'
split.prop(attribute, "name", text="")
sub = split.row()
sub.alignment = 'RIGHT'
sub.active = False
sub.label(text=data_type.name)
class DATA_PT_pointcloud_type(DataButtonsPanel, Panel):
bl_label = "Type"
bl_options = {'DEFAULT_CLOSED'}
COMPAT_ENGINES = {
'BLENDER_RENDER',
'BLENDER_EEVEE',
'BLENDER_WORKBENCH',
}
def draw(self, context):
pointcloud = context.pointcloud
layout = self.layout
layout.prop(pointcloud, "type")
class DATA_PT_pointcloud_attributes(DataButtonsPanel, Panel):
bl_label = "Attributes"
COMPAT_ENGINES = {
'BLENDER_RENDER',
'BLENDER_EEVEE',
'BLENDER_WORKBENCH',
}
def draw(self, context):
pointcloud = context.pointcloud
layout = self.layout
row = layout.row()
col = row.column()
col.template_list(
"POINTCLOUD_UL_attributes",
"attributes",
pointcloud,
"attributes",
pointcloud.attributes,
"active_index",
rows=3,
)
col = row.column(align=True)
col.menu("POINTCLOUD_MT_add_attribute", icon='ADD', text="")
col.operator("geometry.attribute_remove", icon='REMOVE', text="")
col.separator()
col.menu("POINTCLOUD_MT_attribute_context_menu", icon='DOWNARROW_HLT', text="")
class DATA_PT_custom_props_pointcloud(DataButtonsPanel, PropertyPanel, Panel):
COMPAT_ENGINES = {
'BLENDER_RENDER',
'BLENDER_EEVEE',
'BLENDER_WORKBENCH',
}
_context_path = "object.data"
_property_type = bpy.types.PointCloud if hasattr(bpy.types, "PointCloud") else None
classes = (
DATA_PT_context_pointcloud,
DATA_PT_pointcloud_type,
DATA_PT_pointcloud_attributes,
DATA_PT_custom_props_pointcloud,
POINTCLOUD_MT_add_attribute,
POINTCLOUD_MT_attribute_context_menu,
POINTCLOUD_UL_attributes,
)
if __name__ == "__main__": # only for live edit.
from bpy.utils import register_class
for cls in classes:
register_class(cls)