Vizard 8 » Tutorials & Examples » Publishing as an EXE » Adding Resources
8.1

Adding Resources

Files that are dynamically loaded may not be automatically detected by the publish wizard. Common examples of this include files loaded after user defined events and timer expirations, and files loaded in later phases of an application (e.g. viztask function). Add the following code and run the script. Press the space bar to load the dojo model:

def addSceneModel():
    viz.add('dojo.osgb')
    
vizact.onkeydown(' ',addSceneModel)

Next, follow the publish process as in the previous section. Make sure:

  1. That you don't press the space bar while the script runs in Step 1.
  2. You enable the Display console option in Step 2.

This is a short exercise showing how to create and detect an error in the publish process. The published EXE references a file dojo.osgb that's not included in the final build. Run the EXE and press the space bar; nothing happens. Look in the console and you should see the error:

ERROR: Failed to load model: 'dojo.osgb'

This message is generated if a file is not included in the EXE. There are two ways to resolve this type of error:

  1. Trigger all scenarios where files are dynamically loaded during Step 1 of the publish process. This is the recommended method whenever possible. For this example, it would require pressing the space bar so the dojo gets loaded.
  2. In the script, specify file(s) that should be added to the dependency list. In this case the following line of code should be added:
    #Add file to publish exe
    viz.res.addPublishFile('dojo.osgb')

Go ahead and re-publish the script. This time press the spacebar during Step 1. Browse through the dependency list and you should see dojo.osgb included.

Add File Loaders

In addition to the resource itself (e.g. model, image, media file), the EXE requires specific file loader(s) for each file extension. Vizard will automatically detect all file loader plugins that are used during the publish process. However, if your script dynamically loads certain files, then the file loader plugin might not be included in your published executable. For example, if a dynamically loaded model references external texture files, the image loader for those textures may not be included.

 

To manually add a file loader use the viz.res.addPublishFileLoader() command:

# Support loading PNG images  
viz.res.addPublishFileLoader('png')

# Support loading FBX models
viz.res.addPublishFileLoader('fbx')

To add image loaders for common image types to the EXE, use the viz.res.addPublishImageLoaders() command:

# Support loading all common image types 
viz.res.addPublishImageLoaders()

Add a Directory of Files

Sometimes it's helpful to specify all the files or files of a certain type within a directory. For example, the following adds all osgb files from the resource directory of the Vizard installation to the dependency list:

#Add all osgb files from vizard resource directory
resourcePath = viz.res.getVizardPath() + '/resources'
viz.res.addPublishDirectory(resourcePath,'*.osgb')

Using the Publish Wizard

Adding Resources

Accessing Data Files