Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Need a little help porting an example... #7

Open
Skaruts opened this issue May 13, 2020 · 4 comments
Open

Need a little help porting an example... #7

Skaruts opened this issue May 13, 2020 · 4 comments

Comments

@Skaruts
Copy link

Skaruts commented May 13, 2020

I was trying to port the first person maze example, and came across this:

Model model = LoadModelFromMesh(mesh);
//(...)
model.materials[0].maps[MAP_DIFFUSE].texture = texture;             // Set map diffuse texture

And I'm not being able to translate that second line there, because it involves C array pointers, and I don't quite know how to work with those in Nim.
Someone suggested that I use UncheckedArrays, and I used that successfully with Image data in another example, but here I'm not managing to. I tried this but didn't work:

var mats = cast[ptr UncheckedArray[Material]](model.materials)
var maps = cast[ptr UncheckedArray[MaterialMap]](mats[0])         # <--- line 42
maps[MAP_DIFFUSE].texture = texture                  
... first_person_maze.nim(42, 15) Error: expression cannot be cast to ptr UncheckedArray[MaterialMap]
@Skaruts
Copy link
Author

Skaruts commented May 13, 2020

Well I atually figured it out shortly after posting this...
This works.

let maps = cast[ptr UncheckedArray[MaterialMap]](mats[0].maps)  # <-- I had neglected '.maps'

Although I'm still having trouble getting anything to render -- I just get blank screen when I run it -- which may be related to what I'm doing there. When I press escape to quit I get a storage access error:

... first_person_maze.nim(123)
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

and line 123 is

UnloadModel(model)

But model isn't nil...

@Skaruts Skaruts closed this as completed May 13, 2020
@Skaruts Skaruts reopened this May 13, 2020
@Guevara-chan
Copy link
Owner

I'm trying to convert this sample myself. Something seems to be wrong with collisions.

@Skaruts
Copy link
Author

Skaruts commented May 14, 2020

Thanks.
There are problems with collisions in the original too, though.

@Guevara-chan
Copy link
Owner

Well, what I found so far is that problem lies with mesh generation - it only creates disjointed triangles with mangled plane on 0,0,0. Not so sure why, investigating.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants