Create AIScene instance from the file's contentWhat is the purpose of ByteBuffer's flip method? (And why is it called “flip”?)Downloading a file from spring controllersJsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON objectusing JPA in multi-thread RMI architectureCreating a maximized lwjgl windowPointer addressing to invalid content after function returnCreate an Object instance from a MapSpring Boot not serving static contentAny way to retrieve all the material properties from AssImp?Can't create RestTemplate() instance from spring-webpyassimp how to create new scene?

In this example, which path would a monster affected by the Dissonant Whispers spell take?

My coworkers think I had a long honeymoon. Actually I was diagnosed with cancer. How do I talk about it?

Traffic law UK, pedestrians

Will TSA allow me to carry a Continuous Positive Airway Pressure (CPAP)/sleep apnea device?

How to decline physical affection from a child whose parents are pressuring them?

On the Twin Paradox Again

Sharing one invocation list between multiple events on the same object in C#

Which type of electrical protector is better for the appliances? surge or over/under voltage protection?

Can a magnetic field of an object be stronger than its gravity?

Is it possible for people to live in the eye of a permanent hypercane?

How to make thick Asian sauces?

What does it mean by "d-ism of Leibniz" and "dotage of Newton" in simple English?

How were concentration and extermination camp guards recruited?

What risks are there when you clear your cookies instead of logging off?

Can you please explain this joke: "I'm going bananas is what I tell my bananas before I leave the house"?

Implement Homestuck's Catenative Doomsday Dice Cascader

How can drunken, homicidal elves successfully conduct a wild hunt?

How can Iron Man's suit withstand this?

How to pass a regex when finding a directory path in bash?

How to skip replacing first occurrence of a character in each line?

Pros and cons of writing a book review?

Credit card offering 0.5 miles for every cent rounded up. Too good to be true?

Is it OK to bring delicacies from hometown as tokens of gratitude for an out-of-town interview?

What are they doing to this rocket following its test fire?



Create AIScene instance from the file's content


What is the purpose of ByteBuffer's flip method? (And why is it called “flip”?)Downloading a file from spring controllersJsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON objectusing JPA in multi-thread RMI architectureCreating a maximized lwjgl windowPointer addressing to invalid content after function returnCreate an Object instance from a MapSpring Boot not serving static contentAny way to retrieve all the material properties from AssImp?Can't create RestTemplate() instance from spring-webpyassimp how to create new scene?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm writing a Java web service where it is possible to upload a 3D object, operate on it and store it.



What I'm trying to do is creating an AIScene instance using a byte[] as an input parameter which is the file itself (it's content).



I have found no way to do this in the docs, all import methods require a path.



Right now I'm taking a look at both the lwjgl java version of Assimp as well as the C++ version. It doesn't matter which one is used to solve the issue.



Edit: the code I'm trying to get done:



@Override
public String uploadFile(MultipartFile file) aiProcess_Triangulate, fileIo); // ISSUE HERE. file.getName() is not a path, just a name. so is getOriginalName() in my case.

try
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);

return mesh.mName().toString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());
catch(Exception e)
e.printStackTrace();

return "fail";



When debugging the method I get an access violation in the method that binds to the native:



public static long naiImportFileEx(long pFile, int pFlags, long pFS)


this is the message:




#



A fatal error has been detected by the Java Runtime Environment:



#



EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007400125d, pid=6400, tid=0x0000000000003058



#



JRE version: Java(TM) SE Runtime Environment (8.0_201-b09) (build 1.8.0_201-b09)



Java VM: Java HotSpot(TM) 64-Bit Server VM (25.201-b09 mixed mode windows-amd64 compressed oops)



Problematic frame:



V [jvm.dll+0x1e125d]



#



Failed to write core dump. Minidumps are not enabled by default on client versions of Windows



#



An error report file with more information is saved as:



C:UsersragosIdeaProjectsobjectstore3dhs_err_pid6400.log



