Skip to content

Commit

Permalink
Merge pull request #148 from K3D-tools/devel
Browse files Browse the repository at this point in the history
Expose detail parameter of IcosahedronBufferGeometry in PointsMesh #147
  • Loading branch information
artur-trzesiok authored May 6, 2019
2 parents d804c9f + fd88bda commit ab59504
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 6 deletions.
9 changes: 9 additions & 0 deletions examples/points.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
"points.shader = 'mesh'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"points.mesh_detail = 5"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "k3d",
"version": "2.6.2",
"version": "2.6.3",
"description": "3D visualization library",
"author": "k3d team",
"main": "src/index.js",
Expand Down
6 changes: 6 additions & 0 deletions js/src/core/lib/objectsGUIprovider.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ function objectGUIProvider(K3D, json, objects) {
change.bind(this, json, param));
}
break;
case 'mesh_detail':
if (json.shader === 'mesh') {
K3D.gui_map[json.id].add(json, param, 0, 8, 1).name('meshDetail').onChange(
change.bind(this, json, param));
}
break;
case 'opacity':
K3D.gui_map[json.id].add(json, param, 0, 1.0).name('opacity').onChange(
change.bind(this, json, param));
Expand Down
3 changes: 2 additions & 1 deletion js/src/providers/threejs/objects/PointsMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
color = new THREE.Color(config.color),
positions = config.positions.data,
pointColors = (config.colors && config.colors.data) || null,
meshDetail = typeof (config.mesh_detail) !== 'undefined' ? config.mesh_detail : 2,
colors,
object,
colorsToFloat32Array = buffer.colorsToFloat32Array,
Expand All @@ -32,7 +33,7 @@ module.exports = {
clipping: true,
vertexColors: THREE.VertexColors
}),
sphereGeometry = new THREE.IcosahedronBufferGeometry(config.point_size * 0.5, 2),
sphereGeometry = new THREE.IcosahedronBufferGeometry(config.point_size * 0.5, meshDetail),
instancedGeometry = new THREE.InstancedBufferGeometry().copy(sphereGeometry),
geometry = new THREE.BufferGeometry();

Expand Down
2 changes: 1 addition & 1 deletion k3d/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version_info = (2, 6, 2)
version_info = (2, 6, 3)
__version__ = '.'.join(map(str, version_info))
7 changes: 5 additions & 2 deletions k3d/k3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def mesh(vertices, indices, color=_default_color, attribute=[], color_map=[], co


def points(positions, colors=[], color=_default_color, point_size=1.0, shader='3dSpecular', opacity=1.0, name=None,
compression_level=0, **kwargs):
compression_level=0, mesh_detail=2, **kwargs):
"""Create a Points drawable representing a point cloud.
Arguments:
Expand All @@ -202,14 +202,17 @@ def points(positions, colors=[], color=_default_color, point_size=1.0, shader='3
:`mesh`: high precision triangle mesh of a ball (high quality and GPU load).
mesh_detail: `int`.
Default is 2. Setting this to a value greater than 0 adds more vertices making it no longer an
icosahedron. When detail is greater than 1, it's effectively a sphere. Only valid if shader='mesh'
name: `string`.
A name of a object
kwargs: `dict`.
Dictionary arguments to configure transform and model_matrix."""
return process_transform_arguments(
Points(positions=positions, colors=colors,
color=color, point_size=point_size, shader=shader,
opacity=opacity,
opacity=opacity, mesh_detail=mesh_detail,
name=name,
compression_level=compression_level),
**kwargs
Expand Down
5 changes: 4 additions & 1 deletion k3d/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ class Points(Drawable):
:`3dSpecular`: little 3D balls with specular lightning,
:`mesh`: high precision triangle mesh of a ball (high quality and GPU load).
mesh_detail: `int`.
Default is 2. Setting this to a value greater than 0 adds more vertices making it no longer an
icosahedron. When detail is greater than 1, it's effectively a sphere. Only valid if shader='mesh'
model_matrix: `array_like`.
4x4 model transform matrix.
"""
Expand All @@ -338,6 +340,7 @@ class Points(Drawable):
point_size = TimeSeries(Float(min=EPSILON, default_value=1.0)).tag(sync=True)
opacity = TimeSeries(Float(min=0.0, max=1.0, default_value=1.0)).tag(sync=True)
shader = TimeSeries(Unicode()).tag(sync=True)
mesh_detail = TimeSeries(Int(min=0, max=8)).tag(sync=True)
model_matrix = TimeSeries(Array(dtype=np.float32)).tag(sync=True, **array_serialization_wrap('model_matrix'))

def __init__(self, **kwargs):
Expand Down

0 comments on commit ab59504

Please sign in to comment.