Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (789)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Solved] Loading models with the Assimp binding  (Read 1552 times)
0 Members and 1 Guest are viewing this topic.
Offline CopyableCougar4
« Posted 2017-03-26 01:02:35 »

I've been working on implementing the Assimp library into my code, and I've run into a problem and am unsure if I'm going to have to find another library or if I'm just making a simple mistake.

When I load OBJ files (Assimp won't load FBX, 3DSmax, or Maya files, citing invalid formats or outdated versions) into AIScene instances with Assimp, the textures are nowhere to be found.
1  
2  
3  
scene.mNumTextures() = 0
Assimp.aiGetMaterialTextureCount(material, Assimp.aiTextureType_DIFFUSE) = 0
Assimp.aiGetMaterialTextureCount(material, Assimp.aiTextureType_NONE) = 0


I load my AIScene instance with:
1  
2  
3  
4  
5  
6  
ByteBuffer file = Utils.read(asset.toInputStream());
      int flags = Assimp.aiProcess_Triangulate | Assimp.aiProcess_GenNormals | Assimp.aiProcess_ImproveCacheLocality
            | Assimp.aiProcess_SortByPType | Assimp.aiProcess_OptimizeMeshes | Assimp.aiProcess_OptimizeGraph
            | Assimp.aiProcess_CalcTangentSpace | Assimp.aiProcess_TransformUVCoords | Assimp.aiProcess_GenUVCoords
            | Assimp.aiProcess_JoinIdenticalVertices | Assimp.aiProcess_FlipUVs;
      AIScene scene = Assimp.aiImportFileFromMemory(file, flags, "");


Any thoughts or ideas would be appreciated.

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline CopyableCougar4
« Reply #1 - Posted 2017-03-26 01:15:28 »

I just read that OBJ should not be imported from memory, so I will try to import correctly and then update my post.

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline CopyableCougar4
« Reply #2 - Posted 2017-03-26 01:34:50 »

Nevermind, I solved my problem: I had to use another import method.

1  
2  
3  
4  
5  
      int flags = Assimp.aiProcess_Triangulate | Assimp.aiProcess_GenNormals | Assimp.aiProcess_ImproveCacheLocality
            | Assimp.aiProcess_SortByPType | Assimp.aiProcess_OptimizeMeshes | Assimp.aiProcess_OptimizeGraph
            | Assimp.aiProcess_CalcTangentSpace | Assimp.aiProcess_TransformUVCoords | Assimp.aiProcess_GenUVCoords
            | Assimp.aiProcess_JoinIdenticalVertices | Assimp.aiProcess_FlipUVs;
      AIScene scene = Assimp.aiImportFileEx(asset.getPath(), flags, null);

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DesertCookie

Senior Newbie


Exp: 5 years



« Reply #3 - Posted 2019-05-16 10:07:26 »

Have you found a working way to load model files from within the jar file?
Offline orange451

JGO Kernel


Medals: 516
Projects: 8
Exp: 8 years


Your face? Your ass? What's the difference?


« Reply #4 - Posted 2019-05-16 22:32:20 »

@DesertCookie

Assimp's aiImportFile can take a ByteBuffer input. Surely you could read a file in your jar (as a URL) to a ByteBuffer and pass it in?

First Recon. A java made online first person shooter!
Offline Spasi
« Reply #5 - Posted 2019-05-17 07:37:49 »

The correct way to do it is to use aiImportFileEx and pass an AIFileIO that creates the appropriate AIFile instances. The callbacks in AIFile can be implemented however you wish, including reading everything from in-memory buffers or even streaming data from a jar file. If the root file references other files which are also contained in the archive, it will work without extracting everything to disk.

An advice if you choose this solution: log every callback invocation to get a feel of how it works, what you're supposed to do in each callback and avoid unnecessarily reading the same data again and again. You will probably need some kind of temporary cache for each aiImportFileEx call. A simple (non-streaming) implementation to get you started is available in lwjgl3-demos.
Offline DesertCookie

Senior Newbie


Exp: 5 years



« Reply #6 - Posted 2019-05-17 16:01:21 »

Surely you could read a file in your jar (as a URL) to a ByteBuffer and pass it in?
I tried that but it always resulted in weird artefacts when rendering the meshes; reading it directly from a file works flawlessly. I haven't checked if the indices are scrambled or what exactly about the imported data is wrong when using the ByteBuffer read from an InputStream as a source.
The correct way to do it is to use aiImportFileEx and pass an AIFileIO that creates the appropriate AIFile instances.
I'm trying to get into them (had found your answers on the lwjgl-forums after posting here). So far I've only been looking at the AMD Tootle-examples; your link helped clarify a few things that werent clear to me from those demos.
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (2633 views)
2018-11-16 13:46:03

hadezbladez (952 views)
2018-11-16 13:41:33

hadezbladez (2592 views)
2018-11-16 13:35:35

hadezbladez (513 views)
2018-11-16 13:32:03

EgonOlsen (3746 views)
2018-06-10 19:43:48

EgonOlsen (4142 views)
2018-06-10 19:43:44

EgonOlsen (2499 views)
2018-06-10 19:43:20

DesertCoockie (3307 views)
2018-05-13 18:23:11

nelsongames (3403 views)
2018-04-24 18:15:36

nelsongames (4381 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!