#



If you would like to submit a bug report, please visit:



http://bugreport.java.com/bugreport/crash.jsp



#











share|improve this question
























  • You can customize the loading process via the aiImportFileEx function. You can give that function a structure containing callback functions to load/read resources (whatever those resources may be). See this example in LWJGL/lwjgl3-demos repository: github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/… It loads the model and materials from as InputStreams/ByteBuffers from the classpath.

    – httpdigest
    Mar 24 at 15:48











  • Thank you for the comment but here github.com/assimp/assimp/blob/… it shows that the underlying implementation uses the file's path anyway. The defined buffer is a custom IO system. As such it causes read access violation in my code because I have no valid file path coming from Spring's MultipartFile. Did I miss something? I'm adding my code to the question. Largely the same as the one you linked though except getting the data.

    – agiro
    Mar 24 at 19:53











  • The filename is just part of the interface between you and Assimp, for you to somewhat know/identity what should be loaded. The string can actually be anything. Just for you to know what to load/to do.

    – httpdigest
    Mar 24 at 20:03











  • And the filename is used to load linked resources, such as the .mtl file referenced within a Wavefront .obj file by name.

    – httpdigest
    Mar 24 at 20:04











  • Then it really shouldn't be the problem. Could you help me on where did I mess up? I changed the code starting from my lines 8-10, because MultipartFile just passes the object and I already have it's content as a byte[].

    – agiro
    Mar 24 at 20:06

















0















I'm writing a Java web service where it is possible to upload a 3D object, operate on it and store it.



What I'm trying to do is creating an AIScene instance using a byte[] as an input parameter which is the file itself (it's content).



I have found no way to do this in the docs, all import methods require a path.



Right now I'm taking a look at both the lwjgl java version of Assimp as well as the C++ version. It doesn't matter which one is used to solve the issue.



Edit: the code I'm trying to get done:



@Override
public String uploadFile(MultipartFile file) aiProcess_Triangulate, fileIo); // ISSUE HERE. file.getName() is not a path, just a name. so is getOriginalName() in my case.

try
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);

return mesh.mName().toString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());
catch(Exception e)
e.printStackTrace();

return "fail";



When debugging the method I get an access violation in the method that binds to the native:



public static long naiImportFileEx(long pFile, int pFlags, long pFS)


this is the message:




#



A fatal error has been detected by the Java Runtime Environment:



#



EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007400125d, pid=6400, tid=0x0000000000003058



#



JRE version: Java(TM) SE Runtime Environment (8.0_201-b09) (build 1.8.0_201-b09)



Java VM: Java HotSpot(TM) 64-Bit Server VM (25.201-b09 mixed mode windows-amd64 compressed oops)



Problematic frame:



V [jvm.dll+0x1e125d]



#



Failed to write core dump. Minidumps are not enabled by default on client versions of Windows



#



An error report file with more information is saved as:



C:UsersragosIdeaProjectsobjectstore3dhs_err_pid6400.log



#



If you would like to submit a bug report, please visit:



http://bugreport.java.com/bugreport/crash.jsp



#











share|improve this question
























  • You can customize the loading process via the aiImportFileEx function. You can give that function a structure containing callback functions to load/read resources (whatever those resources may be). See this example in LWJGL/lwjgl3-demos repository: github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/… It loads the model and materials from as InputStreams/ByteBuffers from the classpath.

    – httpdigest
    Mar 24 at 15:48











  • Thank you for the comment but here github.com/assimp/assimp/blob/… it shows that the underlying implementation uses the file's path anyway. The defined buffer is a custom IO system. As such it causes read access violation in my code because I have no valid file path coming from Spring's MultipartFile. Did I miss something? I'm adding my code to the question. Largely the same as the one you linked though except getting the data.

    – agiro
    Mar 24 at 19:53











  • The filename is just part of the interface between you and Assimp, for you to somewhat know/identity what should be loaded. The string can actually be anything. Just for you to know what to load/to do.

    – httpdigest
    Mar 24 at 20:03











  • And the filename is used to load linked resources, such as the .mtl file referenced within a Wavefront .obj file by name.

    – httpdigest
    Mar 24 at 20:04











  • Then it really shouldn't be the problem. Could you help me on where did I mess up? I changed the code starting from my lines 8-10, because MultipartFile just passes the object and I already have it's content as a byte[].

    – agiro
    Mar 24 at 20:06













