K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
953 stars 121 forks source link

Flip Z axis for mesh plotting #433

Closed thoth291 closed 10 months ago

thoth291 commented 1 year ago

First of all - this is BRILLIANT project! Thank you so much for making it to work.

I do scientific visualization all the time - and tools like this really enablers for pushing science forward! Thank you!  

Description

I'm plotting a custom mesh which is being generated by another engine. Everything plots well, except that my Z axis is going in opposite direction to what I want. It goes up - I need it to go down (visually) while my Z values go up.

What I get: image

What I want: image

What I Did

Essentially this code - except that I had my own data with verts and inds.

import k3d
import numpy as np

data = np.load('streamlines_data.npz')
plot = k3d.plot()
plot += k3d.mesh(data['vertices'], data['indices'],
                 opacity=0.25, wireframe=False, color=0x0002)
plot.display()

In other visualization tools I can simply set something like flip_z or z_flip - but can't figure out how to set it here.

Am I missing something obvious, or this is not possible to script in the code?

Would appreciate for your help! Thanks in Advance!

etienne87 commented 1 year ago

just revert the data['vertices'] Z axis in python:

data['vertices'][:,z_axis] = max_z - data['vertices'][:,z_axis]
data['vertices'] = data['vertices'][::-1]   # needed otherwise k3d cancels effect of first line
artur-trzesiok commented 10 months ago

I agree with @etienne87 . I dive into topic in three.js but I found this: https://discourse.threejs.org/t/convert-from-one-coordinate-system-to-another/13240/42

Looks like there is no direct support in threejs to do that

artur-trzesiok commented 10 months ago

So at this moment I dont see any short way how to implement it to be consistent in all type of objects. As only threejs will add support for that we can re-open a issue