Kanzi  3.9.7
Kanzi Studio API
FileSystemProjectItem Interface Reference

Access resource files such as images, shader source files, and 3D assets. More...

Properties

string FileSystemParentDirectory [get]
 Gets the path to the directory in which a resource file is stored. More...
 
string FileSystemPath [get]
 Gets the full path to a resource file. More...
 

Detailed Description

Access resource files such as images, shader source files, and 3D assets.

Resource file items are project items that represent the files in the resource file directories of the project directory.

Property Documentation

string FileSystemParentDirectory
get

Gets the path to the directory in which a resource file is stored.

See also
Project.ImageDirectory

Examples

To get the path to the Images directory of a Kanzi Studio project:

public void Execute(PluginCommandParameter parameter)
{
// Get the Images directory which contains the image files in a Kanzi Studio project.
var imageDirectory = studio.ActiveProject.ImageDirectory;
// Get an image file in the Images directory.
var imageFile = imageDirectory.Children.OfType<ImageFile>().First();
// Print the path to the Images directory to the Kanzi Studio Log window.
studio.Log("The image files of this project are stored in " + imageFile.FileSystemParentDirectory);
}
string FileSystemPath
get

Gets the full path to a resource file.

See also
Project.ShaderSourceDirectory, Project.MaterialTypeLibrary, Project.MaterialLibrary

Examples

To create a function that creates a material type from vertex and fragment shaders:

// Create a function that creates a Material Type and takes as its input the paths to the files
// that contain the vertex and fragment shaders for this material type.
private void CreateMaterialType(string name, string vertexShaderPath, string fragmentShaderPath)
{
// Create a Material Type in the Library > Materials and Textures > Material Types library.
var materialTypeLibrary = studio.ActiveProject.MaterialTypeLibrary;
var materialType = studio.ActiveProject.CreateProjectItem<MaterialType>(
materialTypeLibrary.GenerateUniqueChildName(name), materialTypeLibrary);
// Set the material type you created to use the vertex shader that you pass to the function.
// Read the content of the file which contains the vertex shader code that you want to use.
// To use this function, in the class library file that implements the PluginCommand interface
// add the using directive for the System.IO namespace.
string vertexShaderSource = File.ReadAllText(vertexShaderPath);
// Get the vertex shader of the material type you created.
var vertexShader = materialType.Children.OfType<VertexShader>().First();
// Get the vertex shader source file.
var vertexShaderSourceFile = vertexShader.Get(vertexShader.PropertyTypes.ShaderSourceFile);
// Get the path to the vertex shader source file.
var vertexShaderSourceFileFileSystemPath = vertexShaderSourceFile.FileSystemPath;
if (File.Exists(vertexShaderSourceFileFileSystemPath))
{
// Replace the content of the existing vertex shader with the vertex shader you pass to the function.
File.WriteAllText(vertexShaderSourceFileFileSystemPath, vertexShaderSource);
}
// Set the material type you created to use the fragment shader you pass to the function.
// Use the same approach you used to set the vertex shader.
string fragmentShaderSource = File.ReadAllText(fragmentShaderPath);
var fragmentShader = materialType.Children.OfType<FragmentShader>().First();
var fragmentShaderSourceFile = fragmentShader.Get(fragmentShader.PropertyTypes.ShaderSourceFile);
var fragmentShaderSourceFileFileSystemPath = fragmentShaderSourceFile.FileSystemPath;
if (File.Exists(fragmentShaderSourceFileFileSystemPath))
{
File.WriteAllText(fragmentShaderSourceFileFileSystemPath, fragmentShaderSource);
}
// Create a material which uses the material type you created.
var materialLibrary = studio.ActiveProject.MaterialLibrary;
var material = studio.ActiveProject.CreateProjectItem<Material>(
materialLibrary.GenerateUniqueChildName(name + "Material"), materialLibrary);
material.Set(material.PropertyTypes.MaterialType, materialType);
}