Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
I3DManager
DescriptionThis class provides tools for loading shared i3d files. Access using g_i3DManagerParent
AbstractManagerFunctions
- deleteSharedI3DFiles
- fillSharedI3DFileCache
- initDataStructures
- loadSharedI3DFile
- loadSharedI3DFileFinished
- new
- releaseSharedI3DFile
deleteSharedI3DFiles
DescriptionClears i3d cacheDefinition
deleteSharedI3DFiles()Code
158 | function I3DManager:deleteSharedI3DFiles() |
159 | for _, sharedI3D in pairs(self.sharedI3DFiles) do |
160 | if sharedI3D.nodeId ~= 0 then |
161 | delete(sharedI3D.nodeId) |
162 | end |
163 | end |
164 | self.sharedI3DFiles = {} |
165 | end |
fillSharedI3DFileCache
DescriptionAdds an i3d file to cacheDefinition
fillSharedI3DFileCache(string filename, string baseDir)Arguments
string | filename | filename |
string | baseDir | baseDir |
125 | function I3DManager:fillSharedI3DFileCache(filename, baseDir) |
126 | local filename = Utils.getFilename(filename, baseDir) |
127 | local sharedI3D = self.sharedI3DFiles[filename] |
128 | |
129 | if sharedI3D == nil then |
130 | local nodeId = loadI3DFile(filename, false, false) |
131 | local sharedI3D = {nodeId=nodeId, refCount=0} |
132 | self.sharedI3DFiles[filename] = sharedI3D |
133 | end |
134 | end |
initDataStructures
DescriptionInitialize data structuresDefinition
initDataStructures()Code
24 | function I3DManager:initDataStructures() |
25 | self.sharedI3DFiles = {} |
26 | self.sharedI3DFilesPendingCallbacks = {} |
27 | end |
loadSharedI3DFile
DescriptionLoads an i3D file. A cache system is used for faster loadingDefinition
loadSharedI3DFile(string filename, string baseDir, boolean callOnCreate, boolean addToPhysics, boolean verbose, function asyncCallbackFunction, table asyncCallbackObject, table asyncCallbackArguments)Arguments
string | filename | filename |
string | baseDir | baseDir |
boolean | callOnCreate | true if onCreate i3d callbacks should be called |
boolean | addToPhysics | true if collisions should be added to physics |
boolean | verbose | verbose |
function | asyncCallbackFunction | a callback function |
table | asyncCallbackObject | callback function target object |
table | asyncCallbackArguments | a list of arguments |
integer | id | i3d rootnode |
40 | function I3DManager:loadSharedI3DFile(filename, baseDir, callOnCreate, addToPhysics, verbose, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments) |
41 | callOnCreate = Utils.getNoNil(callOnCreate, false) |
42 | addToPhysics = Utils.getNoNil(addToPhysics, false) |
43 | local filename = Utils.getFilename(filename, baseDir) |
44 | local sharedI3D = self.sharedI3DFiles[filename] |
45 | |
46 | -- always print all loading texts |
47 | verbose = true |
48 | |
49 | if asyncCallbackFunction ~= nil then |
50 | if sharedI3D == nil then |
51 | |
52 | local callbacks = self.sharedI3DFilesPendingCallbacks[filename] |
53 | if callbacks == nil then |
54 | self.sharedI3DFilesPendingCallbacks[filename] = {} |
55 | table.insert(self.sharedI3DFilesPendingCallbacks[filename], {callOnCreate, addToPhysics, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments}) |
56 | streamI3DFile(filename, "loadSharedI3DFileFinished", self, {filename}, false, false, verbose) |
57 | else |
58 | table.insert(callbacks, {callOnCreate, addToPhysics, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments}) |
59 | end |
60 | else |
61 | local id = 0 |
62 | |
63 | if sharedI3D.nodeId == 0 then |
64 | print("Error: failed to load i3d file '"..filename.."'") |
65 | else |
66 | id = clone(sharedI3D.nodeId, false, callOnCreate, addToPhysics) |
67 | end |
68 | |
69 | sharedI3D.refCount = sharedI3D.refCount+1 |
70 | asyncCallbackFunction(asyncCallbackObject, id, asyncCallbackArguments) |
71 | end |
72 | else |
73 | if sharedI3D == nil then |
74 | local nodeId = loadI3DFile(filename, false, false, verbose) |
75 | sharedI3D = {nodeId=nodeId, refCount=0} |
76 | self.sharedI3DFiles[filename] = sharedI3D |
77 | end |
78 | |
79 | local id = 0 |
80 | if sharedI3D.nodeId == 0 then |
81 | print("Error: failed to load i3d file '"..filename.."'") |
82 | else |
83 | id = clone(sharedI3D.nodeId, false, callOnCreate, addToPhysics) |
84 | end |
85 | |
86 | sharedI3D.refCount = sharedI3D.refCount + 1 |
87 | |
88 | return id |
89 | end |
90 | end |
loadSharedI3DFileFinished
DescriptionCalled once i3d loading is finishedDefinition
loadSharedI3DFileFinished(integer nodeId, table arguments)Arguments
integer | nodeId | i3d node id |
table | arguments | a list of arguments |
96 | function I3DManager:loadSharedI3DFileFinished(nodeId, arguments) |
97 | local filename = arguments[1] |
98 | local callbacks = self.sharedI3DFilesPendingCallbacks[filename] |
99 | local sharedI3D = {nodeId=nodeId, refCount=0} |
100 | |
101 | self.sharedI3DFilesPendingCallbacks[filename] = nil |
102 | self.sharedI3DFiles[filename] = sharedI3D |
103 | |
104 | if nodeId == 0 then |
105 | print("Error: failed to load i3d file '"..filename.."'") |
106 | end |
107 | |
108 | for _,callback in pairs(callbacks) do |
109 | local callOnCreate, addToPhysics, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments = unpack(callback) |
110 | local id = 0 |
111 | |
112 | if sharedI3D.nodeId ~= 0 then |
113 | id = clone(sharedI3D.nodeId, false, callOnCreate, addToPhysics) |
114 | end |
115 | |
116 | sharedI3D.refCount = sharedI3D.refCount+1 |
117 | asyncCallbackFunction(asyncCallbackObject, id, asyncCallbackArguments) |
118 | end |
119 | end |
new
DescriptionCreating managerDefinition
new()Return Values
table | instance | instance of object |
16 | function I3DManager:new(customMt) |
17 | local self = AbstractManager:new(customMt or I3DManager_mt) |
18 | |
19 | return self |
20 | end |
releaseSharedI3DFile
DescriptionReleases one instance. If autoDelete is true and instance count <= 0. I3d will be removed from cacheDefinition
releaseSharedI3DFile(string filename, string baseDir, boolean autoDelete)Arguments
string | filename | filename |
string | baseDir | baseDir |
boolean | autoDelete | true if file should be removed from cache if instance count is <= 0 |
141 | function I3DManager:releaseSharedI3DFile(filename, baseDir, autoDelete) |
142 | local filename = Utils.getFilename(filename, baseDir) |
143 | local sharedI3D = self.sharedI3DFiles[filename] |
144 | |
145 | if sharedI3D ~= nil then |
146 | sharedI3D.refCount = sharedI3D.refCount-1 |
147 | if autoDelete and sharedI3D.refCount <= 0 then |
148 | if sharedI3D.nodeId ~= 0 then |
149 | delete(sharedI3D.nodeId) |
150 | end |
151 | self.sharedI3DFiles[filename] = nil |
152 | end |
153 | end |
154 | end |