0












0








0








I'm writing a Java web service where it is possible to upload a 3D object, operate on it and store it.



What I'm trying to do is creating an AIScene instance using a byte[] as an input parameter which is the file itself (it's content).



I have found no way to do this in the docs, all import methods require a path.



Right now I'm taking a look at both the lwjgl java version of Assimp as well as the C++ version. It doesn't matter which one is used to solve the issue.



Edit: the code I'm trying to get done:



@Override
public String uploadFile(MultipartFile file) aiProcess_Triangulate, fileIo); // ISSUE HERE. file.getName() is not a path, just a name. so is getOriginalName() in my case.

try
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);

return mesh.mName().toString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());
catch(Exception e)
e.printStackTrace();

return "fail";



When debugging the method I get an access violation in the method that binds to the native:



public static long naiImportFileEx(long pFile, int pFlags, long pFS)


this is the message:




#



A fatal error has been detected by the Java Runtime Environment:



#



EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007400125d, pid=6400, tid=0x0000000000003058



#



JRE version: Java(TM) SE Runtime Environment (8.0_201-b09) (build 1.8.0_201-b09)



Java VM: Java HotSpot(TM) 64-Bit Server VM (25.201-b09 mixed mode windows-amd64 compressed oops)



Problematic frame:



V [jvm.dll+0x1e125d]



#



Failed to write core dump. Minidumps are not enabled by default on client versions of Windows



#



An error report file with more information is saved as:



C:UsersragosIdeaProjectsobjectstore3dhs_err_pid6400.log



#



If you would like to submit a bug report, please visit:



http://bugreport.java.com/bugreport/crash.jsp



#











share|improve this question
















I'm writing a Java web service where it is possible to upload a 3D object, operate on it and store it.



What I'm trying to do is creating an AIScene instance using a byte[] as an input parameter which is the file itself (it's content).



I have found no way to do this in the docs, all import methods require a path.



Right now I'm taking a look at both the lwjgl java version of Assimp as well as the C++ version. It doesn't matter which one is used to solve the issue.



Edit: the code I'm trying to get done:



@Override
public String uploadFile(MultipartFile file) aiProcess_Triangulate, fileIo); // ISSUE HERE. file.getName() is not a path, just a name. so is getOriginalName() in my case.

try
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);

return mesh.mName().toString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());
catch(Exception e)
e.printStackTrace();

return "fail";



When debugging the method I get an access violation in the method that binds to the native:



public static long naiImportFileEx(long pFile, int pFlags, long pFS)


this is the message:




#



A fatal error has been detected by the Java Runtime Environment:



#



EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007400125d, pid=6400, tid=0x0000000000003058



#



JRE version: Java(TM) SE Runtime Environment (8.0_201-b09) (build 1.8.0_201-b09)



Java VM: Java HotSpot(TM) 64-Bit Server VM (25.201-b09 mixed mode windows-amd64 compressed oops)



Problematic frame:



V [jvm.dll+0x1e125d]



#



Failed to write core dump. Minidumps are not enabled by default on client versions of Windows



#



An error report file with more information is saved as:



C:UsersragosIdeaProjectsobjectstore3dhs_err_pid6400.log



#



If you would like to submit a bug report, please visit:



http://bugreport.java.com/bugreport/crash.jsp



#








spring lwjgl assimp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 20:12







agiro

















asked Mar 24 at 14:25









agiroagiro

9571133




