[0.8.9][NK] Texture swapping and model swapping (StaticGraphics)

johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
edited December 2015 in Modding Tutorials
This tutorials covers texture swapping and model swapping on StaticGraphics.

Texture swapping allows dynamic swapping of textures on in-game object.
For example it is used with modular tools to change the texture on the Head part as is becomes damaged.

Model swapping allows dynamic swapping of models on in-game object.
For example it is used with loot objects to assign the model to a proxy object and Cabbage Trap.

Texture types:
  • Diffuse - EternusEngine.ETextureType.Diffuse
  • Normal - EternusEngine.ETextureType.Normal
  • Glow - EternusEngine.ETextureType.Glow

Texture Swapping

Getting StaticGraphics:
local staticGraphics = object:NKGetStaticGraphics()
Swapping texture on static graphic:
staticGraphics:NKSetSubmeshTexture(type, targetSubmesh, textureName)
Example (from ModularTool):
staticGraphics:NKSetSubmeshTexture(EternusEngine.ETextureType.Diffuse, "head", "head2")
Example object with additional textures defined:
GameObjects
{
PlaceableObject
{
Object Name
{
# ...
StaticGraphics
{
model = "path/to/model.obj"
dontCastShadows = 1.0

Diffuse
{
# default texture
"part1" = "path/to/diff1.tga"
# additional textures
"part1_alt" = "path/to/diff2.tga"
"part1_another" = "path/to/diff3.tga"
}
Normal
{
# default texture
"part1" = "path/to/norm1.tga"
# additional textures
"part1_alt" = "path/to/norm2.tga"
"part1_another" = "path/to/norm3.tga"
}
}
# ...
}
}
}
Note: only submesh "part1" needs to exists on the object, the "part1_alt" and "part1_another" textures are loaded but unused until the texture is swapped.

Example texture swap:
-- change diffuse and normal textures to part1_alt
staticGraphics:NKSetSubmeshTexture(EternusEngine.ETextureType.Diffuse, "part1", "part1_alt")
staticGraphics:NKSetSubmeshTexture(EternusEngine.ETextureType.Normal, "part1", "part1_alt")

-- change diffuse and normal textures to part1_another
staticGraphics:NKSetSubmeshTexture(EternusEngine.ETextureType.Diffuse, "part1", "part1_another")
staticGraphics:NKSetSubmeshTexture(EternusEngine.ETextureType.Normal, "part1", "part1_another")

-- change diffuse and normal textures back to default
staticGraphics:NKSetSubmeshTexture(EternusEngine.ETextureType.Diffuse, "part1", "part1")
staticGraphics:NKSetSubmeshTexture(EternusEngine.ETextureType.Normal, "part1", "part1")
Example (Bronze Pick - Damage State):
image

Model Swapping

Loading model from model file:
local model = NKLoadStaticModel(path)
Example model file:
StaticGraphics
{
model = "path/to/model.obj"
useAlphaShadows = 1.0

Diffuse
{
0 = "path/to/diff.tga"
}
Normal
{
0 = "path/to/norm.tga"
}
Glow
{
0 = "path/to/glow.tga"
}
}
Getting model from GameObject:
local model = object:NKGetStaticGraphics()
Getting model from object schematic:
local schematic = Eternus.GameObjectSystem:NKFindObjectSchematicByName("Object Name")
local model = schematic:NKCreateStaticGraphics()
Setting model:
object:NKSetGraphics(model)
My Blog
jc.png
  yt.png  t.png  
Sign In or Register to comment.