2
$\begingroup$

For my game I would like to create an impass map from an image-file, so I don't have to manually set every cell to passable or impassable, but I just cannot figure out any way of reading an image file to feed a library.

I would have guessed the VideoTexture module is the way to go, but even the simplest experiments couldn't give me any results:

print(bge.texture.ImageFFmpeg(logic.expandPath('//image.png')).valid)

This only prints False even though the image.png is in the same folder like the .blend file. Am I doing it wrong? Or would you recommend a completely different approach for this matter?

EDIT: I need a method to create a dynamically changable map where my characters find their way through with path-finding.

$\endgroup$

1 Answer 1

2
$\begingroup$

I realize you're kinda asking for a scripting answer, but hopefully this will be of use.

First start out with a map (white is wall, black is no wall). This one is 16x16:

Map

That's all it is. A 16x16 png file. Now go into blender, create a plane, TAB into edit mode, and add ringcuts in both directions equal to the size of the map minus one. Since my map is 16x16, I should add 15x15 ringcuts. The shortcut for that would be CTRL + R15. You'll end up with:

16x16 squares

Press A to select everything, and then ALT + E to extrude each face individually. If a little window pops up, click on Individual Faces. Press Esc to save the extrude, but keep the new faces in the same place as the old faces.

Keeping the new faces selected, press CTRL + G and click Assign to New Group to assign these extruded faces to their own group. We'll be using this a bit later.

Still with these same faces selected, press CTRL + . to cause each face to scale around it's own center, and then press S and scale all the faces down ever so slightly. Seriously. Just barely.

Yay

One last step. You can come back into object mode with Tab, go to the modifiers panel (it looks like this: Modifier icon) and add a new displacement modifier.

Displacement Modifier

Click New under Texture, then go to the texture panel (Texture Panel), click Open, and browse to your map png.

IMPORTANT: Under Image Sampling, uncheck Interpolation!

Finally, go back to the modifier panel, select the vertex group we created, and set the Midlevel to 0. And viola!

Render 1

You can change the image map and then refresh it in the texture panel, and it will instantly update the model.

Render 2

Simply make the mesh invisible in your game, and have the walls sticking up through your floor. I'm sure there's a way to script this, I'm just not very proficient with blender scripting :)

$\endgroup$
5
  • $\begingroup$ Well thats quite the solution here, but there's a reason I was looking for a script solution: I need to generate a library of the map that says which field is passable and which is impassable so my pathfinding script will find its way through. Also the scripting solution can be modified during the game, while a displaced mesh can't. (I guess..) $\endgroup$
    – HeaX
    Commented Dec 2, 2014 at 17:34
  • $\begingroup$ @HeaX Ahh... you didn't include the purpose in your question so I had to make assumptions :) Well I think you can set the image for the displace modifier during the script, so that will let you change the map, but I doubt I can help with the pathfinding. What pathfinding method are you using? $\endgroup$
    – Entity
    Commented Dec 2, 2014 at 17:41
  • $\begingroup$ Sorry I didn't include the purpose in my question, I'll fix that to avoid further confusion. I'm currently using a script I wrote myself based on the "Sample Algorithm" from this wikipedia article: en.wikipedia.org/wiki/Pathfinding $\endgroup$
    – HeaX
    Commented Dec 2, 2014 at 18:11
  • $\begingroup$ @HeaX Hm... maybe this link can help? blender.stackexchange.com/questions/3673/… $\endgroup$
    – Entity
    Commented Dec 2, 2014 at 18:31
  • 1
    $\begingroup$ BTW you can use [W] > subdivide and then hit [F6] and change the number of subdivisions to 15 instead of adding loop cuts. $\endgroup$
    – PGmath
    Commented Dec 3, 2014 at 23:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .