This discussion is archived
11 Replies Latest reply: Apr 16, 2013 11:06 AM by KonradZuse RSS

importing premade 3d objects(Maya,etc) into FX Shapes????

KonradZuse Explorer
Currently Being Moderated
So I cannot seem to find anything in the API, or on the web, but https://wikis.oracle.com/display/OpenJDK/3D+Features says this

Loader support
Many 3D file formats exist, such as:
Obj, Maya, 3D Studio Max, Collada, KRML
We will not provide a loader as part of the JavaFX runtime
We will make sample code available for one or two popular formats


How do we work with them? Are they like normal Images, or do we do something special with them, and need to set them to a special shape????

Thanks,

~KZ
  • 1. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    jsmith Guru
    Currently Being Moderated
    Try an early access importer available here =>
    http://www.interactivemesh.org/models/jfx3dimporter.html
  • 2. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    KonradZuse Explorer
    Currently Being Moderated
    Thanks! Have you looked at them yet? Any idea how to exactly implement them? I'm using the corkscrew sample, not too sure if there's a specific way of doing it.
  • 3. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    jsmith Guru
    Currently Being Moderated
    Thanks! Have you looked at them yet? Any idea how to exactly implement them?
    Nope.

    Ask any questions regarding the model importer directly to interactivemesh, that will easily be your best and quickest source of info =>
    http://www.interactivemesh.org/impressum.html

    I think the JavaFX team also plan to release some sample code for a 3D model importer but I don't think they have released one yet, so the interactivemesh one is your best starting point at the moment.
  • 4. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    InteractiveMesh Explorer
    Currently Being Moderated
    Is your corkscrew sample as '.obj' or '.stl' export available?

    Assuming that the 'corkscrew.obj' file and its associated material file 'corkscrew.mtl' are located in the project's sub-folder 'resources' following code should import your model:
    import java.net.URL;   
    import javafx.scene.shape.MeshView;
    
    import com.interactivemesh.jfx.importer.ImportException;
    import com.interactivemesh.jfx.importer.obj.ObjModelImporter;
    
    ObjModelImporter objImporter = new ObjModelImporter();
    
    try {
        URL corkscrewUrl = this.getClass().getResource("resources/corkscrew.obj");
        objImporter.read(corkscrewUrl);
    }
    catch (ImportException e) {
        e.printStackTrace();
        return;
    }
    
    MeshView[] corkscrewShape3Ds = objImporter.getImport();
    
    objImporter.close();
    August
  • 5. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    KonradZuse Explorer
    Currently Being Moderated
    So you're the man who we should thank for this huh? :).


    Also I meant to say i'm using this "STL : CylinderHead

    CylinderHead-ascii.stl, 14.6 MB
    CylinderHead-binary.stl, 3.3 MB"

    Sorry about that....

    I'm assuming it's the same way to get and use both the same?

    Also would you say it's hard to create your own importer/format?


    I was noticing that you brought it in as a resource, but according to the STL api you don't use resources, but for obj it seems thast you do hmm, weird...

    Seems as if both are different, but my question is answered for how to display it(as a mesh)? so I guess it should take the STl file, but I don't think I use a resource????

    Originally I tried to grab it using the getClass().getResource().

    Edited by: KonradZuse on Apr 5, 2013 8:47 AM
  • 6. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    InteractiveMesh Explorer
    Currently Being Moderated
    The multiple use of the word 'resources' might be confusing. A 'resources' named sub-directory in a Java project is typically used to collect image, sound, and model files which are associated with the classes:

    .../myProject/MyClass.java
    .../myProject/resources/CylinderHead-binary.stl

    => this.getClass().getResource("resources/CylinderHead-binary.stl");

    A model file itself can also have associated image, material, and shader files. These are the resources of the model file. Their location is typically relative to the location of the model file. If not, then a model-resource-location base is to be set for the importer.
    import java.net.URL;
    
    import javafx.scene.paint.Color;
    import javafx.scene.paint.PhongMaterial;
    import javafx.scene.shape.MeshView;
    import javafx.scene.shape.TriangleMesh;   
    
    import com.interactivemesh.jfx.importer.stl.StlImportOption;
    import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
        
    StlMeshImporter stlImporter = new StlMeshImporter(); 
    // Generated vertex normals result in a smoothly shaded surface
    stlImporter.setCreaseAngle(24);  
    
    try {
        URL cylinderHeadUrl = this.getClass().getResource("resources/CylinderHead-binary.stl");
        stlImporter.read(cylinderHeadUrl);
    }
    catch (ImportException e) {
        e.printStackTrace();;
        return;
    }
    
    // STL includes only geometry data
    TriangleMesh cylinderHeadMesh = stlImporter.getImport();
    
    stlImporter.close();
    
    // Create Shape3D    
    MeshView cylinderHeadMeshView = new MeshView();
    cylinderHeadMeshView.setMaterial(new PhongMaterial(Color.GRAY));
    cylinderHeadMeshView.setMesh(cylinderHeadMesh);
    August
  • 7. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    KonradZuse Explorer
    Currently Being Moderated
    I'm sorry, I made my "resources" post a bit vague in what I was referring to, but I appreciate the recap in how getResource works :)

    Now i'm curious about a few things.

    1. Using Ambient Light on the images causes it to look really POOR quality, but a pointlight shows it all in amazing glory. It seems as if it goes by which color setting is used(even though it seems specular is > diffuse???) (maybe the other way around), but it is 1 SOLID color. No shading, or anything like in the pointlight.


    2. Both OBJ and STL contain 2 files, it seems as if both work, so why include both files?

    Also since you said there can be image, material, and shader files, how will the importer work with multiple files?

    Thanks again for everything, and all the best on your project!

    Edited by: KonradZuse on Apr 6, 2013 5:09 PM
  • 8. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    InteractiveMesh Explorer
    Currently Being Moderated
    "1. Using Ambient Light ..."

    Please, search the web for '3D Lighting' to get more details about interdependencies of light types and material colors.


    "2. Both OBJ and STL contain 2 files ..."

    OBJ defines smoothly shaded faces either by smoothing groups or by normals. ObjModelImporterJFX supports both approaches and converts them into TriangleMesh compliant smoothing groups.

    STL geometry data can be provided in ASCII or binary format. StlModelImporterJFX supports both data representations.


    "... image, material, and shader files, how will the importer work with multiple files?"

    Almost all 3D model formats can reference files for texture images, shader source code, or other resources. The 3D model importer handles these references and loads all these resources while reading the 3D model file. To read several model files just recall 'importer.read(modelUrl)'.

    August
  • 9. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    KonradZuse Explorer
    Currently Being Moderated
    I tried to use the obj importer, but for some reason it's not working for me? I used your exact code have both files together, and returned it as a "MeshView[]" and put it into a group as that MeshView[] and nothing appears?

    Edited by: KonradZuse on Apr 9, 2013 12:53 PM


    I also have been trying to get more stls, and the sites I've been finding like turbosquid and such all give really tiny, or different shape/model than I was supposed to. I'm not too sure if that has to do with "creaseAngle"(as changing the creaseAngle for this Cylinder didn't produce anything that I saw different). I found a program called "MeshView" and I had this AUD.stl that when imported into MeshLab it was as big as the cylinder, and I could manipulate it in any way. For some reason it wouldn't save the file's axis different(even when I moved it) nor it's translation. when I scale is 10x it looks much better though, so it seems it's just an issue of scaling.

    I just think these files are poor, and the only 3D software I have is Photoshop...


    Also for the obj file it specifies a bunch of MeshViews, TriangleMesh's, and PhongMaterials, using codes like u, g, etc... How does that work? I can make obj's in Photoshop, but are we supposed to name each file according to it's "letter." There was a Coffee Cup that I tried and I got an error for 'g' so I'm curious how exactly it works.


    Edited by: KonradZuse on Apr 12, 2013 6:35 PM

    Another thing I notice is that I cannot find "sizes" on these models. It's always measured in Triangles, polygons, or Vertices, and other information is given. Is it possible in the future for us to possibly import pictures at a specific size? I don't know too much about how the 3D programs work, so any insight would be appreciated.

    Edited by: KonradZuse on Apr 12, 2013 6:48 PM

    Also when trying to import 100(lowest I've tried that does it) or more the area around the importing mesh's is extremely slow and choppy. When I try to drag and move a mesh it will take a couple of seconds to drag over, but after it's out of the "area" it moves fine; however putting it back into the area causes it to lag and be slow again. For some reason even when I was rotating a mesh far outside the area, if I moved inside the area, my object outside would freeze for a second.


    Thanks again for putting out this wonderful importer.

    Edited by: KonradZuse on Apr 12, 2013 7:15 PM
  • 10. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    InteractiveMesh Explorer
    Currently Being Moderated
    To "see" imported models you have to identify and adjust following attributes:

    MeshView's size and position
    - boundsInLocal: the 3D BoundingBox of the MeshView in untransformed local coordinates
    - boundsInParent: the 3D BoundingBox of the MeshView after all transformations have been applied

    PerspectiveCamera's
    - position and orientation (after transformations have been applied)
    - near and far clipping planes
    - field of view angle

    While composing your 3D scene take into account that JavaFX might not behave as it should due to its early stage.

    JavaFX repainting of complex 3D scene seems not to work properly yet.

    I can't respond to Photoshop related issues because I don't have access to it.

    August
  • 11. Re: importing premade 3d objects(Maya,etc) into FX Shapes????
    KonradZuse Explorer
    Currently Being Moderated
    Yeah, sorry, I posted a lot of things at once, and edited it so many times I forgot what I fixed and what I still had questions for :p.


    Thanks for the insight into the cam and such, it seemed that for the AUD I just needed to scale, but the main issue was these models I've been getting are extremely poor. They say it's one thing, and it's not :P. That's why I'm happy I got this MeshLab program to help me view them first.


    Yeah I understand how early it is, that's why I want to give into this project as much as I can to help you with making this into a super amazing package(which i don't doubt since it's amazing already).

    Yeah I'm not sure how many will cause it to be slow, but it just seems to happen when dragging the mouse into that area(normally when you drag the object into that area, bt like I said also when I was rotating an object away and my mouse happened to go through the origin of all 100 mesh's).


    no worries on Photoshop, I was using that to try and import models to see, but MeshLab does that for me. Photoshop doesn't really have much in the way of 3D either. Only Maya, 3ds, obj, and max? I want to say.


    Also I'm still having trouble with trying to import this OBJ file. I used the code provided above, and used it in a method in my "importer class."


    the stl is set up the same way
       public MeshView[] objImporter(String s)
       {
              
     
            ObjModelImporter objImporter = new ObjModelImporter();
    
            try
            {
                URL objUrl = this.getClass().getResource(s);
                objImporter.read(objUrl);
            }
            catch (ImportException e)
            {
                e.printStackTrace();
            }
    
           meshV = objImporter.getImport();
            objImporter.close();
               return meshV;
            }
    so I would do
     importer i = new importer();
    
    i.objImport("file.obj");
    I just realized that when trying to redo some elements for the obj, I realized that I don't have a PhongMaterial set. How do we set the PhongMaterial for this?


    I tried to set each individual mesh in the MeshView, but no such luck.




            public Face(MeshView[] mesh)
            {
    
                   this.meshV = mesh;
                
                p.setDiffuseColor(Color.AQUA);
                
                this.relocate(200, 200);
                this.setTranslateZ(0);
                
                this.wide = 1;
                this.high = 1;
                this.deep = 1;
               
                for(int i = 0; i <meshV.length; i++)
                {
                    meshV.setMaterial(p);
    super.getChildren().addAll(meshV[i]);
    }

    public class draw extends Application
    {
    importer i = new importer();

    double x,y,z;

    Face f = new Face(i.objImporter("Scooter.obj"));
    EDIT:  One other thing I've been looking into is how to take 3, or more, sides of an image and create a 3D model.  I know it can be done using Auto CAD, and another company I know does it for their products, but I was curious how hard it would be to do something like that in FX, or how I would go about it?
    
    Edited by: KonradZuse on Apr 16, 2013 11:06 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points