Flix - Procedural training and Movie making

You absolute bloody legend!!! Thankyou. It was the commands I was using!!!
Ive changed it to this:

------------------------------------------------------------------------------------------------------------
local ctr = 0
function geom:makeMesh( goname, indices, verts, uvs, normals )

	if(#indices <= 0) then 
		print("[Error] Invalid indices count.")
		return 
	end
	
	--	local mesh = resource.load("/assets/gotemplate/temp.mesh")
	pprint(goname)
	local res = resource.get_buffer(go.get(goname, "vertices"))	
	-- create a cloned buffer resource from another resource buffer
	local newres = resource.create_buffer("/testbuffer_"..string.format("%d", ctr)..".bufferc", { buffer = res })	
	ctr = ctr + 1
	pprint(newres)
	local iverts = #indices

	local meshdata = {}
	-- positions are required (should assert or something)
	tinsert(meshdata, { name = hash("position"), type=buffer.VALUE_TYPE_FLOAT32, count = 3 } )
	if(normals) then tinsert(meshdata, { name = hash("normal"), type=buffer.VALUE_TYPE_FLOAT32, count = 3 } ) end
	if(uvs) then tinsert(meshdata, { name = hash("texcoord0"), type=buffer.VALUE_TYPE_FLOAT32, count = 2 } ) end
	--{ name = hash("color0"), type=buffer.VALUE_TYPE_FLOAT32, count = 4 }
	
	local meshbuf = buffer.create(iverts, meshdata)

	geomextension.setbufferbytesfromtable( meshbuf, "position", indices, verts )
	if(normals) then geomextension.setbufferbytesfromtable( meshbuf, "normal", indices, normals ) end
	if(uvs) then geomextension.setbufferbytesfromtable( meshbuf, "texcoord0", indices, uvs ) end 
		
	-- set the buffer with the vertices on the mesh
	resource.set_buffer(newres, meshbuf)
	go.set(goname, "vertices", newres)
end

------------------------------------------------------------------------------------------------------------

And it is mostly working - need to obviously change the ctr naming. Will do some testing, I will need to pump up the buffer and mesh limits now too. Thankyou for helping, I was really struggling with how you could possibly have done it without a resource!

Thanks again. And I really appreciate the patience and help.
Also, I apologize for not realizing the code I was using was different. Very sorry. Thankyou again.

5 Likes

@d954mas - Again. Cant thank you enough. It looks like this should work.
Im now having material instancing issues, but thats because many of my naming conventions have moved around so they are referencing the wrong objects. A little piccy:


Yes thats an MQ-9 in the bg. :slight_smile:

2 Likes

Welcome, I Iike to read your posts, you make cool things​:+1::+1:

3 Likes

Thanks mate. You make some astonishing projects yourself. You are quite an inspirational developer, so thanks if it hasnt already been said too much :slight_smile:

2 Likes

It’s thanks to @d954mas that we’ve improved the dynamic buffer system quite a bit during the last year :slight_smile:

6 Likes

Thats awesome. And again, you guys are doing a stellar job too. So its appreciated.
@d954mas and @jhonny.goransson - can I do a similar thing with adding materials to a mesh at runtime?
Going to try it to see if its possible.

< update > possibly not. I guess materials need to be compiled (shader wise). hrm.

I think the go instance material is shared among the others. Changing one material changes all of them. Any way around this? Going through the C++ api atm to see if there is something that might help.

Huh. Ok, maybe there is a way. 4 yrs ago there was this:
Change material for sprite in runtime … < fingers crossed > :slight_smile:

Im really not sure right now. Maybe I need to reapply the material to the gameobject? Since Ive changed the uv’s. Not sure. Trying many things, hopefully there is a simple fix for this also.

1 Like

Little video of the odd material behavior.
Essentially Im spawning a go for every mesh, assigning it a new resource buffer, filling it with the appropriate index, position, uvs and normals data and then setting its textures (if there are any).

Hm ok, but they have a shared material? Otherwise it might look like a batch issue

Its a factory generating an instance of a go with a temp mesh.
That temp mesh has an assigned material. I think that material, if I set its textures, will set it for all instances? Unless I can do something similar as the mesh and create a new one and assign it to the go.

< update > It seems sprites/gui elements have access to materials?
go.get("#gui", "materials")
I think this is a valid call on them? On meshes, this is not the case (cant find property materials).

Did some work on sliders for world env settings (clouds, sun and such). This will be hooked up to the ambient and shadows (when I get that in).

3 Likes

Oh. And a little video of panels using slideout animation now. Currently linear, will tweak methods later.

4 Likes

I don’t quite understand what this is useful for, although I appreciate the progress updates. Think you can explain it in terms of a user story?

Its based around a tool for generating a procedural trainer (as mentioned at top). These are simulated training tools that help trainers develop training material for procedures. Some examples:

  • Training white card certification (this is a safety, hazard, and tool use training certification in Australia)
  • For driver training. Develop procedures for trainers to train drivers (trains, cars, etc)
  • Site awareness training. Where for example a mining site needs to induct people for site procedures.

And much more. The aim of this is to be more oriented at people wanting to make interactive videos/runtimes. With a side benefit of also being able to build procedural training content.
It is effectively an editor of sorts. Its much more simplified, so as to allow trainers (and users in this case) to quickly create content, without needing to learn a full 3D editor like Blender for instance.
When the Director (the main interface) is up and running it will make alot more sense. :wink:

1 Like

Some additional info. A user story isnt kinda applicable to this sort of development. Since the user is a trainer, maker, developer, designer - so as a tool its to facilitate what they need to do (much like an editor facilitates developers to build what they want in an engine).

For general users this product is targeting a specific niche of people. It is not really for game developers (although they could use it to make cut-scenes and interactive movies) so its more suited to content creators like indie film makers who want to try out film camera movements, interactions and so on. It is very movie script oriented. There are ways to do this in many other tools, but this is about bringing the availability of making simple CG based action/interaction sequences to everyone. This will be free to use for general users. I dont expect many people to be overly interested, but the commercial side of the same product (with a bunch of other features) will form the basis for procedural trainers in a few different industries.

Hope that helps out a bit. I have a bunch of google docs that go into far more detail, but this isnt really something that will be revolutionary, its more about a market segment Im well versed in, with people I know and the free version is about being able to give customers something to examine before purchasing.

Sorry to hassle. But should a factory instance with a go with a temp mesh on it be able to change it material textures for each instance? Just wanted to check. As Im unsure.

Im going through my own texture/image handling code, and Im wondering if I might have accidentally shared handles somewhere. Which could cause this.

Ok. I think Ive answered my own question. I think if image buffers are all created with a similar resource.create_texture then this should be working. In my old geom extenstion I was using buffer.create, but not resource.create_texture.

Replacing this like the mesh buffer, has yielded some improvements (I think :wink: ). So most of the models are pulling in their own textures (not colors yet, will address that next). It kinda of looks ok. Heres a number of the meshes loaded, and not interfering with each other. The characters shouldnt be white, but I think thats my character img mapping. All the cars should be white or grey (because the loader will colorize them on input if needed).

If anyone is interested in the messy code (and for my future me to look back in disgust on it):

function loadimage(goname, imagefilepath, tid )

	local res, err = image.load(utils.loaddata( imagefilepath ))
	if(err) then print("[Image Load Error]: "..v.uri.." #:"..err) end 

	if(res.buffer ~= "") then
		rgbcount = 3
		if(res.type == "rgba") then res.format = resource.TEXTURE_FORMAT_RGBA; rgbcount = 4 end
		if(res.type == "rgb") then res.format = resource.TEXTURE_FORMAT_RGB; rgbcount = 3 end

		local buff = buffer.create(res.width * res.height, { 
			{	name=hash(res.type), type=buffer.VALUE_TYPE_UINT8, count=rgbcount } 
		})

		geomextension.setbufferbytes( buff, res.type, res.buffer )

		res.type=resource.TEXTURE_TYPE_2D	
		res.num_mip_maps=1

		-- create a cloned buffer resource from another resource buffer
		local new_path = "/imgbuffer_"..string.format("%d", imageutils.ctr)..".texturec"
		local newres = resource.create_texture(new_path, res)	
		imageutils.ctr = imageutils.ctr + 1				

		-- Store the resource path so it can be used later 
		res.resource_path = hash(new_path)
		res.image_buffer = buff 

		resource.set_texture( new_path, res, buff )
		go.set(goname, "texture"..tid, hash(new_path))
		msg.post( goname, hash("mesh_texture") )
	end

	return res
end 
2 Likes

Another quick update. Characters are now working better. The glb files are doing something odd with the internal png conversion though. But its close now, real close :slight_smile:


The Director is well underway too, and I hope to have Ozz animation in over the weekend so these guys and gals can look a little less alphabet like :slight_smile:

< update > The png loader is converting the images for me but I think I have the stride incorrect, so the buffer is warped. Very happy with all this, it should be working properly tomorrow.

5 Likes

Ok. Everything material and mesh wise is all spot on. Big tip, if you are loading at runtime and are using the png-loader extension, it internally flips the image vertically. And on the glb loader I have it works directly with embedded image data thats already in the correct orientation.


Glad it was an easy fix. Onto anim and camera controls for the director.

3 Likes

Interesting find in recent gltf investigations.
There are many gltf files that do not have indicies set on their primitives (they are just pure mesh buffers). And because of this, if you are using indices it wont load a mesh for it.
As mentioned here: https://github.com/assimp/assimp/issues/2046 Assimplib has added a patch for this so there is a ‘fall through’.
Had me puzzled with a couple of large scenes I had. Missing geom etc.

1 Like

Environments now sorted as well. Heres what some 12,000 meshes in Defold looks like (with silly single point light :slight_smile: ).


Frame rate is a bit average (scene is not really optimized yet) around 20fps. Its still quite good since this is quite a complicated gltf (has all manner of index types, and data types in it).
The big benefit of keeping these large scenes with separate meshes is in the case of needing to be interactive with other objects. Ie: car runs into tree, or light pole. etc.
Might add some illumination with the anim this afternoon.

Note to self - need to get transparent materials working (update render_script to support).

2 Likes