sghr / iGeo

iGeo: Computational Design and 3D Modeling Library for Processing
http://igeo.jp
GNU Lesser General Public License v3.0
146 stars 34 forks source link

How to show different views with IPanel? #14

Open liuzmm opened 9 years ago

liuzmm commented 9 years ago

Hi Satoru, my compliments for your library! I'm using IGeo to draw Nurbs Curves and then construct a Surface with IG.loft (after a few transformations). I would like to show in the same window two different views of my geometries (IG.top of the curves and IG. perspective of the Surface) and I guess I have to use two different IPanes. Is it possible to use IGeo GUI with Processing 2.2.1? ( When I try to run a sketch I get the error unexpected token: package in reference to the first line package igeo.gui; ) How can I use the IPanel to get the result I need? Is there any tutorial about this issue? Thanks in advance!

sghr commented 9 years ago

Because I didn't expect to use in that way, it's ugly but the below should work in Processing 2.2.1.

import igeo.*;
import igeo.gui.*;
size(800,400,IG.GL);
IGridPanel gridPanel = (IGridPanel)IG.cur().panel;
gridPanel.setupGrid(2, 1, null);
IPane pane1 = gridPanel.gridPanes[0][0];
IPane pane2 = gridPanel.gridPanes[1][0];
IView view1 = IView.getTopView((int)pane1.getX(),(int)pane1.getY(),pane1.getWidth(),pane1.getHeight());
view1.enableGL();
view1.setMode(new IGraphicMode(IGraphicMode.GraphicType.GL, false, true, false)); // fill false, wire true, transparent false
IView view2 = IView.getDefaultPerspectiveView((int)pane2.getX(),(int)pane2.getY(),pane2.getWidth(),pane2.getHeight());
view2.enableGL();
view2.setMode(new IGraphicMode(IGraphicMode.GraphicType.GL, true, true, false)); // fill true, wire true, transparent false
pane1.setView(view1);
pane2.setView(view2);
pane1.navigator().setRotateLock(true);
gridPanel.gridPanes[0][0].setVisible(true);
gridPanel.gridPanes[1][0].setVisible(true);
for(int i=0; i<100; i++){
  IVec pos = IRand.pt(100);
  new ISurface(pos, pos.cp(5,0,0), pos.cp(5,5,0), pos.cp(0,5,0)).clr(IRand.clr()); 
}
liuzmm commented 9 years ago

Hi Satoru, many many thanks for your kind answer! I have another doubt about the use of IPanes. It would be possible to draw different geometries in each IPane? It would be useful for me to treat each one as it was indipendent from the other, drawing in the first one only the curves (show in top view) and in the second one the surface (show in perspective view).

sghr commented 9 years ago

Can you put different geometries in locations far apart and set the views to show each? Otherwise, making multiple IG internal servers and tied to views is something I planned but not tested and it'd be very tricky.

liuzmm commented 9 years ago

Sorry for the late reply, I used the first trick you suggested and it works! Thank you so much! One more question.. I'm using ControlP5 slider to move ICurves and get automatically an updated ILoft, but when I change the position the previous curves and surfaces don't disappear, overlapping each other. I tried to refresh the background with IG.bg(0), but it seems that nothing change. Is it possible to refresh the screen in another way?

liuzmm commented 9 years ago

Satoru, I found the refpiGeon method in Nathan Miller Supershape 3D template:

public void refpiGeon(){ IPoint [] ptarr = IG.points(); ICurve [] crvarr = IG.curves(); ISurface [] srfarr = IG.surfaces(); IBrep [] breparr = IG.breps(); IMesh [] mesharr = IG.meshes();

for (IPoint pt:ptarr){ pt.del(); }

for (ICurve crv:crvarr){ crv.del(); }

for (ISurface srf:srfarr){ srf.del(); }

for (IBrep brep:breparr){ brep.del(); }

for (IMesh mesh:mesharr){ mesh.del(); } }

Is it possible to lock rotation and translation in the window and rotate only pressing a key in the keyboard (having only one IPane and one view)?

Regards, liuz