9571133












  • You can customize the loading process via the aiImportFileEx function. You can give that function a structure containing callback functions to load/read resources (whatever those resources may be). See this example in LWJGL/lwjgl3-demos repository: github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/… It loads the model and materials from as InputStreams/ByteBuffers from the classpath.

    – httpdigest
    Mar 24 at 15:48











  • Thank you for the comment but here github.com/assimp/assimp/blob/… it shows that the underlying implementation uses the file's path anyway. The defined buffer is a custom IO system. As such it causes read access violation in my code because I have no valid file path coming from Spring's MultipartFile. Did I miss something? I'm adding my code to the question. Largely the same as the one you linked though except getting the data.

    – agiro
    Mar 24 at 19:53











  • The filename is just part of the interface between you and Assimp, for you to somewhat know/identity what should be loaded. The string can actually be anything. Just for you to know what to load/to do.

    – httpdigest
    Mar 24 at 20:03











  • And the filename is used to load linked resources, such as the .mtl file referenced within a Wavefront .obj file by name.

    – httpdigest
    Mar 24 at 20:04











  • Then it really shouldn't be the problem. Could you help me on where did I mess up? I changed the code starting from my lines 8-10, because MultipartFile just passes the object and I already have it's content as a byte[].

    – agiro
    Mar 24 at 20:06

















  • You can customize the loading process via the aiImportFileEx function. You can give that function a structure containing callback functions to load/read resources (whatever those resources may be). See this example in LWJGL/lwjgl3-demos repository: github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/… It loads the model and materials from as InputStreams/ByteBuffers from the classpath.

    – httpdigest
    Mar 24 at 15:48











  • Thank you for the comment but here github.com/assimp/assimp/blob/… it shows that the underlying implementation uses the file's path anyway. The defined buffer is a custom IO system. As such it causes read access violation in my code because I have no valid file path coming from Spring's MultipartFile. Did I miss something? I'm adding my code to the question. Largely the same as the one you linked though except getting the data.

    – agiro
    Mar 24 at 19:53











  • The filename is just part of the interface between you and Assimp, for you to somewhat know/identity what should be loaded. The string can actually be anything. Just for you to know what to load/to do.

    – httpdigest
    Mar 24 at 20:03











  • And the filename is used to load linked resources, such as the .mtl file referenced within a Wavefront .obj file by name.

    – httpdigest
    Mar 24 at 20:04











  • Then it really shouldn't be the problem. Could you help me on where did I mess up? I changed the code starting from my lines 8-10, because MultipartFile just passes the object and I already have it's content as a byte[].

    – agiro
    Mar 24 at 20:06
















You can customize the loading process via the aiImportFileEx function. You can give that function a structure containing callback functions to load/read resources (whatever those resources may be). See this example in LWJGL/lwjgl3-demos repository: github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/… It loads the model and materials from as InputStreams/ByteBuffers from the classpath.

– httpdigest
Mar 24 at 15:48





You can customize the loading process via the aiImportFileEx function. You can give that function a structure containing callback functions to load/read resources (whatever those resources may be). See this example in LWJGL/lwjgl3-demos repository: github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/… It loads the model and materials from as InputStreams/ByteBuffers from the classpath.

– httpdigest
Mar 24 at 15:48













Thank you for the comment but here github.com/assimp/assimp/blob/… it shows that the underlying implementation uses the file's path anyway. The defined buffer is a custom IO system. As such it causes read access violation in my code because I have no valid file path coming from Spring's MultipartFile. Did I miss something? I'm adding my code to the question. Largely the same as the one you linked though except getting the data.

– agiro
Mar 24 at 19:53





Thank you for the comment but here github.com/assimp/assimp/blob/… it shows that the underlying implementation uses the file's path anyway. The defined buffer is a custom IO system. As such it causes read access violation in my code because I have no valid file path coming from Spring's MultipartFile. Did I miss something? I'm adding my code to the question. Largely the same as the one you linked though except getting the data.

– agiro
Mar 24 at 19:53













The filename is just part of the interface between you and Assimp, for you to somewhat know/identity what should be loaded. The string can actually be anything. Just for you to know what to load/to do.

– httpdigest
Mar 24 at 20:03





The filename is just part of the interface between you and Assimp, for you to somewhat know/identity what should be loaded. The string can actually be anything. Just for you to know what to load/to do.

– httpdigest
Mar 24 at 20:03













And the filename is used to load linked resources, such as the .mtl file referenced within a Wavefront .obj file by name.

– httpdigest
Mar 24 at 20:04





And the filename is used to load linked resources, such as the .mtl file referenced within a Wavefront .obj file by name.

– httpdigest
Mar 24 at 20:04













Then it really shouldn't be the problem. Could you help me on where did I mess up? I changed the code starting from my lines 8-10, because MultipartFile just passes the object and I already have it's content as a byte[].

– agiro
Mar 24 at 20:06





Then it really shouldn't be the problem. Could you help me on where did I mess up? I changed the code starting from my lines 8-10, because MultipartFile just passes the object and I already have it's content as a byte[].

– agiro
Mar 24 at 20:06












1 Answer
1






active

oldest

votes


















0














It is possible if we use the aiImportFileFromMemory method.



The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily.



The reason for the access violation was the use of indirect buffers (for more info why that is a problem, check this out).



The solution is not nearly as complicated as the code I initially pasted:



@Override
public String uploadFile(MultipartFile file) throws IOException
ByteBuffer buffer = BufferUtils.createByteBuffer((int) file.getSize());
buffer.put(file.getBytes());
buffer.flip();
AIScene scene = Assimp.aiImportFileFromMemory(buffer,aiProcess_Triangulate, (ByteBuffer) null);
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);
return mesh.mName().dataString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());



Here I create a direct buffer with the appropriate size, load the data and flip it (this part is a must.) After that let Assimp do its magic so you get pointers to the structure. With the return statement I just check if I got the valid data.



edit



As in the comments it was pointed out, this implementation is limited to a single file upload and assumes it gets everything that is necessary from that one MultipartFile, it won't work well with referenced formats. See docs for more detail.



The demo that was linked in the question's comments which was used in the question as a base has a different use case to my original one.






share|improve this answer

























  • "...and actually copies the buffer around unnecessarily." For the demo (having to read the data from an InputStream as a classpath resource) I'd even argue to be fine. See: github.com/LWJGL/lwjgl3/issues/451#issuecomment-476382224

    – httpdigest
    Mar 25 at 21:46











  • So I'd rephrase "The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily." to "The approach I wanted to follow was copied from a github demo and does not apply to my use-case, since I do not use an InputStream to back the data but instead an array. On top of that, in my use-case Assimp will not load referenced files as is the case in the demo which loads Wavefront .obj files with references to .mtl files."

    – httpdigest
    Mar 25 at 22:02











  • Also be aware of the fact that aiImportFileFromMemory can obviously not handle file formats which spread their content onto multiple files, such as .obj or .md3. See the "Note" section in Assimp's function documentation: assimp.sourceforge.net/lib_html/…

    – httpdigest
    Mar 25 at 22:07











  • Thank you for the input. The service assumed single file uploads, in my case it worked with an obj (because I had only one file, no .mtl and whatnot). I'll take a note in the answer in case someone stumbles upon this.

    – agiro
    Mar 25 at 22:20











  • However in this case I'll think about solving the referencing issue too. This is a practice project after all.

    – agiro
    Mar 25 at 22:26











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324798%2fcreate-aiscene-instance-from-the-files-content%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














It is possible if we use the aiImportFileFromMemory method.



The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily.



The reason for the access violation was the use of indirect buffers (for more info why that is a problem, check this out).



The solution is not nearly as complicated as the code I initially pasted:



@Override
public String uploadFile(MultipartFile file) throws IOException
ByteBuffer buffer = BufferUtils.createByteBuffer((int) file.getSize());
buffer.put(file.getBytes());
buffer.flip();
AIScene scene = Assimp.aiImportFileFromMemory(buffer,aiProcess_Triangulate, (ByteBuffer) null);
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);
return mesh.mName().dataString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());



Here I create a direct buffer with the appropriate size, load the data and flip it (this part is a must.) After that let Assimp do its magic so you get pointers to the structure. With the return statement I just check if I got the valid data.



edit



As in the comments it was pointed out, this implementation is limited to a single file upload and assumes it gets everything that is necessary from that one MultipartFile, it won't work well with referenced formats. See docs for more detail.



The demo that was linked in the question's comments which was used in the question as a base has a different use case to my original one.






share|improve this answer

























  • "...and actually copies the buffer around unnecessarily." For the demo (having to read the data from an InputStream as a classpath resource) I'd even argue to be fine. See: github.com/LWJGL/lwjgl3/issues/451#issuecomment-476382224

    – httpdigest
    Mar 25 at 21:46











  • So I'd rephrase "The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily." to "The approach I wanted to follow was copied from a github demo and does not apply to my use-case, since I do not use an InputStream to back the data but instead an array. On top of that, in my use-case Assimp will not load referenced files as is the case in the demo which loads Wavefront .obj files with references to .mtl files."

    – httpdigest
    Mar 25 at 22:02











  • Also be aware of the fact that aiImportFileFromMemory can obviously not handle file formats which spread their content onto multiple files, such as .obj or .md3. See the "Note" section in Assimp's function documentation: assimp.sourceforge.net/lib_html/…

    – httpdigest
    Mar 25 at 22:07











  • Thank you for the input. The service assumed single file uploads, in my case it worked with an obj (because I had only one file, no .mtl and whatnot). I'll take a note in the answer in case someone stumbles upon this.

    – agiro
    Mar 25 at 22:20











  • However in this case I'll think about solving the referencing issue too. This is a practice project after all.

    – agiro
    Mar 25 at 22:26















0














It is possible if we use the aiImportFileFromMemory method.



The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily.



The reason for the access violation was the use of indirect buffers (for more info why that is a problem, check this out).



The solution is not nearly as complicated as the code I initially pasted:



@Override
public String uploadFile(MultipartFile file) throws IOException
ByteBuffer buffer = BufferUtils.createByteBuffer((int) file.getSize());
buffer.put(file.getBytes());
buffer.flip();
AIScene scene = Assimp.aiImportFileFromMemory(buffer,aiProcess_Triangulate, (ByteBuffer) null);
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);
return mesh.mName().dataString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());



Here I create a direct buffer with the appropriate size, load the data and flip it (this part is a must.) After that let Assimp do its magic so you get pointers to the structure. With the return statement I just check if I got the valid data.



edit



As in the comments it was pointed out, this implementation is limited to a single file upload and assumes it gets everything that is necessary from that one MultipartFile, it won't work well with referenced formats. See docs for more detail.



The demo that was linked in the question's comments which was used in the question as a base has a different use case to my original one.






share|improve this answer

























  • "...and actually copies the buffer around unnecessarily." For the demo (having to read the data from an InputStream as a classpath resource) I'd even argue to be fine. See: github.com/LWJGL/lwjgl3/issues/451#issuecomment-476382224

    – httpdigest
    Mar 25 at 21:46











  • So I'd rephrase "The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily." to "The approach I wanted to follow was copied from a github demo and does not apply to my use-case, since I do not use an InputStream to back the data but instead an array. On top of that, in my use-case Assimp will not load referenced files as is the case in the demo which loads Wavefront .obj files with references to .mtl files."

    – httpdigest
    Mar 25 at 22:02











  • Also be aware of the fact that aiImportFileFromMemory can obviously not handle file formats which spread their content onto multiple files, such as .obj or .md3. See the "Note" section in Assimp's function documentation: assimp.sourceforge.net/lib_html/…

    – httpdigest
    Mar 25 at 22:07











  • Thank you for the input. The service assumed single file uploads, in my case it worked with an obj (because I had only one file, no .mtl and whatnot). I'll take a note in the answer in case someone stumbles upon this.

    – agiro
    Mar 25 at 22:20











  • However in this case I'll think about solving the referencing issue too. This is a practice project after all.

    – agiro
    Mar 25 at 22:26













