Update ImGui menu + update tutorial.
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
# This file is part of libigl, a simple c++ geometry processing library.
|
||||
#
|
||||
# Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com>
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public License
|
||||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
# obtain one at http://mozilla.org/MPL/2.0/.
|
||||
# Add the igl library to the modules search path
|
||||
import sys, os
|
||||
sys.path.insert(0, os.getcwd() + "/../")
|
||||
|
||||
import pyigl as igl
|
||||
import nanogui
|
||||
|
||||
V1 = igl.eigen.MatrixXd()
|
||||
F1 = igl.eigen.MatrixXi()
|
||||
|
||||
V2 = igl.eigen.MatrixXd()
|
||||
F2 = igl.eigen.MatrixXi()
|
||||
|
||||
float_variable = 0.1
|
||||
bool_variable = True
|
||||
dir = 0
|
||||
|
||||
|
||||
def make_accessors(name):
|
||||
def setter(value):
|
||||
globals()[name] = value
|
||||
|
||||
def getter():
|
||||
return globals()[name]
|
||||
return setter, getter
|
||||
|
||||
|
||||
def viewer_init(viewer):
|
||||
# add new group
|
||||
viewer.ngui.addGroup("New Group")
|
||||
|
||||
# Expose the using general callback
|
||||
viewer.ngui.addDoubleVariable("double", *make_accessors("float_variable"))
|
||||
|
||||
def setter(val):
|
||||
global bool_variable
|
||||
bool_variable = val
|
||||
|
||||
def getter():
|
||||
global bool_variable
|
||||
return bool_variable
|
||||
|
||||
# ... or using a custom callback
|
||||
viewer.ngui.addBoolVariable("bool", setter, getter)
|
||||
|
||||
viewer.ngui.addEnumVariable("Direction", *make_accessors("dir")) \
|
||||
.setItems(["Up", "Down", "Left", "Right"])
|
||||
|
||||
# Add a button
|
||||
def cb():
|
||||
print("Hello")
|
||||
viewer.ngui.addButton("Print Hello", cb)
|
||||
|
||||
#Add an additional menu window
|
||||
viewer.ngui.addWindow((220, 10), "New Window")
|
||||
|
||||
# add accessor
|
||||
viewer.ngui.addDoubleVariable("double", *make_accessors("float_variable"))
|
||||
|
||||
#Generate menu
|
||||
viewer.screen.performLayout()
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
# Load a mesh in OFF format
|
||||
igl.readOFF("../../tutorial/shared/bunny.off", V1, F1)
|
||||
|
||||
# Init the viewer
|
||||
viewer = igl.viewer.Viewer()
|
||||
|
||||
# Extend viewer menu
|
||||
viewer.callback_init = viewer_init
|
||||
|
||||
# Plot the mesh
|
||||
viewer.data.set_mesh(V1, F1)
|
||||
viewer.launch()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user