Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Creating an object from memblocks

Author
Message
Harlequin
14
Years of Service
User Offline
Joined: 22nd Mar 2010
Location: Melbourne (AU)
Posted: 22nd Sep 2016 07:07
Hi all,

I am looking to create a randomised object, basically a very low poly style (no smoothing so poly count would be only in the low 5000's) flat terrain that continuously generates as the player moves forward.

I think I need to use memblocks to create it from scratch, but I am struggling to get my head around how to build an object via this way. I have created images with memblocks so I understand the some of the basics of memblocks.

What I would like is an example of an object created via memblocks so I can see the type of values that need to be populated in the various bytes.
But reading through the doc for "CreateObjectFromMeshMemblock" it looks like it may not be worth trying to create it due to the anount of data I need to popluate.

I guess an anternative would be to create a flat plane and modify it directly by loading it into a memblock manipulating it and creating a new object to display?

Any ideas?

thanks
It\'s late, I\'m tired, out of coffee and now I\'m wet.
Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 22nd Sep 2016 08:36
Try CreateObjectFromHeightMap, you could manipulate your 2D-Height-Map-Image in Memory.

After that, you could manipulate the Memory-Mesh with some of these

AddObjectMeshFromMemblock
CreateMemblockFromObjectMesh
CreateObjectFromMeshMemblock
GetMeshMemblockVertexNormalX
GetMeshMemblockVertexNormalY
GetMeshMemblockVertexNormalZ
GetMeshMemblockVertexU
GetMeshMemblockVertexV
GetMeshMemblockVertexX
GetMeshMemblockVertexY
GetMeshMemblockVertexZ
SetMeshMemblockVertexNormal
SetMeshMemblockVertexPosition
SetMeshMemblockVertexUV
SetObjectMeshFromMemblock

You don't have to manipulate the "Memoryblock" directly
Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 22nd Sep 2016 08:41
You could also think about creating a bunch of X-Files, load them, and create from them Memblocks. Maybe you don't need Memblocks for 3D-Objects. If it is for terrain, you could do it with randomly generated images. You also could write you some image-manipualting algorithms and combine 2D-Heightmaps in any way.
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 22nd Sep 2016 19:14
Another method is to create object files on the fly and load them back in. I use this method and works well for me. All you need to do is learn the obj file format. Its txt based and easy to figure out.
Harlequin
14
Years of Service
User Offline
Joined: 22nd Mar 2010
Location: Melbourne (AU)
Posted: 23rd Sep 2016 05:48
Thanks for the replies all.
I'll look at both options (extra knowledge can be usefull), if I get something working I'll post it here for posterities sake

It\'s late, I\'m tired, out of coffee and now I\'m wet.
Harlequin
14
Years of Service
User Offline
Joined: 22nd Mar 2010
Location: Melbourne (AU)
Posted: 28th Sep 2016 07:55 Edited at: 28th Sep 2016 07:57
Am I not understanding this correctly?
I exported as Wavefront OBJ file the basic cube from Blender (no changes or anything).
My understanding is that there are 8 vertices in a cube (the file below indicates this as well).
If I use the command
SetMeshMemblockVertexPosition( mem, 0, 5.000000, -5.000000, 5.000000)
I can manipulate vertex 0 (as expected)
BUT if I use this command I can manipulate vertex 23, which should not exist it does actually change the cube's appearance so it is manipulating the cube.
SetMeshMemblockVertexPosition( mem, 23, 5.000000, -5.000000, 5.000000)

This to me makes zero sense, so I must be misunderstanding it, can somebody explain it to me.

thanks

Crappy Program Code I use to test all of this


Object file contents below
Quote: "
# Blender v2.77 (sub 0) OBJ File: ''
# www.blender.org
mtllib cube.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
vn 1.0000 0.0000 0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
usemtl Material
s off
f 1//1 2//1 3//1 4//1
f 5//2 8//2 7//2 6//2
f 1//3 5//3 6//3 2//3
f 2//4 6//4 7//4 3//4
f 3//5 7//5 8//5 4//5
f 5//6 1//6 4//6 8//6
"
It\'s late, I\'m tired, out of coffee and now I\'m wet.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 28th Sep 2016 09:34
I guess it depends how the cube is made. It is use two triangles per face, and stores each vertex for each triangle, then you'd have 6x2x3=36 vertices.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Preben
AGK Studio Developer
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 29th Sep 2016 13:21
SetMeshMemblockVertexPosition( mem, 23, 5.000000, -5.000000, 5.000000)

Dont think agk check if the vertex exist , but just write to the correct position in the memblock , so your properly just changing the faces instead. here is some code that give you more information about the memblock and the vertices ,sample just give you the size of the object but you can use the information it collect:

best regards Preben Eriksen,
Harlequin
14
Years of Service
User Offline
Joined: 22nd Mar 2010
Location: Melbourne (AU)
Posted: 1st Oct 2016 08:46
Hi Everyone,

Thanks for everyone's suggestions and pointers.

After quite a bit of fiddling and testing, I have some working code (pasted below). The biggest issue is that Blender when exporting an obj file messes up the vertex order something massively. This cost me a bit of time, so I used Milkshape3d (trial version - going to by this awsome tool!!) to export a plane and get the vertices correct.
Attached is a zipfile of my code, the objects required, shaders and the like (shaders are from the Terrain example in AGK).

Comments and code need some work, but I just wanted to get something up tonight.



I will update with my example as I progress more. Code is free to use, change whatever for the community.

cheers
It\'s late, I\'m tired, out of coffee and now I\'m wet.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-25 02:01:40
Your offset time is: 2024-11-25 02:01:40