Hi, I am doing the same thing. I also modified the importer script:
Code: Select all
function sysCall_init()
model=sim.getObjectAssociatedWithScript(sim.handle_self)
size=1
col={255,255,255}
if sim.getSimulationState()==sim.simulation_stopped then
showDlg()
end
end
importClicked_callback=function()
local files=sim.fileDialog(sim.filedlg_type_load_multiple,'*.xyz point cloud import','','','*.xyz','xyz')
if files then
local pc=sim.createPointCloud(0.02,20,0,size)
for token in (files..";"):gmatch("([^;]*);") do
local pts={}
local cols={}
for line in io.lines(token) do
local c=0
for coord in line:gmatch("([^\9 ]+)") do
if c>=3 then
cols[#cols+1]=coord
else
pts[#pts+1]=coord
end
c=c+1
end
end
local opt=0
if #pts==#cols then
opt=2
col=cols
end
sim.insertPointsIntoPointCloud(pc,opt,pts,col)
end
end
end
function ptSizeChange_callback(ui,id,newVal)
local v=tonumber(newVal)
if v then
v=math.floor(v)
if v<1 then v=1 end
if v>5 then v=5 end
size=v
end
simUI.setEditValue(ui,2,tostring(size),true)
end
function colorChange_callback(ui,id,newVal)
local i=1
for token in (newVal..","):gmatch("([^,]*),") do
local v=tonumber(token)
if v==nil then v=0 end
if v>1 then v=1 end
if v<0 then v=0 end
col[i]=v*255
i=i+1
end
simUI.setEditValue(ui,3,(col[1]/255)..','..(col[2]/255)..','..(col[3]/255),true)
end
function onCloseClicked()
sim.removeObject(model)
end
function createDlg()
if not ui then
xml = [[
<ui title="Point Cloud Importer" closeable="true" on-close="onCloseClicked" resizable="false">
<group layout="form" flat="true">
<label text="Point size"/>
<edit oneditingfinished="ptSizeChange_callback" id="2"/>
<label text="RGB color"/>
<edit oneditingfinished="colorChange_callback" id="3"/>
</group>
<button text="Import *.xyz file" checked="false" on-click="importClicked_callback" id="1" />
<label text="" style="* {margin-left: 380px;}"/>
</ui>
]]
ui=simUI.create(xml)
if previousDlgPos then
simUI.setPosition(ui,previousDlgPos[1],previousDlgPos[2],true)
end
simUI.setEditValue(ui,2,tostring(size),true)
simUI.setEditValue(ui,3,(col[1]/255)..','..(col[2]/255)..','..(col[3]/255),true)
end
end
function showDlg()
if ui then
simUI.show(ui)
else
createDlg()
end
end
function removeDlg()
if ui then
local x,y=simUI.getPosition(ui)
previousDlgPos={x,y}
simUI.destroy(ui)
ui=nil
end
end
function sysCall_afterSimulation()
showDlg()
end
function sysCall_beforeSimulation()
removeDlg()
end
function sysCall_cleanup()
removeDlg()
end
I get the same error
Code: Select all
stack traceback:
[C]: in function 'insertPointsIntoPointCloud'
[string "CUSTOMIZATION SCRIPT pointCloudImporter"]:34: in function <[string "CUSTOMIZATION SCRIPT pointCloudImporter"]:11>
Error: [string -unknown location]:?: simCallScriptFunctionEx: error (importClicked_callback)
The scene is an empty one and the object is a .xyz file of a chair found in the web.
Maybe I am not using the correct settings in the window with "Point size" = 1, and "RGB color" = 1,1,1.
Are those one to be modified accordingly to the file?
Some of the code lines:
Code: Select all
0.188121 -0.200840 0.030627
-0.182903 -0.006469 -0.000073
-0.205165 -0.277344 0.030627
-0.205094 -0.277209 0.031238
-0.207391 -0.310896 0.030933
-0.207505 -0.310389 0.030383
-0.207173 -0.325028 0.031879
I also tried the code lines posted by kilian_ft but got the same result.
Thanks in advance for your help