Results 1 to 2 of 2

Thread: Script access to session decal library

  1. #1

    Script access to session decal library

    Currently it is possible to place decals by script, but you have to have the link for that decal, and the scripting environment has no access to the decals that can be placed by players.

    As far as I can tell, the decals that can be placed by players currently have to be imported one-by-one into any session.

    It would be useful for the script environment to be able to (at least) add decals to the library of decals placeable by the player, as well as get a table of the decals in that library for purposes of mapping decal names to links.

    I have worked around this, at this time, by creating a "decal library" object and script and adding a bit of script to the global environment. This creates a mapping of names to decal links, but does not allow the player to place them readily.

    Code:
    function onload(saved_data)
    	updateDecals()
    end
    function onDropped(_color)
    	updateDecals()
    end
    
    function updateDecals()
    	local decalMap = Global.call('getDecalMap')
    	local decalTable = self.getDecals() or {}
    
    	-- add any decals on object to the map / update existing
    	for i=1, #decalTable do
    		decalMap[decalTable[i].name] = decalTable[i].url
    	end
    	
    	-- clear decals on this object
    	decalTable = {}
    	self.setDecals({})
    
    	-- gather information on all decals
    	local count = 0
    	for k,v in pairs(decalMap) do
    		count = count + 1
    		local decal = {}
    		decal.name = k
    		decal.url = v
    		table.insert(decalTable, decal)
    	end
    
    	table.sort (decalTable, function (k1, k2) return k1.name < k2.name end )
    
    	-- x * x * 1.5 > count
    	local maxX = math.ceil(math.sqrt(count / 1.5)) - 1
    	local scale = 2.0 / (maxX + 1)
    	local x = 0
    	local y = 0
    	for _,v in ipairs(decalTable) do
    		v.position = {-x * scale + 1.0 - scale/2, 1.2, y * scale - 1.5 + scale/2}
    		v.rotation = {90,180,0}
    		v.scale = {scale,scale,1.0}
    		if (x < maxX) then
    			x = x + 1
    		else
    			x = 0
    			y = y + 1
    		end
    	end
    
    	-- we do this several times as there appears to be an issue with updates
    	--- seemingly, setDecals doesn't clear all of the existing decals (even after the earlier clear).
    	--- There do not seem to be issues with it not adding new ones, only not removing old ones.
    	self.setDecals(decalTable)
    	self.setDecals(decalTable)
    	self.setDecals(decalTable)
    end
    
    --- Add to Global script
    function getDecalMap()
    	decalMapTable = decalMapTable or {}
    	return decalMapTable
    end



    Thank you for all of the hard work and time! Tabletop Simulator is an excellent tool and toy.

  2. #2
    Yea agreed, this would be quite cool

Similar Threads

  1. Don't go back to page 1 after selecting a decal
    By Unreal_Ed in forum Suggestions
    Replies: 0
    Last Post: 10-02-2018, 10:55 AM
  2. Decal tool that uses snap points
    By Unreal_Ed in forum Suggestions
    Replies: 0
    Last Post: 09-20-2018, 12:42 PM
  3. Decal Support
    By Horikawa Otane in forum Scripting
    Replies: 2
    Last Post: 07-26-2018, 01:24 PM
  4. Decal Layering
    By Mark in forum Suggestions
    Replies: 1
    Last Post: 10-08-2017, 03:37 AM
  5. Request: script access to player hand zone
    By dizneyguy in forum Scripting
    Replies: 1
    Last Post: 05-23-2016, 02:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •