Jump to page: 1 2
Thread overview
Loading assimp
Jan 09, 2017
Dlearner
Jan 10, 2017
Mike Parker
Jan 10, 2017
Dlearner
Jan 29, 2017
Dlearner
Mar 26, 2017
Dlearner
Mar 26, 2017
ag0aep6g
Mar 26, 2017
Dlearner
Mar 26, 2017
Dlearner
Mar 26, 2017
ag0aep6g
Mar 27, 2017
Dlearner
Sep 28, 2021
Eric_DD
Sep 28, 2021
russhy
Sep 28, 2021
Eric_DD
Sep 29, 2021
russhy
Sep 29, 2021
Mike Parker
Sep 29, 2021
russhy
Sep 29, 2021
Guillaume Piolat
January 09, 2017
I'm trying to use assimp to load models in a program.  I see the Derelict binding is for version 3.3, but the assimp site has no binaries for this, just source.  So I try to use version 3.1.1 and I get this error:

derelict.util.exception.SymbolLoadException@..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source\derelict\util\exception.d(35): Failed to load symbol aiReleaseExportFormatDescription from shared library assimp.dll

Is this a version problem that I need 3.3 for?  If so, I don't know how to build the .dll since I'm still new to programming.  Please send help!  :)
January 10, 2017
On Monday, 9 January 2017 at 18:13:03 UTC, Dlearner wrote:
> I'm trying to use assimp to load models in a program.  I see the Derelict binding is for version 3.3, but the assimp site has no binaries for this, just source.  So I try to use version 3.1.1 and I get this error:
>
> derelict.util.exception.SymbolLoadException@..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source\derelict\util\exception.d(35): Failed to load symbol aiReleaseExportFormatDescription from shared library assimp.dll

Use version 1.1.1 of DerelictASSIMP3. It's implemented against ASSIMP 3.1.

January 10, 2017
On Tuesday, 10 January 2017 at 00:10:12 UTC, Mike Parker wrote:
> On Monday, 9 January 2017 at 18:13:03 UTC, Dlearner wrote:
>> I'm trying to use assimp to load models in a program.  I see the Derelict binding is for version 3.3, but the assimp site has no binaries for this, just source.  So I try to use version 3.1.1 and I get this error:
>>
>> derelict.util.exception.SymbolLoadException@..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source\derelict\util\exception.d(35): Failed to load symbol aiReleaseExportFormatDescription from shared library assimp.dll
>
> Use version 1.1.1 of DerelictASSIMP3. It's implemented against ASSIMP 3.1.

A-haa, thank you!
January 29, 2017
Need to rez this thread because I ran into a wall.  Two little things:

1) Can't seem to get the Importer class to work ("undefined identifier 'Importer' ", etc), and
2) GetTexture and GetTextureCount for aiMaterial don't seem to work
(source\model.d(105,28): Error: no property 'GetTextureCount' for type 'aiMaterial*'
source\model.d(107,6): Error: no property 'GetTexture' for type 'aiMaterial*')

