Ok, now I understand a bit better. You have several possibilities.
First of all, if your script runs threaded, then you should forbit thread switches during the creation of the
points:
Code: Select all
function sysCall_init()
corout=coroutine.create(coroutineMain)
end
function sysCall_actuation()
if coroutine.status(corout)~='dead' then
local ok,errorMsg=coroutine.resume(corout)
if errorMsg then
error(debug.traceback(corout,errorMsg),2)
end
end
end
function SpawnPoint()
POINTArray[#POINTArray+1]=sim.copyPasteObjects({point},0)[1]
local position=RANDTable[#POINTArray]
sim.setObjectPosition(POINTArray[#POINTArray],-1,position)
end
function coroutineMain()
...
-- temporarily forbid automatic thread switches:
local l=sim.setThreadAutomaticSwitch(false)
for i=1,100,1 do
SpawnPoint()
end
-- Restore the automatic thread switching:
sim.setThreadAutomaticSwitch(l)
...
end
Next, you can save a copy operation at each point creation if you use sim.saveModel and sim.loadModel, saving and loading to/from buffer, e.g.:
Code: Select all
function sysCall_init()
corout=coroutine.create(coroutineMain)
end
function sysCall_actuation()
if coroutine.status(corout)~='dead' then
local ok,errorMsg=coroutine.resume(corout)
if errorMsg then
error(debug.traceback(corout,errorMsg),2)
end
end
end
function SpawnPoint(modelData)
POINTArray[#POINTArray+1]=sim.loadModel(modelData)
local position=RANDTable[#POINTArray]
sim.setObjectPosition(POINTArray[#POINTArray],-1,position)
end
function coroutineMain()
local serializedModel=sim.saveModel(originalModel)
...
-- temporarily forbid automatic thread switches:
local l=sim.setThreadAutomaticSwitch(false)
for i=1,100,1 do
SpawnPoint(serializedModel)
end
-- Restore the automatic thread switching:
sim.setThreadAutomaticSwitch(l)
...
end
For above to work, you will need to have a model first. You can do it via the API like:
Code: Select all
local saveProp=sim.getModelProperty(originalObject)
sim.setModelProperty(originalObject,0) -- this make a model from originalObject
local serializedModel=sim.saveModel(originalObject)
sim.setModelProperty(originalObject,saveProp)
And of course, if you simply need visualization of spheres, you can also use drawing objects:
Code: Select all
local sphereContainer=sim.addDrawingObject(sim.drawing_spherepoints,0.1,0,-1,100,color)
while true do
sim.addDrawingObjectItem(sphereContainer,nil) -- clear the container
for i=1,100,1 do
local position={math.random(),math.random(),math.random()}
sim.addDrawingObjectItem(sphereContainer,position)
end
end
Cheers