2 Replies Latest reply: Apr 6, 2013 6:42 PM by KonradZuse RSS

    Adding a MeshView as part of another class not working when returned?

    KonradZuse
      I have a class that extends box, to get the properties to display it as a box, or else have the option to display it as a 3D image/Mesh.

      I have this code
      public class Face extends Box
      
      {
      
              private MeshView image3D;
      
              public Face(TriangleMesh mesh)
              {
                  this.image3D = new MeshView(mesh);
              }
      
          public TriangleMesh getImage3D()
         {
              return (TriangleMesh) image3D.getMesh();
          }
      
      
      
      public MeshView getImage3DView()
       {
              return image3D;
          }
        
          public void setImage3D(TriangleMesh mesh)
          {
              this.image3D = new MeshView(mesh);
      
          }
      
         }
       
      Granted there are many more methods and variables I just wanted to show what I needed. Basically I have a 3D importer class, which I'll post in a second, which imports the data for the mesh. From there I return the TriangleMesh and then set it to a MeshViewer that is setup currently as a constructor call in the Face class, and then I set it to a group using the getter method.

        Face d = new Face(i.stlImporter("CylinderHead-binary.stl"));
      d.setMaterial(gray);
      d.setLayoutX(200);
      d.setLayoutY(200);
      Group s1 = new Group (d.getImage3DView());
      and finally
      public class importer
      {
          TriangleMesh mesh = new TriangleMesh();
         public TriangleMesh stlImporter(String s)
         {
              StlMeshImporter stl = new StlMeshImporter(); 
              // Generated vertex normals result in a smoothly shaded surface
              stl.setCreaseAngle(24);  
      
              try
              {
                  URL cylinderHeadUrl = this.getClass().getResource(s);
                  stl.read(cylinderHeadUrl);
              }
              catch (ImportException e) {
                  e.printStackTrace();
      
              }
      
              // STL includes only geometry data
              mesh = stl.getImport();
      
      
              stl.close();
              return mesh;
         }
      
         public TriangleMesh getStlImport()
         {
             return mesh;
         }
      }
      However if I change all of the face code into MeshView it will work. So basically it seems that something is up with MeshView being used in Face.

      Edited by: KonradZuse on Apr 5, 2013 8:22 PM
        • 1. Re: Adding a MeshView as part of another class not working when returned?
          aidreamer
          I'm a little confused as to why you would place a MeshView inside of an extension to the Box class, but ok. What's the question?
          • 2. Re: Adding a MeshView as part of another class not working when returned?
            KonradZuse
            Well basically I wanted to have a class that was originally a box, but then would have a 3D image. The converter that came out a week or so ago imports it as a Mesh, so I wanted to be able to have it return a mesh if it's a 3D object.

            I was just confused how it would all work. To make a box, I assumed I had to extend the box, and great it based on that, or shape. Maybe it would just be easier to save the TriangleMesh, then load it into a MeshViewer in another class. I figured I could just make a viewer in the class and just add that viewer, but maybe that's not a good idea.

            Now I realize that I can just make everything a 3D mesh, box included, so I can just make it a viewer with additional properties like my box was supposed to be, or maybe just the mesh itself, then add it to a viewer later, thoughts?


            I'd appreciate any insight on the class structure that I'm confused about, thanks!~!!


            ~KZ