There are some const issues, too, but I can hack around them.  Does anyone have any experience with these?
March 26, 2017
I came back to this project and realised my mistakes (Importer is a class for the C++ API, and we're using the C API).
So I fixed all my errors, but now I get an access violation.
As far as I can tell, it seems to be an issue with `aiGetMaterialTexture`.  It is meant to return an aiString with a filename (default value of "$texture.png"), I believe.  But I get:

aiString(13, x"67 6C 61 73 73 5F 64 69 66 2E 70 6E 67 00 FF FF FF ... FF"c)
[shortened for brevity]

I'm meant to add this on to a directory string so I can load an image, but obviously this wouldn't work.

I thought it might be a problem with converting from D-strings to C-strings.  I sent a string to `aiImportFile` as `toStringz(path)`.
I tested this with some writeln debugging:

```
auto temp = path.toStringz;
writeln("toStringz: ", temp);
writeln("string: ", temp.to!string);
```

This gave:
toStringz: 4770B6
string: Models/Nanosuit/nanosuit.obj

So maybe this is a problem with using aiStrings?  I'm quite confused.  Sorry if this is more of an assimp question than a D question, but I don't know if it's me misusing D language features or not.
March 26, 2017
On Sunday, 26 March 2017 at 10:34:21 UTC, Dlearner wrote:
> I came back to this project and realised my mistakes (Importer is a class for the C++ API, and we're using the C API).
> So I fixed all my errors, but now I get an access violation.
> As far as I can tell, it seems to be an issue with `aiGetMaterialTexture`.  It is meant to return an aiString with a filename (default value of "$texture.png"), I believe.  But I get:
>
> aiString(13, x"67 6C 61 73 73 5F 64 69 66 2E 70 6E 67 00 FF FF FF ... FF"c)
> [shortened for brevity]

The data is "glass_dif.png", followed by a null terminator, followed by a bunch of 0xFFs. 13 is the length of "glass_dif.png". Judging from the definition of aiString [1], the 0xFFs are just unused space. So, this looks good.

> I'm meant to add this on to a directory string so I can load an image, but obviously this wouldn't work.

To convert an aiString to a D string, it should be possible to slice the data with the length:

    aiString x;
    const(char)[] y = x.data[0 .. x.length];

You have to be cautiots of lifetime requirements, of course. If needed, you can make a copy with dup (mutable copy) or idup (immutable copy):

    const(char)[] y = x.data[0 .. x.length].dup;
    string z = x.data[0 .. x.length].idup;


[1] http://www.assimp.org/lib_html/structai_string.html
March 26, 2017
On Sunday, 26 March 2017 at 11:10:55 UTC, ag0aep6g wrote:
> On Sunday, 26 March 2017 at 10:34:21 UTC, Dlearner wrote:
>> I came back to this project and realised my mistakes (Importer is a class for the C++ API, and we're using the C API).
>> So I fixed all my errors, but now I get an access violation.
>> As far as I can tell, it seems to be an issue with `aiGetMaterialTexture`.  It is meant to return an aiString with a filename (default value of "$texture.png"), I believe.  But I get:
>>
>> aiString(13, x"67 6C 61 73 73 5F 64 69 66 2E 70 6E 67 00 FF FF FF ... FF"c)
>> [shortened for brevity]
>
> The data is "glass_dif.png", followed by a null terminator, followed by a bunch of 0xFFs. 13 is the length of "glass_dif.png". Judging from the definition of aiString [1], the 0xFFs are just unused space. So, this looks good.
>
>> I'm meant to add this on to a directory string so I can load an image, but obviously this wouldn't work.
>
> To convert an aiString to a D string, it should be possible to slice the data with the length:
>
>     aiString x;
>     const(char)[] y = x.data[0 .. x.length];
>
> You have to be cautiots of lifetime requirements, of course. If needed, you can make a copy with dup (mutable copy) or idup (immutable copy):
>
>     const(char)[] y = x.data[0 .. x.length].dup;
>     string z = x.data[0 .. x.length].idup;
>
>
> [1] http://www.assimp.org/lib_html/structai_string.html

Ahh this did help!  I practically followed your advice, then fixed a somewhat unrelated range violation, and got a similar "object.Error@(0): Access Violation".  But in the console I got:
filename: Models/Nanosuit/glass_dif.png
filename: Models/Nanosuit/leg_dif.png
filename: Models/Nanosuit/leg_showroom_spec.png
filename: Models/Nanosuit/hand_dif.png
filename: Models/Nanosuit/hand_showroom_spec.png
filename: Models/Nanosuit/arm_dif.png
filename: Models/Nanosuit/arm_showroom_spec.png
filename: Models/Nanosuit/helmet_diff.png

About half the textures seem to load fine.  Some progress!
March 26, 2017
On Sunday, 26 March 2017 at 12:40:42 UTC, Dlearner wrote:

> ...
> About half the textures seem to load fine.  Some progress!

I don't know why, but when I get to the 8th texture, the filename has some garbage attached.

SDL_Surface* surface = IMG_Load(filename.ptr);
    if (surface is null) {
        writeln("surface is null: ", to!string(IMG_GetError()));
    } else {
        writeln(filename);
    }

From console:
surface is null: Couldn't open Models/Nanosuit/helmet_diff.pngÇ2ÿ

I'm assuming the previous textures didn't experience this, but I have no idea what could be the problem here, especially as the filename seems fine when I writeln it.
:(
March 26, 2017
On 03/26/2017 11:31 PM, Dlearner wrote:
> SDL_Surface* surface = IMG_Load(filename.ptr);
>     if (surface is null) {
>         writeln("surface is null: ", to!string(IMG_GetError()));
>     } else {
>         writeln(filename);
>     }
>
> From console:
> surface is null: Couldn't open Models/Nanosuit/helmet_diff.pngÇ2ÿ
>
> I'm assuming the previous textures didn't experience this, but I have no
> idea what could be the problem here, especially as the filename seems
> fine when I writeln it.
> :(

How do you construct `filename`? Looks like it's not properly null-terminated.

If you followed my (short-sighted) `dup` advice, that doesn't do null-termination. Since the original strings are null-terminated, just slicing one more character should do the trick. I'd put an assert that verifies that the last character is '\0'.

I.e.:
----
string z = x.data[0 .. x.length + 1].idup;
assert(z[$ - 1] == '\0');
----

Generally, don't pass just the pointer of a string unless you know for sure that it's properly null-terminated.

If you're using a slice directly, without `dup`-ing, then the original aiString would seem to be broken already.
March 27, 2017
On Sunday, 26 March 2017 at 21:52:42 UTC, ag0aep6g wrote:
> On 03/26/2017 11:31 PM, Dlearner wrote:
>> SDL_Surface* surface = IMG_Load(filename.ptr);
>>     if (surface is null) {
>>         writeln("surface is null: ", to!string(IMG_GetError()));
>>     } else {
>>         writeln(filename);
>>     }
>>
>> From console:
>> surface is null: Couldn't open Models/Nanosuit/helmet_diff.pngÇ2ÿ
>>
>> I'm assuming the previous textures didn't experience this, but I have no
>> idea what could be the problem here, especially as the filename seems
>> fine when I writeln it.
>> :(
>
> How do you construct `filename`? Looks like it's not properly null-terminated.
>
> If you followed my (short-sighted) `dup` advice, that doesn't do null-termination. Since the original strings are null-terminated, just slicing one more character should do the trick. I'd put an assert that verifies that the last character is '\0'.
>
> I.e.:
> ----
> string z = x.data[0 .. x.length + 1].idup;
> assert(z[$ - 1] == '\0');
> ----
>
> Generally, don't pass just the pointer of a string unless you know for sure that it's properly null-terminated.
>
> If you're using a slice directly, without `dup`-ing, then the original aiString would seem to be broken already.

Ahh you were absolutely right.  I concatenated a '\0' and it worked.  Silly me!
Most of the textures loaded and a really broken model appears, but I'm guessing that's a result of trying to follow along with a tutorial written for C++ in D.
Thank you for your help.  I really appreciate it.  :)
« First   ‹ Prev
1 2