0












0








0







It is possible if we use the aiImportFileFromMemory method.



The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily.



The reason for the access violation was the use of indirect buffers (for more info why that is a problem, check this out).



The solution is not nearly as complicated as the code I initially pasted:



@Override
public String uploadFile(MultipartFile file) throws IOException
ByteBuffer buffer = BufferUtils.createByteBuffer((int) file.getSize());
buffer.put(file.getBytes());
buffer.flip();
AIScene scene = Assimp.aiImportFileFromMemory(buffer,aiProcess_Triangulate, (ByteBuffer) null);
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);
return mesh.mName().dataString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());



Here I create a direct buffer with the appropriate size, load the data and flip it (this part is a must.) After that let Assimp do its magic so you get pointers to the structure. With the return statement I just check if I got the valid data.



edit



As in the comments it was pointed out, this implementation is limited to a single file upload and assumes it gets everything that is necessary from that one MultipartFile, it won't work well with referenced formats. See docs for more detail.



The demo that was linked in the question's comments which was used in the question as a base has a different use case to my original one.






share|improve this answer















It is possible if we use the aiImportFileFromMemory method.



The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily.



The reason for the access violation was the use of indirect buffers (for more info why that is a problem, check this out).



The solution is not nearly as complicated as the code I initially pasted:



@Override
public String uploadFile(MultipartFile file) throws IOException
ByteBuffer buffer = BufferUtils.createByteBuffer((int) file.getSize());
buffer.put(file.getBytes());
buffer.flip();
AIScene scene = Assimp.aiImportFileFromMemory(buffer,aiProcess_Triangulate, (ByteBuffer) null);
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);
return mesh.mName().dataString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());



Here I create a direct buffer with the appropriate size, load the data and flip it (this part is a must.) After that let Assimp do its magic so you get pointers to the structure. With the return statement I just check if I got the valid data.



edit



As in the comments it was pointed out, this implementation is limited to a single file upload and assumes it gets everything that is necessary from that one MultipartFile, it won't work well with referenced formats. See docs for more detail.



The demo that was linked in the question's comments which was used in the question as a base has a different use case to my original one.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 22:24

























answered Mar 25 at 21:33









agiroagiro

9571133




9571133












  • "...and actually copies the buffer around unnecessarily." For the demo (having to read the data from an InputStream as a classpath resource) I'd even argue to be fine. See: github.com/LWJGL/lwjgl3/issues/451#issuecomment-476382224

    – httpdigest
    Mar 25 at 21:46











  • So I'd rephrase "The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily." to "The approach I wanted to follow was copied from a github demo and does not apply to my use-case, since I do not use an InputStream to back the data but instead an array. On top of that, in my use-case Assimp will not load referenced files as is the case in the demo which loads Wavefront .obj files with references to .mtl files."

    – httpdigest
    Mar 25 at 22:02











  • Also be aware of the fact that aiImportFileFromMemory can obviously not handle file formats which spread their content onto multiple files, such as .obj or .md3. See the "Note" section in Assimp's function documentation: assimp.sourceforge.net/lib_html/…

    – httpdigest
    Mar 25 at 22:07











  • Thank you for the input. The service assumed single file uploads, in my case it worked with an obj (because I had only one file, no .mtl and whatnot). I'll take a note in the answer in case someone stumbles upon this.

    – agiro
    Mar 25 at 22:20











  • However in this case I'll think about solving the referencing issue too. This is a practice project after all.

    – agiro
    Mar 25 at 22:26

















  • "...and actually copies the buffer around unnecessarily." For the demo (having to read the data from an InputStream as a classpath resource) I'd even argue to be fine. See: github.com/LWJGL/lwjgl3/issues/451#issuecomment-476382224

    – httpdigest
    Mar 25 at 21:46











  • So I'd rephrase "The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily." to "The approach I wanted to follow was copied from a github demo and does not apply to my use-case, since I do not use an InputStream to back the data but instead an array. On top of that, in my use-case Assimp will not load referenced files as is the case in the demo which loads Wavefront .obj files with references to .mtl files."

    – httpdigest
    Mar 25 at 22:02











  • Also be aware of the fact that aiImportFileFromMemory can obviously not handle file formats which spread their content onto multiple files, such as .obj or .md3. See the "Note" section in Assimp's function documentation: assimp.sourceforge.net/lib_html/…

    – httpdigest
    Mar 25 at 22:07











  • Thank you for the input. The service assumed single file uploads, in my case it worked with an obj (because I had only one file, no .mtl and whatnot). I'll take a note in the answer in case someone stumbles upon this.

    – agiro
    Mar 25 at 22:20











  • However in this case I'll think about solving the referencing issue too. This is a practice project after all.

    – agiro
    Mar 25 at 22:26
















"...and actually copies the buffer around unnecessarily." For the demo (having to read the data from an InputStream as a classpath resource) I'd even argue to be fine. See: github.com/LWJGL/lwjgl3/issues/451#issuecomment-476382224

– httpdigest
Mar 25 at 21:46





"...and actually copies the buffer around unnecessarily." For the demo (having to read the data from an InputStream as a classpath resource) I'd even argue to be fine. See: github.com/LWJGL/lwjgl3/issues/451#issuecomment-476382224

– httpdigest
Mar 25 at 21:46













So I'd rephrase "The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily." to "The approach I wanted to follow was copied from a github demo and does not apply to my use-case, since I do not use an InputStream to back the data but instead an array. On top of that, in my use-case Assimp will not load referenced files as is the case in the demo which loads Wavefront .obj files with references to .mtl files."

– httpdigest
Mar 25 at 22:02





So I'd rephrase "The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily." to "The approach I wanted to follow was copied from a github demo and does not apply to my use-case, since I do not use an InputStream to back the data but instead an array. On top of that, in my use-case Assimp will not load referenced files as is the case in the demo which loads Wavefront .obj files with references to .mtl files."

– httpdigest
Mar 25 at 22:02













Also be aware of the fact that aiImportFileFromMemory can obviously not handle file formats which spread their content onto multiple files, such as .obj or .md3. See the "Note" section in Assimp's function documentation: assimp.sourceforge.net/lib_html/…

– httpdigest
Mar 25 at 22:07





Also be aware of the fact that aiImportFileFromMemory can obviously not handle file formats which spread their content onto multiple files, such as .obj or .md3. See the "Note" section in Assimp's function documentation: assimp.sourceforge.net/lib_html/…

– httpdigest
Mar 25 at 22:07













Thank you for the input. The service assumed single file uploads, in my case it worked with an obj (because I had only one file, no .mtl and whatnot). I'll take a note in the answer in case someone stumbles upon this.

– agiro
Mar 25 at 22:20





Thank you for the input. The service assumed single file uploads, in my case it worked with an obj (because I had only one file, no .mtl and whatnot). I'll take a note in the answer in case someone stumbles upon this.

– agiro
Mar 25 at 22:20













However in this case I'll think about solving the referencing issue too. This is a practice project after all.

– agiro
Mar 25 at 22:26





However in this case I'll think about solving the referencing issue too. This is a practice project after all.

– agiro
Mar 25 at 22:26



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324798%2fcreate-aiscene-instance-from-the-files-content%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해