LibLoad collision

Hi,

I’m creating an game and I load the objects using libload


dir = bge.logic.expandPath("//")
for lib in libs: # []
  bge.logic.LibLoad(dir + lib, "Mesh")

for obj in libObjects: # [] - meshNames from loaded lib
  sampleObject = scene.addObject("singleVertex", someRandomObj)# single vertex object
  sampleObject.replaceMesh(obj)

but the collision is not copied, how could I do that.
And how to get the objects loaded from an lib? (I use an second file now and replace the .blend with .info and add the content to libObjects

The ‘replacemesh’ function takes some other parameters:


replaceMesh(<i>mesh</i>, <i>useDisplayMesh=True</i>, <i>usePhysicsMesh=False</i>)

As @sdfgeoff says, it should be replaceMesh(obj, True, True).

Also, notice that with libload on ‘scene’ mode and using binary data with diferent names you can efectively create completly new objects (and multiple of them) from a single “.blend” file (wich should contain only one object). In your code replacing the physical mesh of “simpleObject” will also replace the physical mesh of any other instance of “singleVertex”, I suspect that’s not what you want.

Thanks sdfgeoff!
It works after moving the objects in the lib to the second layer and using LibLoad with scene and add the using scene.addObject
But with LibLoad using Mesh and replaceMesh(mesh, True) or replaceMesh(mesh, True, True) does not work, the collision bounds is not changing and the object still falls thru. But that’s is not a big deal anymore using libload with Scene.

And is there a way the get the objects loaded from the scene?
I was thinking of:


currentObjects = scene.objects
bge.logic.LibLoad(STUFF)
for obj in scene.objects:
    if obj not in currentObjects:
        loadedLibObjects.append(obj)

The problem is that scene.objects uses the object name as identifier an it is replaced every time you load a new object, therefore you need to list them in time of loading and store them somewhere else. In BGECore I use a special object which is the one that represents the blend file and you access the copies from it (it stores a list of copies of itself). You can check exactly how is done in the source code (the ObjectGenerator class and the blend file): https://github.com/elmeunick9/BGECore/blob/master/template/data/core/dynamic.py

I suspect that because it’s a single vertex, some funny things happen. Instead of a single vertex, try making it a really scaled down cube.

The easiest way to check for added objects is to give every object a property and check for it:


for obj in scene.objectsInactive:
    obj['__LOADED__'] = 1

bge.logic.libload....

added_objects = [o for o in scene.objectsInactive if '__LOADED__'] not in o]

That code snipped only does objects on an inactive layer, but it should be easy to change it to active ones.

Thanks!
It is now fully working :smiley: