@Bri_G I think this does mostly what you want. This is the original code above, but uses the obj file instead of the positions file. This sizes and centers the models that I tried, so I think it works ok. You can uncomment the line createSphere() to see a white sphere drawn at all the position points. This gave me something to do while I avoided the high temps today, so thanks.
viewer.mode=STANDARD
function setup()
ast=asset.builtin.Watercraft.watercraftPack_003_obj
assert(OrbitViewer, "Please include Cameras as a dependency")
scene = craft.scene()
sc = scene:entity()
sc.model = craft.model(ast)
minMax()
viewer = scene.camera:add(OrbitViewer, vec3(cx,cy,cz), ((sMax/WIDTH)*1500), 0, 2000)
end
function update(dt)
scene:update(dt)
end
function draw()
update(DeltaTime)
scene:draw()
end
function minMax()
minX,minY,minZ=999,999,999
maxX,maxY,maxZ=-999,-999,-999
-- determine min,max values
str=readText(ast)
for a,b,c in string.gmatch(str,"v (%g+) (%g+) (%g+)") do
--createSphere(vec3(a,b,c),.05)
minX=math.min(tonumber(a),minX)
minY=math.min(tonumber(b),minY)
minZ=math.min(tonumber(c),minZ)
maxX=math.max(tonumber(a),maxX)
maxY=math.max(tonumber(b),maxY)
maxZ=math.max(tonumber(c),maxZ)
end
-- center values
cx=(minX+maxX)/2
cy=(minY+maxY)/2
cz=(minZ+maxZ)/2
-- size values
sx=math.abs(minX)+math.abs(maxX)
sy=math.abs(minY)+math.abs(maxY)
sz=math.abs(minZ)+math.abs(maxZ)
-- largest x,y,z size
sMax=math.max(sx,sy)
sMax=math.max(sMax,sz)
print("minX "..minX)
print("maxX "..maxX)
print("centerX ",cx)
print("minY "..minY)
print("maxY "..maxY)
print("centerY ",cy)
print("minZ "..minZ)
print("maxZ "..maxZ)
print("centerZ ",cz)
print("sMax "..sMax)
end
function createSphere(p,s)
local pt=scene:entity()
pt.position=p
pt.model = craft.model.icosphere(s,2)
pt.material = craft.material(asset.builtin.Materials.Specular)
pt.material.diffuse=color(255)
end