Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
9829 lines (7871 sloc) 206 KB
-- SEA3D Exporter (Sunag Entertainment Assets 3D)
-- Copyright (C) Sunag Entertainment
-- SEA3D - A file format for games
-- https://github.com/sunag/sea3d
-- developed by Jean Carlo Deconto (Brazil)
-- never give up without trying...
fileIn "SEA3D.inc"
if (LoadSEADLL() == false) then exit
--
-- Global
--
global
-- Extensions (Max 4chars ASCII Compatible 32bit)
EXT_INFO = ".info",
EXT_GEOMETRY = ".geo",
EXT_GEOMETRY_DELTA = ".geDL",
EXT_SCENE_OBJECT = ".o3d",
EXT_MESH = ".m3d",
EXT_SPRITE3D = ".m2d",
--EXT_CONTAINER3D = ".c3d",
EXT_JOINT_OBJECT = ".jnt",
EXT_ANIMATION = ".anm", -- Generic SEA3D Animation (Lights, Meshes, Helpers, Textures and others)
EXT_ANIMATION_UVW = ".auvw",
EXT_GIF = ".gif",
EXT_PNG = ".png",
EXT_JPEG = ".jpg",
EXT_JPEG_XR = ".wdp",
EXT_DDS = ".dds",
EXT_DDS_CUBE = ".ddsc",
EXT_ATF = ".atf",
EXT_ATF_CUBE = ".atfc",
EXT_TEXTURE = ".tex",
EXT_TEXTURE_URL = ".urlT",
EXT_MORPH = ".mph",
EXT_MORPH_ANIMATION = ".mpha",
EXT_VERTEX_COLOR = ".vtc",
EXT_VERTEX_ANIMATION = ".vtxa",
EXT_POINT_LIGHT = ".plht",
EXT_DIRECTIONAL_LIGHT = ".dlht",
EXT_SKELETON = ".skl",
EXT_SKELETON_LOCAL = ".sklq",
EXT_SKELETON_ANIMATION = ".skla",
EXT_MATERIAL = ".mat",
EXT_COMPOSITE = ".ctex",
EXT_CUBE_MAPPING = ".cmap",
EXT_SINGLE_CUBE_MAPPING = ".smap",
EXT_PERSPECTIVE_CAMERA = ".cam",
EXT_PROPERTIES = ".prop",
EXT_OGG = ".ogg",
EXT_MP3 = ".mp3",
EXT_SOUND_POINT = ".sp",
EXT_SOUND_MIXER = ".smix",
--EXT_DATA = ".data", -- CUSTOM BYTEARRAY
--EXT_SCRIPT = ".src", -- SCRIPT
EXT_LINE = ".line",
EXT_DUMMY = ".dmy",
EXT_RTT_CUBE = ".rttc",
EXT_RTT_PLANAR = ".rttp",
EXT_ACTIONS = ".act"
global
DT_NONE = "none",
DT_UINT = "uint",
DT_FLOAT = "float",
DT_STRING = "string",
DT_COLOR = "color",
DT_BYTE = "byte",
DT_BITMAP = "bitmap",
DT_TEXTURE = "texture",
DT_COMPOSITE = "composite",
DT_CUBE = "cube",
DT_CUBE_RTT = "cube_rtt",
DT_PLANAR_RTT = "planar_rtt"
global
SH_DIFFUSE_MAP = "DiffuseMap",
SH_LIGHT_MAP = "LightMap",
SH_DETAIL_MAP = "DetailMap"
global
BAKE_COMPLETE_MAP = "completemap",
BAKE_DIFFUSE_MAP = "diffusemap",
BAKE_LIGHT_MAP = "lightmap",
BAKE_AO = "ao"
global
-- READER --
-- GEOMETRY
HEADER_BIGMESH = 1,
HEADER_VERTEX = 2,
HEADER_NORMAL = 4,
HEADER_TANGENT = 8,
HEADER_BINORMAL = 16,
HEADER_UV = 32,
HEADER_JOINTS = 64,
HEADER_COLOR = 128,
-- GEOMETRY COLOR4
HEADER_COLOR1 = 0,
HEADER_COLOR2 = 64,
HEADER_COLOR3 = 128,
HEADER_COLOR4 = 192,
-- ANIMATION
HEADER_ANIMATION_SEQUENCE = 1,
-- OBJECT3D
HEADER_PARENT = 1,
HEADER_ANIMATION = 2,
HEADER_SCRIPT = 4,
HEADER_CLASS = 8,
HEADER_PROPERTIES = 16,
HEADER_OBJECT_CONFIG = 32,
-- OBJECT3D -> LINE
HEADER_BIG_SPLINE = 64,
HEADER_CLOSED = 128,
-- OBJECT3D -> SOUND3D
HEADER_AUTO_PLAY = 64,
HEADER_SOUND_MIXER = 128,
-- OBJECT3D -> LIGHT
HEADER_SHADOW = 64,
HEADER_ATTENUATION = 128,
-- OBJECT3D -> ENITY3D
HEADER_LIGHT_CONFIG = 64,
-- OBJECT3D -> ENITY3D -> MESH
HEADER_MATERIAL = 256,
HEADER_MODIFIERS = 512,
-- SUB-READER --
-- HEADER_OBJECT_CONFIG
HEADER_STATIC = 1,
-- HEADER_LIGHT_CONFIG
HEADER_NOCAST_SHADOWS = 1,
-- HEADER_ANIMATION_SEQUENCE
HEADER_REPEAT = 1,
HEADER_NOINTERPOLATION = 2
global
TAG_LOOK_AT = 0x0001
global
SEA_INDEX = 0,
SEA_JOINT_INDEX = 1
global
ACT_ENVIRONMENT = 2,
ACT_FOG = 3,
ACT_LOOK_AT = 7,
ACT_RTT_TARGET = 8
global
C_BIG = 0xFFFF --65535
global
MAT_DEFAULT = 0x0000,
MAT_COMPOSITE_TEXTURE = 0x0001,
MAT_DIFFUSE_MAP = 0x0002,
MAT_SPECULAR_MAP = 0x0003,
MAT_REFLECTION_MAP = 0x0004,
MAT_REFRACTION_MAP = 0x0005,
MAT_NORMAL_MAP = 0x0006,
MAT_FRESNEL_REFLECTION = 0x0007,
MAT_RIM = 0x0008,
MAT_LIGHT_MAP = 0x0009,
MAT_DETAIL_MAP = 0x000A,
MAT_CEL = 0x000B,
MAT_TRANSLUCENT = 0x000C,
MAT_BLEND_NORMAL_MAP = 0x000D,
MAT_MIRROR_REFLECTION = 0x000E,
MAT_AMBIENT_MAP = 0x000F,
MAT_ALPHA_MAP = 0x0010,
MAT_EMISSIVE_MAP = 0x0011,
MAT_VERTEX_COLOR = 0x0012
global
ANM_POSITION = 0x0000,
ANM_ROTATION = 0x0001,
ANM_SCALE = 0x0002,
ANM_COLOR = 0x0003,
ANM_MULTIPLIER = 0x0004,
ANM_ATTENUATION_START = 0x0005,
ANM_ATTENUATION_END = 0x0006,
ANM_FOV = 0x0007,
ANM_OFFSET_U = 0x0008,
ANM_OFFSET_V = 0x0009,
ANM_SCALE_U = 0x000A,
ANM_SCALE_V = 0x000B,
ANM_DEGREE = 0x000C,
ANM_ALPHA = 0x000D,
ANM_VOLUME = 0x000E,
ANM_RADIAN = 0x000F
global
SEA_QUATERNION = 0,
SEA_INV_MATRIX = 1
global
UISIZE = 0
--
-- ATF Extension
--
global
ENC_ALL = "all",
ENC_DXT = "dxt",
ENC_ETC1 = "etc1",
ENC_PVRTC = "pvrtc",
ATF_EXTENSION_PATH = getSourceFolder() + "atf-extension\\",
ATF_PNG_TO_ATF = ATF_EXTENSION_PATH + "png2atf.exe",
ATF_DDS_TO_ATF = ATF_EXTENSION_PATH + "dds2atf.exe",
ATF_SUPPORTS = dirExist (ATF_EXTENSION_PATH) and fileExist (ATF_PNG_TO_ATF) and fileExist (ATF_DDS_TO_ATF)
--
-- 3ds Max Fixes
--
global skinops_getBoneNameByListID = skinops.getBoneName
if (hasProperty skinops #getBoneNameByListID) do
skinops_getBoneNameByListID = skinops.getBoneNameByListID
-- DisableProcessWindowsGhosting
-- @Source: http://forums.cgsociety.org/archive/index.php?t-1045092.html
fn getDisplayTopologyDependenceWarning =
(
local enabled = (getIniSetting (getMAXIniFile()) #performance #TopoMessage)
if enabled == "" do return true
return (enabled as integer) != 0
)
fn setDisplayTopologyDependenceWarning enabled =
(
global seaSetDisplayTopologyDependenceWarning = enabled
fn PreferenceCallback =
(
-- http://forums.cgsociety.org/showpost.php?p=6973531&postcount=13
fn setCheckBoxState hwnd state =
(
local BN_CLICKED = 0
local BM_SETCHECK = 241
local WM_COMMAND = 273
local parent = UIAccessor.getParentWindow hwnd
local id = UIAccessor.getWindowResourceID hwnd
windows.sendMessage hwnd BM_SETCHECK (if state then 1 else 0) 0
windows.sendMessage parent WM_COMMAND ((bit.shift BN_CLICKED 16) + id) hwnd
ok
)
local hWND = DialogMonitorOPS.GetWindowHandle()
if (UIAccessor.GetWindowText hWND) != "Preference Settings" do return true
local bt = windows.getchildhwnd hWND "Display Topology-Dependence Warning"
global seaSetDisplayTopologyDependenceWarning
setCheckBoxState bt[1] seaSetDisplayTopologyDependenceWarning
UIAccessor.SendMessageID hWND #IDOK
true
)
DialogMonitorOPS.RegisterNotification PreferenceCallback id:#preferencesConfigure
DialogMonitorOPS.Enabled = true
max file preferences
DialogMonitorOPS.unRegisterNotification id:#preferencesConfigure
DialogMonitorOPS.Enabled = false
)
try
(
if getDisplayTopologyDependenceWarning() do setDisplayTopologyDependenceWarning false
)
catch()
-- DisableProcessWindowsGhosting
-- @Source: http://aarondabelow.com/wp/2014/01/08/3ds-max-ui-freezing-during-scripts-disable-window-ghosting/
fn DisableProcessWindowsGhosting =
(
local source = StringStream ("using System.Runtime.InteropServices; public class DisableWindowsGhosting{ [DllImport(\"user32.dll\")] public static extern bool DisableProcessWindowsGhosting(); }")
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.GenerateInMemory = on
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source as String)
flush source
close source
if (compilerResults.Errors.Count > 0 ) then
(
local errs = stringstream ""
for i = 0 to (compilerResults.Errors.Count-1) do
(
local err = compilerResults.Errors.Item[i]
format "Error:% Line:% Column:% %\n" err.ErrorNumber err.Line err.Column err.ErrorText to:errs
)
format "%\n" errs
undefined
)
else
(
compilerResults.CompiledAssembly.CreateInstance "DisableWindowsGhosting"
)
)
try
(
global DisableWindowsGhosting
if DisableWindowsGhosting == undefined do
(
DisableWindowsGhosting = DisableProcessWindowsGhosting()
DisableWindowsGhosting.DisableProcessWindowsGhosting()
)
)
catch()
--
-- Config
--
fn CreateSEAConfig =
(
local seaconfig = dotNetObject "Poonya.Utils.Hashmap"
seaconfig.AddString "compress" "deflate"
seaconfig.AddString "export" "visible"
seaconfig.AddFloat "mindiff" 0.01
seaconfig.AddBoolean "exceptionprotection" true
seaconfig.AddBoolean "sprite" true
seaconfig.AddBoolean "sounds" true
seaconfig.AddBoolean "all_sounds" false
seaconfig.AddBoolean "attrib" true
seaconfig.AddBoolean "animation" true
seaconfig.AddBoolean "force_animation" false
seaconfig.AddBoolean "geometry" true
seaconfig.AddBoolean "skeleton" true
seaconfig.AddBoolean "material" true
seaconfig.AddBoolean "rtt" true
seaconfig.AddBoolean "rtt_target" true
seaconfig.AddBoolean "atf" false
seaconfig.AddBoolean "atf_auto" true
seaconfig.AddBoolean "atf_force" false
seaconfig.AddBoolean "atf_jpegxr" false
seaconfig.AddString "atf_compress" "dxt"
seaconfig.AddBoolean "materialcolor" true
seaconfig.AddBoolean "texture" true
seaconfig.AddBoolean "compress_texture" true
seaconfig.AddBoolean "textureanimationtakes" true
seaconfig.AddBoolean "camera" true
seaconfig.AddBoolean "cameratarget"false
seaconfig.AddBoolean "light" true
seaconfig.AddBoolean "lighttarget" false
seaconfig.AddBoolean "shape" false
seaconfig.AddBoolean "dummy" false
seaconfig.AddBoolean "multiplechannel" true
seaconfig.AddBoolean "uv" true
seaconfig.AddBoolean "normal" true
seaconfig.AddBoolean "tangent" false
seaconfig.AddBoolean "sg" true
seaconfig.AddBoolean "vertexcolor" false
seaconfig.AddBoolean "env" false
seaconfig.AddBoolean "morph" true
seaconfig.AddInteger "lossygeometry" 1
seaconfig.AddBoolean "vertexanimation" true
seaconfig.AddBoolean "warning" false
seaconfig.AddBoolean "auto_rename" true
seaconfig.AddBoolean "positive_scale" true
seaconfig.AddBoolean "parent" true
seaconfig.AddBoolean "bindoffset" true
seaconfig.AddBoolean "snapshot" false
seaconfig.AddBoolean "instanceanimation" true
seaconfig.AddInteger "bindframe" 0
seaconfig.AddInteger "splinestep" 100
seaconfig.AddInteger "animationtype" 2
seaconfig.AddBoolean "envtex" false
seaconfig.AddBoolean "instances" true
seaconfig.AddBoolean "sharematerials" false
seaconfig.AddBoolean "allstatic" false
seaconfig.AddBoolean "baketextures" true
seaconfig.AddBoolean "embedtextures" true
seaconfig.AddBoolean "renderall" false
seaconfig.AddInteger "bakesize" 8
seaconfig.AddInteger "minbakesize" 8
seaconfig.AddInteger "bakequality" 80
seaconfig.AddString "bakeext" EXT_PNG
seaconfig.AddString "bakeoutput" "completemap"
seaconfig.AddBoolean "relativesize" false
seaconfig.AddBoolean "meshoptimizer" true
seaconfig.AddBoolean "joinvertices" false
seaconfig.AddBoolean "moveslide" true
seaconfig.AddBoolean "fileinfo" false
seaconfig.AddString "fileinfo-name" ""
seaconfig.AddString "fileinfo-author" ""
seaconfig.AddString "fileinfo-website" "http://"
seaconfig.AddBoolean "fog" false
seaconfig.AddFloat "fog-min" 100.0
seaconfig.AddFloat "fog-max" 6000.0
seaconfig.AddColor "fog-color" 0 0 255
return seaconfig
)
fn SetSEAConfig seaconfig =
(
seaconfig.AddString "compress" seaconfig_compress
seaconfig.AddString "export" seaconfig_export
seaconfig.AddFloat "mindiff" seaconfig_mindiff
seaconfig.AddBoolean "exceptionprotection" seaconfig_exceptionprotection
seaconfig.AddBoolean "sprite" seaconfig_sprite
seaconfig.AddBoolean "sounds" seaconfig_sounds
seaconfig.AddBoolean "all_sounds" seaconfig_all_sounds
seaconfig.AddBoolean "attrib" seaconfig_attrib
seaconfig.AddBoolean "animation" seaconfig_animation
seaconfig.AddBoolean "force_animation" seaconfig_force_animation
seaconfig.AddBoolean "geometry" seaconfig_geometry
seaconfig.AddBoolean "skeleton" seaconfig_skeleton
seaconfig.AddBoolean "material" seaconfig_material
seaconfig.AddBoolean "rtt" seaconfig_rtt
seaconfig.AddBoolean "rtt_target" seaconfig_rtt_target
seaconfig.AddBoolean "atf" seaconfig_atf
seaconfig.AddBoolean "atf_auto" seaconfig_atf_auto
seaconfig.AddBoolean "atf_force" seaconfig_atf_force
seaconfig.AddBoolean "atf_jpegxr" seaconfig_atf_jpegxr
seaconfig.AddString "atf_compress" seaconfig_atf_compress
seaconfig.AddBoolean "materialcolor" seaconfig_materialcolor
seaconfig.AddBoolean "texture" seaconfig_texture
seaconfig.AddBoolean "textureanimationtakes" seaconfig_textureanimationtakes
seaconfig.AddBoolean "camera" seaconfig_camera
seaconfig.AddBoolean "cameratarget" seaconfig_cameratarget
seaconfig.AddBoolean "light" seaconfig_light
seaconfig.AddBoolean "lighttarget" seaconfig_lighttarget
seaconfig.AddBoolean "spline" seaconfig_spline
seaconfig.AddBoolean "dummy" seaconfig_dummy
seaconfig.AddBoolean "multiplechannel" seaconfig_multiplechannel
seaconfig.AddBoolean "uv" seaconfig_uv
seaconfig.AddBoolean "normal" seaconfig_normal
seaconfig.AddBoolean "tangent" seaconfig_tangent
seaconfig.AddBoolean "sg" seaconfig_sg
seaconfig.AddBoolean "vertexcolor" seaconfig_vertexcolor
seaconfig.AddBoolean "env" seaconfig_env
seaconfig.AddBoolean "morph" seaconfig_morph
seaconfig.AddBoolean "vertexanimation" seaconfig_vertexanimation
seaconfig.AddBoolean "warning" seaconfig_warning
seaconfig.AddBoolean "auto_rename" seaconfig_auto_rename
seaconfig.AddBoolean "positive_scale" seaconfig_positive_scale
seaconfig.AddBoolean "parent" seaconfig_parent
seaconfig.AddBoolean "bindoffset" seaconfig_bindoffset
seaconfig.AddBoolean "snapshot" seaconfig_snapshot
seaconfig.AddBoolean "instanceanimation" seaconfig_instanceanimation
seaconfig.AddInteger "bindframe" seaconfig_bindframe
seaconfig.AddInteger "splinestep" seaconfig_splinestep
seaconfig.AddBoolean "envmap" seaconfig_envmap
seaconfig.AddBoolean "instances" seaconfig_instances
seaconfig.AddBoolean "sharematerials" seaconfig_sharematerials
seaconfig.AddBoolean "allstatic" seaconfig_allstatic
seaconfig.AddBoolean "baketextures" seaconfig_baketextures
seaconfig.AddBoolean "embedtextures" seaconfig_embedtextures
seaconfig.AddBoolean "renderall" seaconfig_renderall
seaconfig.AddBoolean "newmapping" seaconfig_newmapping
seaconfig.AddInteger "bakesize" seaconfig_bakesize
seaconfig.AddString "bakeoutput" seaconfig_bakeoutput
seaconfig.AddInteger "minbakesize" seaconfig_minbakesize
seaconfig.AddInteger "bakequality" seaconfig_bakequality
seaconfig.AddString "bakeext" seaconfig_bakeext
seaconfig.AddBoolean "relativesize" seaconfig_relativesize
seaconfig.AddBoolean "meshoptimizer" seaconfig_meshoptimizer
seaconfig.AddBoolean "joinvertices" seaconfig_joinvertices
seaconfig.AddBoolean "moveslide" seaconfig_moveslide
seaconfig.AddBoolean "fileinfo" seaconfig_fileinfo[1]
seaconfig.AddString "fileinfo-name" seaconfig_fileinfo[2]
seaconfig.AddString "fileinfo-author" seaconfig_fileinfo[3]
seaconfig.AddString "fileinfo-website" seaconfig_fileinfo[4]
seaconfig.AddBoolean "fog" seaconfig_fog[1]
seaconfig.AddColor "fog-color" seaconfig_fog[2].r seaconfig_fog[2].g seaconfig_fog[2].b
seaconfig.AddFloat "fog-min" seaconfig_fog[3]
seaconfig.AddFloat "fog-max" seaconfig_fog[4]
)
fn GetSEAConfig seaconfig =
(
global
seaconfig_compress = seaconfig.GetString "compress",
seaconfig_export = seaconfig.GetString "export",
seaconfig_mindiff = seaconfig.GetFloat "mindiff",
seaconfig_exceptionprotection = seaconfig.GetBoolean "exceptionprotection",
seaconfig_sprite = seaconfig.GetBoolean "sprite",
seaconfig_sounds = seaconfig.GetBoolean "sounds",
seaconfig_all_sounds = seaconfig.GetBoolean "all_sounds",
seaconfig_attrib = seaconfig.GetBoolean "attrib",
seaconfig_animation = seaconfig.GetBoolean "animation",
seaconfig_force_animation = seaconfig.GetBoolean "force_animation",
seaconfig_geometry = seaconfig.GetBoolean "geometry",
seaconfig_skeleton = seaconfig.GetBoolean "skeleton",
seaconfig_material = seaconfig.GetBoolean "material",
seaconfig_rtt = seaconfig.GetBoolean "rtt",
seaconfig_rtt_target = seaconfig.GetBoolean "rtt_target",
seaconfig_atf = seaconfig.GetBoolean "atf",
seaconfig_atf_auto = seaconfig.GetBoolean "atf_auto",
seaconfig_atf_force = seaconfig.GetBoolean "atf_force",
seaconfig_atf_jpegxr = seaconfig.GetBoolean "atf_jpegxr",
seaconfig_atf_compress = seaconfig.GetString "atf_compress",
seaconfig_materialcolor = seaconfig.GetBoolean "materialcolor",
seaconfig_texture = seaconfig.GetBoolean "texture",
seaconfig_compress_texture = seaconfig.GetBoolean "compress_texture",
seaconfig_textureAnimationTakes = seaconfig.GetBoolean "textureanimationtakes",
seaconfig_camera = seaconfig.GetBoolean "camera",
seaconfig_cameratarget = seaconfig.GetBoolean "cameratarget",
seaconfig_light = seaconfig.GetBoolean "light",
seaconfig_lighttarget = seaconfig.GetBoolean "lighttarget",
seaconfig_spline = seaconfig.GetBoolean "spline",
seaconfig_dummy = seaconfig.GetBoolean "dummy",
seaconfig_multiplechannel = seaconfig.GetBoolean "multiplechannel",
seaconfig_uv = seaconfig.GetBoolean "uv",
seaconfig_normal = seaconfig.GetBoolean "normal",
seaconfig_tangent = seaconfig.GetBoolean "tangent",
seaconfig_sg = seaconfig.GetBoolean "sg", -- smoothing group
seaconfig_vertexcolor = seaconfig.GetBoolean "vertexcolor",
seaconfig_env = seaconfig.GetBoolean "env",
seaconfig_morph = seaconfig.GetBoolean "morph",
seaconfig_vertexanimation = seaconfig.GetBoolean "vertexanimation",
seaconfig_warning = seaconfig.GetBoolean "warning",
seaconfig_auto_rename = seaconfig.GetBoolean "auto_rename",
seaconfig_positive_scale = seaconfig.GetBoolean "positive_scale",
seaconfig_parent = seaconfig.GetBoolean "parent",
seaconfig_bindoffset = seaconfig.GetBoolean "bindoffset",
seaconfig_snapshot = seaconfig.GetBoolean "snapshot",
seaconfig_instanceanimation = seaconfig.GetBoolean "instanceanimation",
seaconfig_bindframe = seaconfig.GetInteger "bindframe",
seaconfig_splinestep = seaconfig.GetInteger "splinestep",
seaconfig_envmap = seaconfig.GetBoolean "envmap",
seaconfig_instances = seaconfig.GetBoolean "instances",
seaconfig_sharematerials = seaconfig.GetBoolean "sharematerials",
seaconfig_allstatic = seaconfig.GetBoolean "allstatic",
seaconfig_baketextures = seaconfig.GetBoolean "baketextures",
seaconfig_embedtextures = seaconfig.GetBoolean "embedtextures",
seaconfig_renderall = seaconfig.GetBoolean "renderall",
seaconfig_newmapping = seaconfig.GetBoolean "newmapping",
seaconfig_bakesize = seaconfig.GetInteger "bakesize",
seaconfig_bakeoutput = seaconfig.GetString "bakeoutput",
seaconfig_minbakesize = seaconfig.GetInteger "minbakesize",
seaconfig_bakequality = seaconfig.GetInteger "bakequality",
seaconfig_bakeext = seaconfig.GetString "bakeext",
seaconfig_relativesize = seaconfig.GetBoolean "relativesize",
seaconfig_meshoptimizer = seaconfig.GetBoolean "meshoptimizer",
seaconfig_joinvertices = seaconfig.GetBoolean "joinvertices",
seaconfig_moveslide = seaconfig.GetBoolean "moveslide",
seaconfig_fileinfo = #(seaconfig.getBoolean "fileinfo",seaconfig.GetString "fileinfo-name",seaconfig.GetString "fileinfo-author",seaconfig.GetString "fileinfo-website"),
seaconfig_fog = #(seaconfig.getBoolean "fog", color (seaconfig.GetRed "fog-color") (seaconfig.GetGreen "fog-color") (seaconfig.GetBlue "fog-color"), seaconfig.GetFloat "fog-min", seaconfig.GetFloat "fog-max")
)
fn LoadSEA3DExporterConfigFromDummy target: =
(
if (target == unsupplied) do
target = getnodebyname NODE_CONFIG
if target != undefined then
(
local cfgdata = getUserProp target DEF_ANIMATION_CONFIG
if cfgdata != undefined then
(
try
(
local cfg = dotNetObject "Poonya.Utils.Hashmap"
cfg.ReadBase64 cfgdata
LoadSEA3DExporterConfig cfg
)
catch()
)
)
)
fn ReadSEAConfig filename =
(
local seapath = getSourceFolder() + filename
local seaconfig = dotNetObject "Poonya.Utils.Hashmap"
if (seaconfig.ContainsFile seapath) do
(
seaconfig.Load seapath
return seaconfig
)
return undefined
)
fn WriteSEAConfig seaconfig filename =
(
local seapath = getSourceFolder() + filename
seaconfig.Save seapath
)
fn GetSEAConfigList =
(
return ( getFiles (getSourceFolder() + "*.config") )
)
--
-- Create Config
--
global seaconfig, seaconfig_selected
seaconfig = ReadSEAConfig "Default.config"
if seaconfig == undefined then seaconfig = CreateSEAConfig()
else seaconfig_selected = "Default"
GetSEAConfig seaconfig
if sea_sounds == undefined or sea_sounds_names == undefined then
(
global sea_sounds = #(), sea_sounds_names = #()
)
--
-- Exporter
--
global sea_floater,
sea_listeners = #(),
sea_changes = #(),
seaTimeRange = #(animationRange.start.frame as integer,animationRange.end.frame as integer,0 as integer,framerate),
seaUnits = #(#Generic, #Centimeters),
seaao = #(32,color 255 255 255,color 0 0 0,1.0,50.0,0.5),
sea3d = undefined,
seabuild = false,
seaAssetNames = #(),
seaErrors = #(),
seaWarning = #(),
seaMaterials = #(),
seaTBakes = undefined,
seaListenerText = "",
seaBitmapList = #(),
seaCubeList = #(),
seaTextureList = #(),
seaMaterialList = #(),
seaObjectList = #(),
seaTempFileList = #(),
seaModifierList = #(),
seaError = undefined,
seaObjectTemp = undefined,
seauseparent = false,
seauseboneparent = false,
seanames = undefined,
seamats = undefined,
seamatnames = undefined,
seasceneobject = undefined,
seaboneobject = undefined,
seaboneinobject = undefined,
seabonelist = undefined,
seaprogressbar = undefined,
seaactions = undefined,
seadefaultsequence = undefined,
seasingleuv = false,
seablendpalette = #("normal","add","subtract","multiply","dividing","mix","alpha","screen","darken",
"overlay","colorburn","linearburn","lighten","colordodge","lineardodge",
"softlight","hardlight","pinlight","spotlight","spotlightblend","hardmix",
"average","difference","exclusion","hue","saturation","color","value"),
seacompositepalette = #("normal","average","add","subtract","darken","multiply",
"colorburn","linearburn","lighten","screen","colordodge","lineardodge","spotlight",
"spotlightblend","overlay","softlight","hardlight","pinlight",
"hardmix","difference","exclusion","hue","saturation","color","value"),
seaProceduralList = #(
Cellular,
Dent,
Marble,
Noise,
Perlin_Marble,
Smoke,
Speckle,
Splat,
Stucco,
Swirl,
Tiles,
Vertex_Color,
Waves,
Wood
),
seaCompatibleLightList = #(
OmniLight,
FreeSpot,
TargetSpot,
Directionallight,
TargetDirectionallight
),
seaCompatibleMeshList = #(
Editable_Mesh,
PolyMeshObject,
Editable_Poly,
Box,
Cone,
Sphere,
GeoSphere,
Cylinder,
Tube,
Torus,
Pyramid,
Teapot,
Plane,
Hedra,
Torus_Knot,
ChamferBox,
ChamferCyl,
OilTank,
Capsule,
Spindle,
L_Ext,
Gengon,
C_Ext,
RingWave,
Hose,
Prism
)
global seaevent_anm = undefined
rollout _SEAListener "SEA3D Listener" width:500 height:300
(
dotNetControl dncText "System.Windows.Forms.Textbox" width:490 height:290 align:#center
on _SEAListener open do
(
dncText.Font = dotNetObject "System.Drawing.Font" "MS Sans Serif" 8 ((dotNetClass "System.Drawing.FontStyle").Regular)
dncText.BorderStyle = (dotNetClass "System.Windows.Forms.BorderStyle").FixedSingle
dncText.BackColor = (dotNetClass "System.Drawing.Color").fromARGB (((colorMan.getColor #background) * 255)[1] as integer) (((colorMan.getColor #background) * 255)[2] as integer) (((colorMan.getColor #background) * 255)[3] as integer)
dncText.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB (((colorMan.getColor #text) * 255)[1] as integer) (((colorMan.getColor #text) * 255)[2] as integer) (((colorMan.getColor #text) * 255)[3] as integer)
dncText.MultiLine = true
dncText.WordWrap = true
dncText.ReadOnly = true
dncText.ScrollBars = (dotNetClass "System.Windows.Forms.ScrollBars").Vertical
dncText.Text = seaListenerText
)
)
function openSEAListener =
(
if (seaWarning.count > 0 or seaErrors.count > 0) do
(
seaListenerText = ""
for i=1 to seaWarning.count do
(
seaListenerText = ("• Warning " + (seaWarning[i]) + "\r\n") + seaListenerText
)
for i=1 to seaErrors.count do
(
seaListenerText = ("• Error " + (seaErrors[i]) + "\r\n") + seaListenerText
)
createDialog _SEAListener
)
)
--
-- Alerts
--
function errorValidMaterialName n =
(
if n != undefined then return "in the material \"" + n + "\""
return ""
)
function error1001 n =
(
append seaErrors ("#1001: Conflicted name. More than one object with the name \"" + n + "\" was found.")
)
function error1002 n =
(
append seaErrors ("#1002: Conflicted name. More than one material with the name \"" + n + "\" was found.")
)
function error1003 n =
(
append seaErrors ("#1003: Conflicted name. More than one texture with the name \"" + n + "\" was found.")
)
function error1004 n nobj =
(
append seaErrors ("#1004: Conflicted name. More than one bone with the name \"" + n + "\" was found on the model \"" + nobj + "\".")
)
function error1005 n nobj =
(
append seaErrors ("#1005: Conflicted name. More than one morph with the name \"" + n + "\" was found on the model \"" + nobj + "\".")
)
function error1012 t n =
(
append seaErrors ("#1012: " + t + " shader in the \"" + n + "\" is not compatible.")
)
function error1013 t n =
(
append seaErrors ("#1013: Slot \"" + t + "\" in the material \"" + n + "\" is not compatible.")
)
function error1014 t n =
(
append seaErrors ("#1014: Texture \"" + t + "\" in the material \"" + n + "\" is not compatible. Only DDS, PNG, JPEG, JPEG_XR and GIF.")
)
function error1015 n =
(
append seaErrors ("#1015: Skin from the object \"" + n + "\" will not be exported. Convert to Editable Mesh object.")
)
function error1016 t n =
(
append seaErrors ("#1016: Texture \"" + t + "\" in the material \"" + n + "\" was not found. Reselect the texture in Material Editor.")
)
function error1017 c t n =
(
append seaErrors ("#1017: Composite layer \"" + c + "\" of slot " + (toLowerString t) + " in the material \"" + n + "\" is not compatible. Select a bitmap texture.")
)
function error1018 c t n =
(
n = errorValidMaterialName n
append seaErrors ("#1018: Cube Mapping \"" + c + "\" of slot \"" + (toLowerString t) + "\"" + n + " is undefined. Select a bitmap texture.")
)
function error1019 c t n f =
(
n = errorValidMaterialName n
append seaErrors ("#1019: Cube Mapping \"" + c + "\" of slot \"" + (toLowerString t) + "\"" + n + " of the face name \"" + f +"\" is not compatible. Place faces of names: Left(-x), Right(+x), Bottom(-y), Top(+y), Back(-z) and Front(+z).")
)
function error1020 t n =
(
n = errorValidMaterialName n
append seaErrors ("#1020: Cube Mapping of slot \"" + t + "\"" + n + " must have 6 face names: Left(-x), Right(+x), Bottom(-y), Top(+y), Back(-z) and Front(+z).")
)
function error1021 t n =
(
n = errorValidMaterialName n
append seaErrors ("#1021: Cube Mapping \"" + t + "\"" + n + " must be have faces with the same file extension.")
)
function error1025 n =
(
append seaErrors ("#1025: Invalid Environment Map \"" + n + "\". Select a Cube Mapping texture.")
)
function error1030 n =
(
append seaErrors ("#1030: Frames values of Animation Sequence in the object \"" + n + "\" do not match the timeline.")
)
function error1031 n nobj =
(
append seaErrors ("#1031: Conflicted name in Animation Sequence. More than one sequence with the name \"" + n + "\" was found on the model \"" + nobj + "\".")
)
function error1060 n t =
(
append seaErrors ("#1060: Sound with the name \"" + t+ "\" in the object \"" + n + "\" was not found in the Sound List.")
)
function error1090 n t =
(
append seaErrors ("#1090: Line \"" + t+ "\" can not be exported.")
)
function error1201 n =
(
append seaErrors ("#1201: File \"" + n + "\" was not found.")
)
function error1301 =
(
append seaErrors ("#1301: It is necessary Mental Ray Renderer to create Ambient Occlusion baking.")
)
function error1302 n =
(
append seaErrors ("#1302: Invalid material in the object \"" + n + "\" to apply a LightMap, select a Standard Material.")
)
function error1401 n =
(
append seaErrors ("#1401: Error creating ATF \"" + n + "\". Make sure the size is a Power of 2.")
)
function customError error =
(
append seaErrors ("#unknown:" + error)
)
function warning2001 n =
(
append seaWarning ("#2001: Object \"" + n + "\" will not be exported.")
)
function warning2002 n =
(
append seaWarning ("#2002: Invalid geometry. Object \"" + n + "\" will not be exported.")
)
function warning2003 n =
(
append seaWarning ("#2003: Skin from the object \"" + n + "\" will not be exported.")
)
function warning2004 n =
(
append seaWarning ("#2004: Morpher from the object \"" + n + "\" will not be exported.")
)
function warning2005 n =
(
append seaWarning ("#2005: Additional Bump in the material \"" + n + "\" will not be exported.")
)
function warning2006 n =
(
append seaWarning ("#2006: Invalid light, \"" + n + "\" will not be exported.")
)
function warning2007 n =
(
append seaWarning ("#2007: Found a vertex in mesh \"" + n + "\" without skin attachment.")
)
function warning2008 n =
(
append seaWarning ("#2008: Skin can not be exported the object \"" + n + "\". Convert to Editable Mesh object.")
)
function warning2009 t n =
(
append seaWarning ("#2009: Falloff parameters \"" + t + "\" in the material \"" + n + "\" is not compatible.")
)
function warning2010 n =
(
append seaWarning ("#2010: \"" + n + "\" is not compatible with Stream Loader Type.")
)
function warning2011 n =
(
append seaWarning ("#2011: \"" + n + "\" instance invalid. The instance may not contain modifiers different order.")
)
function warning2012 t n =
(
append seaWarning ("#2012: Material \"" + t + "\" is not compatible in \"" + n + "\".")
)
function warning2401 n =
(
append seaWarning ("#2401: ATF Texture \"" + n + "\" can not be created.")
)
function warning2501 n =
(
append seaWarning ("#2501 : Animation Key \"" + n + "\" was not found.")
)
--
-- Structs
--
-- SceneObject
struct SEAIndex
(
type, index, joint
)
struct SEAHashTable
(
keys = #()
, values = #()
, function add key value =
(
append keys key
append values value
)
, function contains key =
(
return ((findItem keys key) > 0)
)
, function get key =
(
return values[ (findItem keys key) ]
)
)
struct SEAMod
(
obj, m
)
struct SEAAction
(
type, value
)
struct SEASplines
(
obj
, animation, instanceOf, frame_rate, attribs
, asset
)
struct SEAAnimator
(
index, relative = false
)
struct SEADummy
(
obj, type="dummy"
, animation, instanceOf, frame_rate, attribs
, asset
, fn dist =
(
return (distance [0,0,0] obj.transform.position)
)
)
struct SEACamera
(
obj, target
, animation, instanceOf, frame_rate, attribs
, asset
)
struct SEALight
(
obj, target
, animation, instanceOf, frame_rate, attribs
, asset
)
struct SEASound
(
obj, s_sound, soundMod
, sound_index
, animation, instanceOf, frame_rate, attribs
, asset
)
struct SEASprite
(
obj, spriteMode, mats, tag
, mats_index
, animation, instanceOf, frame_rate, attribs
, asset
, fn dist =
(
return (distance [0,0,0] obj.transform.position)
)
, fn isStatic =
(
if tag != undefined then return tag.enabledstaticparam
else return (seaconfig_animation == false and seaconfig_allstatic)
)
, fn castShadows =
(
if tag != undefined then return tag.m_castshadows
else return obj.castshadows
)
, fn receiveShadows =
(
if tag != undefined then return tag.m_receiveshadows
else return obj.receiveshadows
)
, fn receiveLights =
(
if tag != undefined then return tag.m_receivelights
else return true
)
)
struct SEAMesh
(
obj, temp, tag, mats, meshObj, normalNObj, normalObj, smoothing_group, skinObj, morphObj, morphAnmObj, vertexAnm, boneList, boneParentList, bindpos, mchs, mchsValue, instances=#(), skeleton, skeletonAnimation, morphAnimation, vertexAnimation, uvwAnimation
, geo_index = -1, mats_index, morph_index
, e_index, e_normal, c_vertex, c_index, c_weights, c_normal, c_uv, c_color, c_tangent, maxweight
, animation, instanceOf, frame_rate, attribs
, asset
, fn dist =
(
return (distance [0,0,0] obj.transform.position)
)
, fn useVertexColor =
(
if tag != undefined then return tag.m_vertexcolorparam
else return seaconfig_vertexcolor
)
, fn useNormal =
(
if tag != undefined then return tag.m_normalparam
else return seaconfig_normal
)
, fn isStatic =
(
if tag != undefined then return tag.enabledstaticparam
else return (seaconfig_animation == false and seaconfig_allstatic)
)
, fn castShadows =
(
if tag != undefined then return tag.m_castshadows
else return obj.castshadows
)
, fn receiveShadows =
(
if tag != undefined then return tag.m_receiveshadows
else return obj.receiveshadows
)
, fn receiveLights =
(
if tag != undefined then return tag.m_receivelights
else return true
)
)
-- dependências
struct SEABitmap
(
filename, bake = undefined
, asset
)
struct SEABitmapComposite
(
obj, blendMode, data
)
struct SEATexture
(
obj, name=#(),textures=#(), masks=#(), masksID=#(), blendMode=#(), opacity=#(), bitmaps=#(), animation=#(), animationMask=#(), color
, asset
, lightMapTexture, detailMapTexture
, fn type =
(
if textures.count == 1 then return DT_TEXTURE
else if textures.count > 1 then return DT_COMPOSITE
else DT_NONE
)
, fn diffuseType =
(
local texType = type()
if texType == DT_TEXTURE then MAT_DIFFUSE_MAP
else if texType == DT_COMPOSITE then MAT_COMPOSITE_TEXTURE
else -1
)
, fn getBitmap =
(
return bitmaps[1].asset
)
, fn isValid =
(
return type() != DT_NONE
)
)
struct SEACube
(
obj, textures, bitmaps=#()
, asset
, fn isValid =
(
return bitmaps.count == 1 or bitmaps.count == 6
)
)
struct SEAMaterial
(
obj, tech=#(), maps=#()
, twoSided = false, smoothMat = true, containsAlpha = false, opacity = 1.0
, uvwAnimation
, rttCube = false, rttPlanar = false, rttCubeAsset, rttPlanarAsset
, asset
)
SEA3DSpriteDef = attributes SEA3DSpriteDef
(
parameters main rollout:SEA3DSpriteParams
(
enabledparam type:#boolean ui:enabledparam default:true
widthparam type:#float ui:widthparam default:50.0
heightparam type:#float ui:heightparam default:50.0
)
rollout SEA3DSpriteParams "Parameters"
(
checkbox enabledparam "Enabled" type:#boolean
spinner widthparam "Width:" type:#float range:[0,10000,0]
spinner heightparam "Height:" type:#float range:[0,10000,0]
dropdownlist _blend "Blend Type" items:#("Normal", "Add", "Multiply", "Alpha")
button _update "Active Display" align:#left
local obj = undefined
-- Align to View [2010-03-13] by Anubis [project3d.narod.ru]
fn alignObjToView = (
if obj != undefined then
(
local o_pos = obj.pos
obj.transform = inverse (viewport.getTM())
obj.pos = o_pos
)
else unRegisterRedrawViewsCallback alignObjToView
)
on _update pressed do
(
if obj == undefined then
(
_update.text = "Deactive Display"
obj = $
registerRedrawViewsCallback alignObjToView
)
else
(
_update.text = "Active Display"
obj = undefined
unRegisterRedrawViewsCallback alignObjToView
)
alignObjToView()
)
fn getBlend =
(
local state = 0
local userprop = getUserProp $ DEF_MATERIAL_BLEND_TYPE
if userprop == "normal" then state = 1
else if userprop == "add" then state = 2
else if userprop == "multiply" then state = 3
else if userprop == "alpha" then state = 4
return state
)
fn setBlend state =
(
local blendValue = undefined
if state == 1 then blendValue = "normal"
else if state == 2 then blendValue = "add"
else if state == 3 then blendValue = "multiply"
else if state == 4 then blendValue = "alpha"
setUserProp $ DEF_MATERIAL_BLEND_TYPE blendValue
)
on SEA3DSpriteParams open do
(
_blend.selection = (getBlend())
)
on _blend selected i do
(
setBlend i
)
on widthparam changed v do
(
$.width = v
)
on heightparam changed v do
(
$.length = v
)
)
)
SEA3DSoundDef = attributes SEA3DSoundDef
(
parameters main rollout:SEA3DSoundParams
(
enabledparam type:#boolean ui:enabledparam default:true
volumeparam type:#float ui:volumeparam default:1.0
distanceparam type:#float ui:distanceparam default:300.0
namespaceparam type:#string ui:namespaceparam
autoplayparam type:#boolean ui:autoplayparam default:true
soundparam type:#string
tagversion type:#float default:1.0
)
rollout SEA3DSoundParams "Parameters"
(
checkbox enabledparam "Enabled" type:#boolean
spinner volumeparam "Volume:" type:#float range:[0,1000000,0]
spinner distanceparam "Distance:" type:#float range:[0,1000000,0]
checkbox autoplayparam "Auto Play" type:#boolean
edittext namespaceparam "Mixer:"
dropdownlist _sound "Sound"
button _updateList "Update List"
fn updateList =
(
if sea_sounds_names != undefined then
(
local selectedName = undefined
if _sound.selection > 0 then
(
selectedName = _sound.items[_sound.selection]
)
_sound.items = sea_sounds_names
if selectedName != undefined then
(
_sound.selection = findItem sea_sounds_names selectedName
)
)
else _sound.items = #()
if soundparam != undefined then
(
_sound.selection = findItem sea_sounds_names soundparam
)
)
on distanceparam changed v do
(
$.size = v
)
on _sound selected i do
(
soundparam = _sound.items[i]
)
on _updateList pressed do
(
updateList()
)
on SEA3DSoundParams open do
(
updateList()
)
)
)
SEA3DTagDef = attributes SEA3DTagDef
(
parameters mainGlobal rollout:SEA3DTagGlobal
(
enabledstaticparam type:#boolean ui:enabledstaticparam default:false
tagversion type:#float default:1.1
)
parameters mainAnimation rollout:SEA3DTagAnimation
(
a_framerateparam type:#integer ui:a_framerateparam default:framerate
)
parameters mainMesh rollout:SEA3DTagMesh
(
m_normalparam type:#boolean ui:m_normalparam default:true
m_sgparam type:#boolean ui:m_sgparam default:true
m_vertexanmparam type:#boolean ui:m_vertexanmparam default:false
m_vertexcolorparam type:#boolean ui:m_vertexcolorparam default:false
m_castshadows type:#boolean ui:m_castshadows default:true
m_receiveshadows type:#boolean ui:m_receiveshadows default:true
m_receivelights type:#boolean ui:m_receivelights default:true
)
rollout SEA3DTagGlobal "Global"
(
checkbox enabledstaticparam "Static Object" type:#boolean
)
rollout SEA3DTagAnimation "Animation"
(
spinner a_framerateparam "Frame rate:" range:[1,256,framerate] type:#integer
)
rollout SEA3DTagMesh "Mesh"
(
checkbox m_normalparam "Normal" type:#boolean
checkbox m_sgparam "Smoothing Group" type:#boolean
checkbox m_vertexanmparam "Vertex Animation" type:#boolean
checkbox m_vertexcolorparam "Vertex Color" type:#boolean
checkbox m_castshadows "Cast Shadows" type:#boolean
checkbox m_receiveshadows "Receive Shadows" type:#boolean
checkbox m_receivelights "Receive Lights" type:#boolean
)
)
--
-- System
--
global
seastarttime = undefined,
seaupdatetime = undefined
fn seatime t =
(
set time t
if seaconfig_moveslide do sliderTime = t
)
fn seaupdatewindow =
(
windows.processPostedMessages()
)
fn seadispatchChange changes: dispatch: =
(
seabuild = false
if changes != false then
(
for i=1 to sea_changes.count do
(
sea_changes[i]()
)
)
if dispatch == true then
(
for i=1 to sea_listeners.count do
(
sea_listeners[i]()
)
)
)
fn seaprogressStart c name: =
(
seastarttime = timeStamp()
seaupdatetime = timeStamp()
seaprogressbar.value = 0
seaprogressbar.color = c
)
fn seaprogressUpdate p =
(
local actime = timeStamp()
seaprogressbar.value = p
if seabuild do seabuild = keyboard.escPressed == false
if actime - seastarttime > 5000 and actime - seaupdatetime > 1000 then
(
seaupdatewindow()
seaupdatetime = actime
)
)
fn seaprogressEnd =
(
seaprogressbar.value = 0
)
--
-- Utils
--
fn roundNum n =
(
if n > 0 then (n+0.5) as integer
else (n-0.5) as integer
)
fn getValidName name list =
(
local regexp = dotnetObject "System.Text.RegularExpressions.Regex" "[0-9]+$"
if regexp.IsMatch name then
(
local match = regexp.Match name
local length = match.Length - 1
local num = (substring name (match.Index+1) match.Length) as integer
name = substring name 1 match.Index
local newname = undefined
local i = 0
while true do
(
num += 1
local numstr = num as string
for i=numstr.count to length do
(
numstr = "0" + numstr
)
newname = name + numstr
if (findItem list newname) == 0 then
(
exit
)
)
return newname
)
return name + "1"
)
-- selectMod from: http://forums.cgsociety.org/archive/index.php/t-972272.html
fn selectMod obj modObj =
(
-- Select @_pNode if needed.
if not obj.IsSelected do
(
Select obj
)
-- Set Modify Panel active if needed.
if obj.IsFrozen do
(
Unfreeze obj DoLayer:true
)
-- Set Modify Panel active if needed.
if GetCommandPanelTaskMode() != #modify do
(
SetCommandPanelTaskMode mode:#modify
)
-- Set @_pNode skin modifier as current object in modpanel if needed.
if modObj != undefined and ModPanel.GetCurrentObject() != modObj do
(
ModPanel.SetCurrentObject modObj
)
)
fn getUVCount obj force: =
(
selectMod obj undefined
local m = Edit_Mesh ()
if obj.modifiers.count > 0 then
modPanel.setCurrentObject obj.modifiers[1]
else modPanel.setCurrentObject obj
local channelcount = (nummapsused obj) - 1
if force == true do channelcount = 9
modPanel.addModToSelection m
local uvs = #()
local index = 1
for c = 1 to channelcount do
(
try
(
meshop.getMapVert obj c 1
uvs[index] = c
index += 1
)
catch ()
)
deleteModifier obj m
uvs
)
fn isValidInstancing =
(
return seaconfig_instances and ((seaconfig_renderall and seaconfig_newmapping) == false)
)
fn classOfList n list =
(
local cof = ClassOf n
for i=1 to list.count do
(
if list[i] == cof do
(
return true
)
)
return false
)
-- http://tech-artists.org/wiki/Common_functions
fn isPowerOf2 n =
(
-- Can't be a power of two if it's not an integer
if classOf n != integer then return false
bit.and n (n-1) == 0
)
fn getPowerOf2 v =
(
if v < 0 do return 0
bit.set 0 (v+1) true
)
fn getLowerPowerOf2 v =
(
ceil ((log v) / (log 2))
)
fn getUpperPowerOf2 v =
(
(getLowestPowerOf2 v) - 1
)
fn getNearestPowerOf2 v =
(
if (isPowerOf2 v) == false then
(
local upper = getPowerOf2 (getUpperPowerOf2 v)
local lower = getPowerOf2 (getLowerPowerOf2 v)
if (v - lower) > (upper - v) then return upper
else return lower
)
v
)
fn removeTempObject =
(
if seaObjectTemp != undefined do
(
delete seaObjectTemp
seaObjectTemp = undefined
)
)
fn creatTempFile ext =
(
local id = seaTempFileList.count
local filename = (getDir #image) + "\\SEA3D_TEMP" + (id as String) + ext
append seaTempFileList filename
return filename
)
fn loadBakeConfig =
(
JPEGIO.setQuality seaconfig_bakequality
JPEGIO.setSmoothing 0
PNGIO.setAlpha false
PNGIO.setType #true24
)
fn appendLightMap mat tex =
(
if classof mat.diffuseMap == CompositeTexturemap then
(
local ctex = mat.diffuseMap
local lightMapIndex = findItem ctex.layerName SH_LIGHT_MAP
if lightMapIndex == 0 then
(
for i=1 to ctex.mapList.count do
(
if classof ctex.mapList[i] == BitmapTexture then
(
if ctex.mapList[i].filename == tex.filename then
(
lightMapIndex = i
exit
)
)
)
)
if lightMapIndex == 0 then
(
ctex.add()
lightMapIndex = ctex.mapList.count
ctex.layerName[lightMapIndex] = SH_LIGHT_MAP
)
ctex.mapList[lightMapIndex] = tex
)
else
(
local dmap = mat.diffuseMap
local ctex = CompositeTexturemap()
ctex.name = tex.name
ctex.add()
ctex.layerName[1] = SH_DIFFUSE_MAP
ctex.mapList[1] = mat.diffuseMap
ctex.layerName[2] = SH_LIGHT_MAP
ctex.mapList[2] = tex
ctex.blendMode[2] = 5
mat.diffuseMap = ctex
)
mat.showInViewport = true
)
fn bakeTexture tex filename: size: =
(
if seaTBakes.contains tex then
(
return (seaTBakes.get tex)
)
if filename == unsupplied do
(
filename = creatTempFile seaconfig_bakeext
)
if size == unsupplied do
(
if classof tex == BitmapTexture and (openBitMap tex.filename) != undefined then
(
local _bmp = openBitMap tex.filename
size = [_bmp.width,_bmp.height]
close _bmp
free _bmp
)
else
(
local tex_size = getPowerOf2 seaconfig_bakesize
size = [tex_size,tex_size]
)
)
loadBakeConfig()
local scl = 1.0
if (classOfList tex seaProceduralList) then
(
scl = 100
)
local rm = renderMap tex filename:filename scale:scl size:size filter:true display:false time:seaTimeRange[1]
save rm
close rm
free rm
seaTBakes.add tex filename
return filename
)
fn appendBakeMaterial mat =
(
if (finditem seaMaterials mat) == 0 then
(
append seaMaterials mat
return false
)
true
)
fn bakeMesh obj temp: filename: size: =
(
select obj
obj.renderable = true
obj.visibility = true
if temp == unsupplied do temp = true
if filename == unsupplied do
(
if temp == false or seaconfig_bakeoutput == BAKE_LIGHT_MAP or seaconfig_bakeoutput == BAKE_AO then
(
filename = ((getDir #image) + "\\SEA3D_BAKE_" + obj.name + seaconfig_bakeext)
)
else
(
filename = creatTempFile seaconfig_bakeext
)
)
if size == unsupplied do
(
size = getPowerOf2 seaconfig_bakesize
)
local bk = undefined
local singleuv = (classof obj.material) != StandardMaterial and (classof obj.material) != MultiMaterial
if seaconfig_bakeoutput == BAKE_COMPLETE_MAP then
(
bk = CompleteMap()
bk.shadowsOn = true
singleuv = true
)
else if seaconfig_bakeoutput == BAKE_DIFFUSE_MAP then
(
bk = DiffuseMap()
bk.shadowsOn = true
bk.lightingOn = true
singleuv = true
)
else if seaconfig_bakeoutput == BAKE_LIGHT_MAP then
(
bk = LightingMap()
bk.directOn = true
bk.indirectOn = true
bk.shadowsOn = true
)
else if seaconfig_bakeoutput == BAKE_AO then
(
if classof renderers.current != mental_ray_renderer then
(
error1301()
)
bk = AmbientOcclusionBakeElement()
bk.samples = seaao[1]
bk.bright = seaao[2]
bk.dark = seaao[3]
bk.spread = seaao[4]
bk.maxDistance = seaao[5]
bk.falloff = seaao[6]
)
if bk == undefined then
return undefined
bk.outputSzX = bk.outputSzY = size
bk.fileType = filename
bgColor = backgroundColor
backgroundColor = color 128 128 128
try
(
local uv = getUVCount obj force:true
local uv_bake = 1
if uv.count > 0 then
(
if uv.count > 1 then
(
if singleuv then uv_bake = uv[uv.count] + 1
else uv_bake = uv[2]
)
else
(
uv_bake = uv[1] + 1
)
)
else
(
singleuv = true
)
if seaconfig_newmapping or singleuv then
(
local uvw = Unwrap_UVW ()
uvw.name = "SEA3D UVW"
modPanel.addModToSelection uvw
uvw.setMapChannel uv_bake
uvw.flattenMap 60.0 [0,0,1] 0.01 true 0 true true
)
obj.iNodeBakeProperties.removeAllBakeElements()
obj.INodeBakeProperties.addBakeElement bk
obj.INodeBakeProperties.bakeEnabled = true
obj.INodeBakeProperties.bakeChannel = uv_bake
loadBakeConfig()
render rendertype:#bakeSelected vfb:false progressBar:true outputSize:[size,size]
local tex = BitmapTexture()
tex.name = getName (filenameFromPath filename)
tex.filename = filename
tex.coords.mapChannel = uv_bake
if singleuv then
(
uvw.setMapChannel uv_bake
local mat = StandardMaterial()
mat.name = obj.name
if classof obj.material == StandardMaterial then
(
mat.diffuse = obj.material.diffuse
mat.specular = obj.material.specular
mat.specularLevel = obj.material.specularLevel
mat.glossiness = obj.material.glossiness
mat.selfIllumAmount = obj.material.selfIllumAmount
)
else
(
mat.diffuse = obj.wirecolor
--mat.selfIllumAmount = 100.0
)
if seaconfig_bakeoutput == BAKE_LIGHT_MAP or seaconfig_bakeoutput == BAKE_AO then
(
appendLightMap mat tex
)
else
(
mat.diffuseMap = tex
)
mat.showInViewport = true
obj.material = mat
)
else
(
tex.coords.mapChannel = uv_bake
if classof obj.material == StandardMaterial then
(
if temp or (appendBakeMaterial obj.material) do
(
local diffMap = obj.material.diffuseMap
obj.material = copy obj.material
if (classof diffMap == CompositeTexture) or (classof diffMap == BitmapTexture) then
diffMap = copy diffMap
obj.material.diffuseMap = diffMap
)
appendLightMap obj.material tex
)
else if classof obj.material == MultiMaterial then
(
if temp do obj.material = copy obj.material
for m=1 to obj.material.materiallist.count do
(
if classof obj.material.materiallist[m] == StandardMaterial then
(
local diffMap = obj.material.materiallist[m].diffuseMap
if temp or (appendBakeMaterial obj.material.materiallist[m]) do
obj.material.materiallist[m] = copy obj.material.materiallist[m]
if (classof diffMap == CompositeTexture) or (classof diffMap == BitmapTexture) do
diffMap = copy diffMap
obj.material.materiallist[m].diffuseMap = diffMap
appendLightMap obj.material.materiallist[m] tex
)
else
(
error1302 obj.name
)
)
)
else
(
error1302 obj.name
)
)
)
catch()
backgroundColor = bgColor
)
fn creatSEA3DTag m =
(
local tag = EmptyModifier()
tag.name = "SEA3D Tag"
custattributes.add tag SEA3DTagDef
addModifier m tag
)
fn creatSEA3DSound snd =
(
p = PointHelperObj()
p.cross = false
p.box = true
p.size = 300
sc = EmptyModifier()
sc.name = "SEA3D Sound"
custattributes.add sc SEA3DSoundDef
local ca = custattributes.get sc 1
ca.soundparam = snd
addModifier p sc
return p
)
fn creatSEA3DSprite =
(
p = Plane()
p.length = 50
p.lengthsegs = 1
p.width = 50
p.widthsegs = 1
setUserProp p "material-blendtype" "add"
sc = EmptyModifier()
sc.name = "SEA3D Sprite"
custattributes.add sc SEA3DSpriteDef
local ca = custattributes.get sc 1
ca.widthparam = 50
ca.heightparam = 50
local o_pos = p.pos
p.transform = inverse (viewport.getTM())
p.pos = o_pos
addModifier p sc
return p
)
fn rotateMatrix t offset =
(
local r = t.rotation as eulerangles
r.x += offset.x
r.y += offset.y
r.z += offset.z
r = (r as matrix3) * (scaleMatrix t.scale)
r.position = t.position
return r
)
fn getInstanceIndex n returnnode: =
(
InstanceMgr.GetInstances n &instances
for j=1 to instances.count do
(
local inst = instances[j]
for i=1 to seaObjectList.count do
(
local obj = seaObjectList[i].obj
if obj == inst do
(
if obj.modifiers.count == inst.modifiers.count then
(
local validInst = true
for m=1 to obj.modifiers.count do
(
if obj.modifiers[m] != inst.modifiers[m] then
(
validInst = false
)
)
if validInst and seaconfig_positive_scale then
(
local objS = obj.scale.x < 0 or obj.scale.y < 0 or obj.scale.z < 0
local instS = inst.scale.x < 0 or inst.scale.y < 0 or inst.scale.z < 0
validInst = (objS == instS)
)
if validInst then
(
if returnnode == unsupplied then return i
else return obj
)
else
(
warning2011 n.name
)
)
else
(
warning2011 n.name
)
)
)
)
return 0
)
function getSEATag obj =
(
for m=1 to obj.modifiers.count do
(
if (ClassOf obj.modifiers[m] == EmptyModifier and obj.modifiers[m].enabled) then
(
try
(
local md = custAttributes.get obj.modifiers[m] 1
if md.name == "SEA3DTagDef" then
(
return obj.modifiers[m]
)
)
catch()
)
)
return undefined
)
function getCompositeAnimationTokenList obj =
(
local tokenList = #()
if obj.coords.U_Offset.isAnimated do (
append tokenList #(ANM_OFFSET_U,10) -- offsetU, float
)
if obj.coords.V_Offset.isAnimated do (
append tokenList #(ANM_OFFSET_V,10) -- offsetV, float
)
if obj.coords.U_Tiling.isAnimated do (
append tokenList #(ANM_SCALE_U,10) -- scaleU, float
)
if obj.coords.V_Tiling.isAnimated do (
append tokenList #(ANM_SCALE_V,10) -- scaleV, float
)
if obj.coords.W_Angle.isAnimated do (
append tokenList #(ANM_RADIAN,10) -- rotationUV, float
)
return tokenList
)
fn getDepthList list =
(
local pcount = #()
for i = 1 to list.count do
(
local c = 0
local p = list[i].parent
while (p != undefined) do
(
p = p.parent
c += 1
)
pcount[i] = c
)
return pcount
)
-- source: md5 exporter by der_ton, tom-(at)gmx.de
fn righthand_mat mat =
(
-- convert the matrix to a righthanded one, by flipping its Z axis if it's lefthanded
if dot (cross mat.row1 mat.row2) mat.row3 > 0 then
(
md5mat = copy mat
)
else
(
md5mat = copy mat
md5mat.row3 = - md5mat.row3
)
return md5mat
)
fn normalToTangent normal =
(
return cross normal (point3 0 1 0)
)
fn sortHierarchyFN v1 v2 dep: =
(
local dp1 = dep[v1]
local dp2 = dep[v2]
case of
(
(dp1 > dp2): 1
(dp1 < dp2): -1
default:0
)
)
fn sortHierarchy list dep =
(
local indexArray = for i = 1 to list.count collect i
qsort indexArray sortHierarchyFN dep:dep
local nlist = for i = 1 to list.count collect list[i]
local nindex = #()
for i = 1 to list.count do
(
list[i] = nlist[indexArray[i]]
nindex[indexArray[i]] = i
)
return nindex
)
fn getDepth obj =
(
local c = 0
local p = obj.parent
while (p != undefined) do
(
p = p.parent
c += 1
)
InstanceMgr.GetInstances obj &instances
if instances.count > 1 then
(
local skinAt = 0
for m=1 to obj.modifiers.count do
(
if (ClassOf obj.modifiers[m] == Skin and obj.modifiers[m].enabled) then
(
skinAt = m
)
)
if skinAt > 0 then
(
local skinObj = obj.modifiers[skinAt]
selectMod obj skinObj
-- skeleton
local numbones = skinops.getnumberbones skinObj
-- sort dependencies
local boneList = #()
for i=1 to numbones do
(
local boneobjname = skinops_getBoneNameByListID skinObj i 0
boneList[i] = getnodebyname boneobjname
)
sortHierarchy boneList (getDepthList boneList)
local posRelative = boneList[1].transform.position
local actDistance = 0xFFFFFFFF
local rootObj = instances[1]
for i=1 to instances.count do
(
local dist = distance instances[i].center boneList[1].center
if dist < actDistance then
(
rootObj = instances[i]
actDistance = dist
)
)
if rootObj != obj then
(
c += 1
)
)
)
return c
)
fn getDependenceList list =
(
local sel = GetCurrentSelection()
local pcount = #()
for i = 1 to list.count do
(
pcount[i] = getDepth list[i]
)
selectMore sel
return pcount
)
fn getMassList list =
(
local sel = GetCurrentSelection()
local pcount = #()
local minValue = 0xFFFFFFFF
local maxValue = 0x00
for i = 1 to list.count do
(
local bb = list[i].max - list[i].min
local liter = (bb.x + bb.y + bb.z) / 3
if liter > maxValue then
(
maxValue = liter
)
else if liter < minValue then
(
minValue = liter
)
pcount[i] = liter
)
maxValue -= minValue
for i = 1 to list.count do
(
pcount[i] = (pcount[i] - minValue) / maxValue
)
selectMore sel
return pcount
)
function removeObjectTransform object =
(
object.position.controller = Position_XYZ()
object.position = [0,0,0]
object.rotation.controller = Euler_XYZ()
object.rotation = eulerangles 0 0 0 --quat 0 0 0 1
object.scale.controller = Bezier_Scale()
object.scale = [1,1,1]
)
function colorNotEqual c v =
(
return (ceil c.r != v or ceil c.g != v or ceil c.b != v)
)
function newAsset =
(
return (dotNetObject "Poonya.SEA3D.Objects.SEAData")
)
function newNode =
(
return (dotNetObject "Poonya.Utils.ByteArray")
)
function realParent obj =
(
obj = obj.parent
while obj != undefined do
(
local id = finditem seasceneobject obj
if id == 0 then
(
local id = finditem seaboneobject obj
if id == 0 then
(
obj = obj.parent
)
else return obj
)
else return obj
)
return undefined
)
function containsSEA3DTag obj =
(
for i = 1 to obj.modifiers.count do
(
local m = obj.modifiers[i]
if (classof m) == EmptyModifier then
(
try
(
local _mod = custAttributes.get n.modifiers[1] 1
if _mod.name == "SEA3DTagDef" then
(
return true
)
)
catch()
)
)
return false
)
function realTransform obj useparent: p: t: tp: =
(
local matRelative = obj.transform
if useparent == unsupplied then
useparent = seauseparent
if classof t == Matrix3 then
(
-- bind matrix
matRelative *= inverse (righthand_mat t)
)
if useparent then
(
if p == unsupplied then
p = realParent obj
if p != undefined then
(
local trans = p.transform
if classof tp == Matrix3 do
(
-- bind parent matrix
trans *= inverse (righthand_mat tp)
)
matRelative *= inverse (righthand_mat trans)
)
)
return (righthand_mat matRelative)
)
function containsDifference val0 val1 =
(
return ((distance val0 val1) > seaconfig_mindiff)
)
function containsPosition obj =
(
seatime seaTimeRange[1]
local p = undefined
if seauseparent do p = realParent obj
local value = obj.transform
if p != undefined then
value *= inverse p.transform
for t = seaTimeRange[1] to seaTimeRange[2] do
(
seatime t
local trans = obj.transform
if p != undefined then
trans *= inverse p.transform
if (containsDifference value.position trans.position) then
return true
)
return false
)
function containsRotation obj =
(
seatime seaTimeRange[1]
local p = undefined
if seauseparent do p = realParent obj
local value = obj.transform
if p != undefined then
value *= inverse p.transform
for t = seaTimeRange[1] to seaTimeRange[2] do
(
seatime t
local trans = obj.transform
if p != undefined then
trans *= inverse p.transform
if value.rotation != trans.rotation then
return true
)
return false
)
function containsScale obj =
(
seatime seaTimeRange[1]
local p = undefined
if seauseparent do p = realParent obj
local value = obj.transform
if p != undefined then
value *= inverse p.transform
for t = seaTimeRange[1] to seaTimeRange[2] do
(
seatime t
local trans = obj.transform
if p != undefined then
trans *= inverse p.transform
if (containsDifference value.scale trans.scale) then
return true
)
return false
)
function containsInvalidParentAnimation obj =
(
try
(
obj = obj.parent
if obj == undefined then
return false
while obj != undefined do
(
local id = finditem seasceneobject obj
if id == 0 then
(
local id = finditem seaboneobject obj
if id == 0 then
(
local _containsPos = ps and (containsPosition obj)
local _containsRot = rt and (containsRotation obj)
local _containsScl = sc and (containsScale obj)
if _containsPos or _containsRot or _containsScl then
return true
obj = obj.parent
)
else return false
)
else return false
)
)
catch ()
return false
)
function getBlendIndex name =
(
local index = findItem seablendpalette name
if index > 0 do index -= 1
return index
)
function getSEAIndex obj type =
(
if obj != undefined do
(
local objName = obj.name + type
if (finditem seaAssetNames objName) > 0 then
(
local index = (finditem seaAssetNames objName) - 1
-- object3d parent
return (SEAIndex SEA_INDEX index)
)
else if (finditem seaboneobject obj) > 0 then
(
local globalBoneIndex = finditem seaboneobject obj
objName = seaboneinobject[globalBoneIndex].name + type
local index = (finditem seaAssetNames objName) - 1
local boneIndex = (finditem seabonelist[globalBoneIndex] obj) - 1
-- joint parent
return (SEAIndex SEA_JOINT_INDEX index boneIndex)
)
)
undefined
)
function getAssetIndex obj type =
(
return (getSEAIndex obj type).index
)
function seaDispose =
(
function disposeMesh obj =
(
while obj.modifiers.count > 0 do
(
if (substring obj.modifiers[1].name 1 5) == "SEA3D" then
(
deleteModifier obj obj.modifiers[1]
)
else exit
)
delete obj
)
removeTempObject()
for file in seaTempFileList do
(
deleteFile file
)
seaTempFileList = #()
for m in seaModifierList do
(
deleteModifier m.obj m.m
)
for sea in seaObjectList do
(
if classof sea == SEAMesh do
(
if sea.temp != undefined do
(
disposeMesh sea.temp
sea.temp = undefined
)
if sea.normalNObj != undefined do
(
disposeMesh sea.normalNObj
sea.normalNObj = undefined
)
)
)
seamats =
seamatnames =
seaactions =
seanames =
seasceneobject =
seaboneobject =
seaboneinobject =
seabonelist =
seaErrors =
seaWarning =
seaMaterials =
seaTBakes =
seaBitmapList =
seaCubeList =
seaTextureList =
seaMaterialList =
seaObjectList =
seaAssetList =
seaAssetNames =
seaModifierList = undefined
gc()
)
--
-- Append
--
function appendSceneObject obj =
(
append seasceneobject obj
)
function appendBones obj boneList =
(
for i=1 to boneList.count do
(
append seaboneobject boneList[i]
append seaboneinobject obj
append seabonelist boneList
)
)
function appendAsset asset share: type: =
(
local index = undefined
if share == unsupplied do
share = isValidInstancing()
if share then index = sea3d.AddSharedObject asset
else index = sea3d.AddObject asset
if type == unsupplied then
seaAssetNames[index+1] = asset.Filename
else
seaAssetNames[index+1] = asset.Name + type
return index
)
function appendToken list token value type =
(
append list (#(token,value,type))
)
function getTexture filename =
(
for i=1 to seaBitmapList.count do
(
if (seaBitmapList[i].filename == filename) do
(
return seaBitmapList[i]
)
)
return undefined
)
function appendBitmap filename n map: =
(
f = toLowerString filename
local seaBmp = getTexture filename
if seaBmp != undefined do return seaBmp
local ext = getExtension f
local _bitmap = undefined
if seaconfig_embedtextures then
(
if ext == EXT_JPEG or ext == EXT_PNG or ext == EXT_GIF or ext == EXT_JPEG_XR then
(
if fileExist filename then
(
_bitmap = SEABitmap filename
)
else if seaconfig_baketextures then
(
_bitmap = SEABitmap filename (bakeTexture map)
)
else
(
error1016 f n
)
)
else if seaconfig_baketextures then
(
_bitmap = SEABitmap filename (bakeTexture map)
)
)
else
(
_bitmap = SEABitmap filename
)
if _bitmap != undefined then
(
append seaBitmapList _bitmap
return _bitmap
)
else
(
error1014 (getName filename) n
)
)
function appendCube map textures n =
(
for i=1 to seaCubeList.count do
(
local equal = textures.count == seaCubeList[i].textures.count
if equal then
(
for j=1 to textures.count do
(
if textures[j].filename != seaCubeList[i].textures[j].filename then
(
equal = false
exit
)
)
)
if equal do return seaCubeList[i]
)
local cube = SEACube map textures
append seaCubeList cube
if cube.textures.count > 0 then
(
local filename = textures[1].filename
local ext = getExtension filename
if ext == EXT_JPEG or ext == EXT_PNG or ext == EXT_GIF or EXT_JPEG_XR then
(
for i=1 to cube.textures.count do
(
filename = textures[i].filename
if (ext == (getExtension filename)) then
(
cube.bitmaps[i] = filename
)
else
(
error1021 (getName filename) matName
)
)
)
else
(
error1014 (getName filename) n
)
)
return cube
)
function appendCubeTexture map type matName singleCube =
(
local names = #()
for i=1 to seaCubeList.count do
(
names[i] = seaCubeList[i].obj.name
if seaCubeList[i].obj.name == map.name do
(
if seaCubeList[i].obj == map then
(
return seaCubeList[i]
)
else
(
if seaconfig_auto_rename then map.name = getValidName map.name names
else error1003 map.name
)
)
)
if (singleCube and classof map == BitmapTexture) then
(
return (appendCube map #(map) matName)
)
else if (classof map == CompositeTexturemap) then
(
local successfully = true
local textures = #()
for i=1 to map.mapList.count do
(
local dm = map.mapList[i]
local nm = map.layerName[i]
if (map.mapEnabled[i] == false) do continue
if (dm != undefined) then
(
if (classof dm == BitmapTexture) then
(
nm = toLowerString nm
if nm == "left" then textures[1] = dm
else if nm == "right" then textures[2] = dm
else if nm == "bottom" then textures[3] = dm
else if nm == "top" then textures[4] = dm
else if nm == "back" then textures[5] = dm
else if nm == "front" then textures[6] = dm
else
(
error1019 ("Map "+(i as string)) type matName map.layerName[i]
successfully = false
)
)
else
(
error1017 ("Map "+(i as string)) type matName
successfully = false
)
)
else
(
error1018 ("Map "+(i as string)) type matName
successfully = false
)
)
if textures.count != 6 then
(
error1020 type matName
return undefined
)
else
(
for i=1 to textures.count do
(
if (textures[i] == undefined) then
(
error1020 type matName
return undefined
)
)
)
if successfully then
(
return (appendCube map textures matName)
)
)
else
(
error1013 type matName
)
return undefined
)
function appendTexture map n type enabledComposite =
(
local names = #()
for i=1 to seaTextureList.count do
(
names[i] = seaTextureList[i].obj.name
if seaTextureList[i].obj.name == map.name do
(
if seaTextureList[i].obj == map then
(
return seaTextureList[i]
)
else
(
if seaconfig_auto_rename then map.name = getValidName map.name names
else error1003 map.name
)
)
)
local sea = SEATexture map
append seaTextureList sea
if classof map == BitmapTexture then
(
local bmpTex = appendBitmap map.filename n map:map
sea.textures[1] = map
sea.blendMode[1] = "normal"
sea.opacity[1] = 100.0
if seaconfig_animation and (getCompositeAnimationTokenList map).count > 0 then
sea.animation[1] = map.name
append sea.bitmaps bmpTex
)
else if enabledComposite and classof map == CompositeTexturemap then
(
local c = 1
for i=1 to map.mapList.count do
(
local en = map.mapEnabled[i]
local dm = map.mapList[i]
local mm = map.mask[i]
local emm = map.maskEnabled[i]
local blendMode = seacompositepalette[ map.blendMode[i] + 1 ]
local opacity = map.opacity[i]
local nm = map.layerName[i]
if en and dm != undefined then
(
local diffuseTexture = undefined
if classof dm == BitmapTexture then
(
diffuseTexture = dm
)
else if seaconfig_baketextures then
(
-- Bake Texture
diffuseTexture = BitmapTexture()
diffuseTexture.name = dm.name
diffuseTexture.filename = bakeTexture dm
)
else
(
error1017 ("Map "+(i as string)) type n
continue
)
local diffuseBitmap = appendBitmap diffuseTexture.filename n map:dm
append sea.bitmaps diffuseBitmap
if nm == SH_LIGHT_MAP then
(
local uvChannel = undefined
if seaconfig_multiplechannel and seaconfig_uv then
(
uvChannel = diffuseTexture.coords.mapChannel - 1
)
else
(
uvChannel = 0
)
sea.lightMapTexture = SEABitmapComposite diffuseBitmap blendMode uvChannel
)
else if nm == SH_DETAIL_MAP then
(
local tiling = undefined
if diffuseTexture.coords.U_Tile == true and diffuseTexture.coords.V_Tile == true then
(
tiling = (diffuseTexture.coords.U_Tiling + diffuseTexture.coords.V_Tiling) / 2
)
else
(
tiling = 1
)
sea.detailMapTexture = SEABitmapComposite diffuseBitmap blendMode tiling
)
else
(
sea.textures[c] = diffuseTexture
sea.opacity[c] = opacity
sea.blendMode[c] = blendMode
sea.name[c] = nm
if seaconfig_animation and (getCompositeAnimationTokenList diffuseTexture).count > 0 then
sea.animation[c] = diffuseTexture.name + ":texture" + ((i-1) as string)
if emm and mm != undefined do
(
if classof mm == BitmapTexture then
(
sea.masks[c] = mm
if seaconfig_animation and (getCompositeAnimationTokenList mm).count > 0 then
sea.animationMask[c] = mm.name + ":mask" + ((i-1) as string)
append sea.bitmaps (appendBitmap mm.filename n map:mm)
)
else if seaconfig_baketextures then
(
local bakeBitmap = BitmapTexture()
bakeBitmap.name = mm.name
bakeBitmap.filename = bakeTexture mm
sea.masks[c] = bakeBitmap
append sea.bitmaps (appendBitmap bakeBitmap.filename n)
)
else
(
error1017 ("Mask "+(i as string)) type n
)
)
c += 1
)
)
)
)
else if seaconfig_baketextures then
(
local bakeBitmap = BitmapTexture()
bakeBitmap.name = map.name
bakeBitmap.filename = bakeTexture map
sea.textures[1] = bakeBitmap
sea.blendMode[1] = "normal"
sea.opacity[1] = 100.0
append sea.bitmaps (appendBitmap bakeBitmap.filename n)
)
else
(
error1013 type n
)
return sea
)
--
-- Writers
--
function writeTag data n kind =
(
data.WriteUInt16 kind
data.WriteDataObject n
)
function writeTags data count nodeData: =
(
data.WriteByte count
if count > 0 do (
data.WriteData nodeData
)
)
function writeStr data t =
(
if t != undefined and t != unsupplied then data.WriteUTF8 t
else data.WriteByte 0
)
function write3D data t =
(
data.WriteFloat t.x
data.WriteFloat t.z
data.WriteFloat t.y
)
function writeQuat data t =
(
data.WriteFloat t.x
data.WriteFloat t.z
data.WriteFloat t.y
data.WriteFloat t.w
)
function writeColor data t =
(
data.WriteByte t.b
data.WriteByte t.g
data.WriteByte t.r
)
function writePosition data obj useparent: p: t: tp: =
(
local trans = realTransform obj useparent:useparent p:p t:t tp:tp
write3D data trans.position
)
function writeRotation data obj useparent: p: t: tp: offset: =
(
local trans = realTransform obj useparent:useparent p:p t:t tp:tp
if offset != unsupplied do
(
trans = rotateMatrix trans offset
)
writeQuat data trans.rotation
)
function writeScale data obj useparent: p: t: tp: =
(
local trans = realTransform obj useparent:useparent p:p t:t tp:tp
write3D data trans.scale
)
function positiveMatrixScale &t =
(
local x = t.scale.x,
y = t.scale.y,
z = t.scale.z
if x < 0 do t.scale.x = -x
if y < 0 do t.scale.y = -y
if z < 0 do t.scale.z = -z
)
function writeMatrix3x4 data t =
(
local r = t.row1
data.WriteFloat r.x
data.WriteFloat r.z
data.WriteFloat r.y
r = t.row3
data.WriteFloat r.x
data.WriteFloat r.z
data.WriteFloat r.y
r = t.row2
data.WriteFloat r.x
data.WriteFloat r.z
data.WriteFloat r.y
r = t.row4
data.WriteFloat r.x
data.WriteFloat r.z
data.WriteFloat r.y
)
function writeMatrix data obj useparent: p: position: offset: ignoreRotation: =
(
local t = realTransform obj useparent:useparent p:p
if offset != unsupplied then
(
t = rotateMatrix t offset
)
else if ignoreRotation == true then
(
local r = scaleMatrix t.scale
r.position = t.position
t = r
)
if position != unsupplied do
(
t.position = position
)
if seaconfig_positive_scale do
positiveMatrixScale &t
writeMatrix3x4 data t
)
function writeBone data obj type parent: bindpos: =
(
local matRelative = righthand_mat obj.transform
if (parent == undefined or parent == unsupplied) and bindpos != unsupplied then
matRelative.position = matRelative.position - bindpos
if seauseboneparent and (parent != undefined and parent != unsupplied) do
(
matRelative.position *= matRelative.scale
local parentTrans = righthand_mat parent.transform
parentTrans.position *= parentTrans.scale
parentTrans = righthand_mat parentTrans
matRelative *= inverse parentTrans
)
matRelative = righthand_mat matRelative
if type == SEA_QUATERNION then
(
write3D data matRelative.position
writeQuat data matRelative.rotation
)
else if type == SEA_INV_MATRIX then
(
writeMatrix3x4 data (inverse matRelative)
)
)
function writeAnimationList data list =
(
data.WriteByte list.count
for i = 1 to list.count do
(
local anm = list[i]
local attrib = 0x00
if anm.relative do
attrib = bit.set attrib 1 true
data.WriteByte attrib
data.WriteInt32 anm.index
)
)
function writeAnimationHead data sequence: =
(
local containsSequence = sequence != undefined and sequence != unsupplied
local flag = 0x00
if containsSequence do
flag += HEADER_ANIMATION_SEQUENCE
data.WriteByte flag
if containsSequence do
data.WriteData sequence
data.WriteByte framerate
data.WriteInt32 ((seaTimeRange[2] - seaTimeRange[1])+1)
)
function writeCompositeLayer data tex anm =
(
local useMapChannel = tex.coords.mapChannel > 1 and (seaconfig_multiplechannel and seaconfig_uv)
local useCustomRepeat = tex.coords.U_Tile == false and tex.coords.V_Tile == false
local useOffsetU = tex.coords.U_Offset != 0
local useOffsetV = tex.coords.V_Offset != 0
local useScaleU = tex.coords.U_Tiling != 1
local useScaleV = tex.coords.V_Tiling != 1
local useRotation = tex.coords.W_Angle != 0
local useAnimation = anm != undefined
local ext_attrib = 0
if useMapChannel do
ext_attrib = bit.set ext_attrib 1 true
if useCustomRepeat do
ext_attrib = bit.set ext_attrib 2 true
if useOffsetU do
ext_attrib = bit.set ext_attrib 3 true
if useOffsetV do
ext_attrib = bit.set ext_attrib 4 true
if useScaleU do
ext_attrib = bit.set ext_attrib 5 true
if useScaleV do
ext_attrib = bit.set ext_attrib 6 true
if useRotation do
ext_attrib = bit.set ext_attrib 7 true
if useAnimation do
ext_attrib = bit.set ext_attrib 8 true
data.WriteInt32 (getTexture tex.filename).asset
data.WriteUInt16 ext_attrib
if useMapChannel do
data.WriteByte (tex.coords.mapChannel-1)
if useOffsetU do
data.WriteFloat tex.coords.U_Offset
if useOffsetV do
data.WriteFloat tex.coords.V_Offset
if useScaleU do
data.WriteFloat tex.coords.U_Tiling
if useScaleV do
data.WriteFloat tex.coords.V_Tiling
if useRotation do
data.WriteFloat (degToRad tex.coords.W_Angle)
if useAnimation do
writeAnimationList data #( SEAAnimator anm )
)
function writeAppendJointObject obj =
(
local asset = newAsset()
local data = asset.Data
asset.Filename = obj.name + EXT_JOINT_OBJECT
-- HEADER
local header = 0x0000
local body = newNode()
local indexData = getSEAIndex obj EXT_SCENE_OBJECT
-- PARENT
header += HEADER_PARENT
body.WriteInt32 indexData.index
-- TARGET | JOINT OBJECT
body.WriteInt32 indexData.index
body.WriteUInt16 indexData.joint
-- HEADER | BODY
data.WriteUInt16 header
data.WriteData body
-- TAGS
writeTags data 0
return (appendAsset asset)
)
function writeAppendSoundMixer ns =
(
local filename = ns + EXT_SOUND_MIXER
local index = findItem seaAssetNames filename
if index == 0 then
(
local asset = newAsset()
local data = asset.Data
asset.Filename = filename
-- ATTRIB
data.WriteByte 0x00
index = appendAsset asset share:false
)
return index
)
function writeObject3D data sea &header animation: =
(
-- HEADER
local parent = realParent sea.obj
local useInstance = sea.instanceof != undefined
local useAttribs = sea.attribs != undefined
if seaconfig_instanceanimation and sea.animation == undefined and useInstance and sea.instanceof.animation != undefined then
(
sea.animation = sea.instanceof.animation
)
if animation == unsupplied or animation == undefined then
(
animation = #()
)
if sea.animation != undefined then
(
append animation ( SEAAnimator sea.animation (seaconfig_bindoffset and parent == undefined) )
)
-- WRITER
if seauseparent and parent != undefined then
(
header += HEADER_PARENT
local indexData = getSEAIndex parent EXT_SCENE_OBJECT
if indexData.type == SEA_INDEX then
(
-- SEA3D ASSET INDEX
data.WriteInt32 indexData.index
)
else if indexData.type == SEA_JOINT_INDEX then
(
data.WriteInt32 (writeAppendJointObject parent)
)
)
if animation.count > 0 then
(
header += HEADER_ANIMATION
writeAnimationList data animation
)
if useAttribs then
(
header += HEADER_PROPERTIES
data.WriteInt32 sea.attribs
)
)
function writeDataList data list =
(
for i=1 to list.count do
(
local type = list[i][1]
local value = list[i][2]
if type == DT_UINT then data.WriteInt32 value
else if type == DT_FLOAT then data.WriteFloat value
else if type == DT_STRING then data.WriteUTF8 value
else if type == DT_COLOR then WriteColor data value
else if type == DT_BYTE then data.WriteByte value
else if type == DT_BITMAP then data.WriteInt32 value.obj.asset
else if type == DT_TEXTURE then data.WriteInt32 (value.getBitmap())
else if type == DT_COMPOSITE then data.WriteInt32 (getAssetIndex value.obj EXT_COMPOSITE)
else if type == DT_CUBE then data.WriteInt32 (getAssetIndex value.obj EXT_CUBE_MAPPING)
else if type == DT_CUBE_RTT then data.WriteInt32 value.rttCubeAsset
else if type == DT_PLANAR_RTT then data.WriteInt32 value.rttPlanarAsset
)
)
function writeMaterialTechs data tech =
(
data.WriteByte tech.count
for i = 1 to tech.count do
(
local attrib = tech[i]
local type = attrib[1]
deleteItem attrib 1
local nodeData = newNode()
writeDataList nodeData attrib
data.WriteUInt16 type
data.WriteUInt16 nodeData.Length
data.WriteData nodeData
)
)
--
-- Compiler
--
fn compileStandardMaterial mat =
(
local sea = SEAMaterial mat
local t = undefined
if (mat.shaderType == 0) then t = "Anisotropic"
else if (mat.shaderType == 2) then t = "Metal"
else if (mat.shaderType == 3) then t = "Multi-Layer"
else if (mat.shaderType == 4) then t = "Oren-Nayar-Blinn"
else if (mat.shaderType == 6) then t = "Strauss"
if (t != undefined) then
(
error1012 t mat.name
return undefined
)
sea.twoSided = mat.twoSided
sea.smoothMat = mat.faceted == false
sea.containsAlpha = mat.opacity != 100.0
sea.opacity = mat.opacity / 100.0
local tech = sea.tech
local _ambient = undefined
if (mat.useSelfIllumColor) then
_ambient = mat.selfIllumColor
else
(
local _color = ((mat.selfIllumAmount/100.0) * 255.0)
_ambient = color _color _color _color
)
append tech #(
MAT_DEFAULT,
#(DT_COLOR, _ambient),
#(DT_COLOR, mat.diffuse),
#(DT_COLOR, mat.specular),
#(DT_FLOAT, mat.specularLevel/100.0),
#(DT_FLOAT, mat.glossiness)
)
if mat.shaderType == 7 then
(
append tech #(
MAT_TRANSLUCENT,
#(DT_COLOR, mat.translucentColor),
#(DT_FLOAT, mat.translucentColorMapAmount/100.0),
#(DT_FLOAT, .5)
)
)
if (seaconfig_texture and mat.diffuseMapEnable and mat.diffuseMap != undefined) then
(
local tex = appendTexture mat.diffusemap mat.name "Diffuse Map" true
append sea.maps tex
if tex.isValid() then
(
append tech #(
tex.diffuseType(),
#(tex.type(),tex)
)
)
if tex.lightMapTexture != undefined then
(
append tech #(
MAT_LIGHT_MAP,
#(DT_BITMAP, tex.lightMapTexture),
#(DT_BYTE, tex.lightMapTexture.data),
#(DT_BYTE, (getBlendIndex tex.lightMapTexture.blendMode))
)
)
if tex.detailMapTexture != undefined then
(
append tech #(
MAT_DETAIL_MAP,
#(DT_BITMAP, tex.detailMapTexture),
#(DT_FLOAT, tex.detailMapTexture.data),
#(DT_BYTE, (getBlendIndex tex.detailMapTexture.blendMode))
)
)
)
if (seaconfig_texture and mat.specularMapEnable and mat.specularMap != undefined) then
(
local tex = appendTexture mat.specularMap mat.name "Specular Map" false
if tex.isValid() then
(
append sea.maps tex
append tech #(
MAT_SPECULAR_MAP,
#(tex.type(),tex)
)
)
)
if (seaconfig_texture and mat.refractionMapEnable and mat.refractionMap != undefined) do
(
local tex = appendCubeTexture mat.refractionMap "Refraction Map" mat.name false
if tex.isValid() then
(
append sea.maps tex
append tech #(
MAT_REFRACTION_MAP,
#(DT_CUBE, tex),
#(DT_FLOAT, (mat.refractionMapAmount/100.0)),-- alpha
#(DT_FLOAT, 0.9)-- ior
)
)
)
if (seaconfig_texture and mat.bumpMap != undefined and mat.bumpMapEnable) do
(
if (classof mat.bumpMap == Normal_Bump) then
(
if (mat.bumpMap.normal_map != undefined) do
(
local tex = appendTexture mat.bumpMap.normal_map mat.name "Normal Map" false
if tex.isValid() then
(
append sea.maps tex
append tech #(
MAT_NORMAL_MAP,
#(tex.type(),tex)
)
)
)
if (mat.bumpMap.bump_map != undefined) do
(
warning2005 mat.name
)
)
else
(
local tex = appendTexture mat.bumpMap mat.name "Bump Map" false
if tex.isValid() then
(
append sea.maps tex
append tech #(
MAT_NORMAL_MAP,
#(tex.type(),tex)
)
)
)
)
if (mat.reflectionMapEnable and mat.reflectionMap != undefined) do
(
if classof mat.reflectionMap == Falloff then
(
if mat.reflectionMap.type == 2 then
(
if mat.reflectionMap.map2On == true and mat.reflectionMap.map2 != undefined then
(
if seaconfig_texture then
(
local tex_type = undefined
if classof mat.reflectionMap.map2 == ReflectRefract and seaconfig_rtt then
(
-- Environment Reflection
sea.rttCube = true
tex_type = #(DT_CUBE_RTT, sea)
)
else if seaconfig_texture then
(
local tex = appendCubeTexture mat.reflectionMap.map2 "Reflection Map" mat.name false
if tex.isValid() then
(
append sea.maps tex
tex_type = #(DT_CUBE, tex)
)
)
if tex_type != undefined then
(
append tech #(
MAT_FRESNEL_REFLECTION,
tex_type,
#(DT_FLOAT, mat.reflectionMapAmount/100.0),-- alpha
#(DT_FLOAT, 2),-- fresnelPower
#(DT_FLOAT, 0) -- normalReflectance
)
)
)
)
else
(
append tech #(
MAT_RIM,
#(DT_COLOR, mat.reflectionMap.color2),-- color
#(DT_FLOAT, mat.reflectionMapAmount/100.0),-- strength
#(DT_FLOAT, 2),-- power
#(DT_BYTE, 5)-- 5 = mix (blend mode)
)
)
)
else if seaconfig_texture then
(
warning2008 "Reflection Map" mat.name
)
)
else if classof mat.reflectionMap == FlatMirror and seaconfig_rtt then
(
-- Planar Reflection
sea.rttPlanar = true
append tech #(
MAT_MIRROR_REFLECTION,
#(DT_PLANAR_RTT, sea),
#(DT_FLOAT, mat.reflectionMapAmount/100.0)
)
)
else if classof mat.reflectionMap == ReflectRefract and seaconfig_rtt then
(
-- Environment Reflection
sea.rttCube = true
append tech #(
MAT_REFLECTION_MAP,
#(DT_CUBE_RTT, sea),
#(DT_FLOAT, mat.reflectionMapAmount/100.0)
)
)
else if seaconfig_texture then
(
local tex = appendCubeTexture mat.reflectionMap "Reflection Map" mat.name true
if tex.isValid() then
(
append sea.maps tex
append tech #(
MAT_REFLECTION_MAP,
#(DT_CUBE, tex),
#(DT_FLOAT, mat.reflectionMapAmount/100.0)
)
)
)
)
--
-- if (seaconfig_texture and mat.opacityMapEnable and mat.opacityMap != undefined) then
-- (
-- local tex = appendTexture mat.opacityMap mat.name "Opacity Map" false
--
-- if tex.isValid() then
-- (
-- append sea.maps tex
--
-- append tech #(
-- MAT_OPACITY_MAP,
-- #(tex.type(),tex)
-- )
-- )
-- )
return sea
)
fn compileInkMaterial mat =
(
local sea = SEAMaterial mat
sea.twoSided = mat.two_side_on
sea.smoothMat = mat.faceted_on == false
sea.containsAlpha = mat.paint_map_amt != 100.0
local tech = sea.tech
append tech #(
MAT_CEL,
#(DT_COLOR, mat.color1),
#(DT_BYTE, mat.paint_levels),
#(DT_FLOAT, mat.min_ink_width),
#(DT_FLOAT, .5),
#(DT_FLOAT,.1)
)
append tech #(
MAT_DEFAULT,
#(DT_COLOR, (color 50 50 50)),-- ambient
#(DT_COLOR, mat.paint_color), -- diffuse
#(DT_COLOR, (color 255 255 255)), -- specular
#(DT_FLOAT, 0.30),
#(DT_FLOAT, 10.0)
)
if (seaconfig_texture and mat.bump_map_on and mat.bump_map != undefined) then
(
local tex = appendTexture mat.bump_map mat.name "Paint Map" false
if tex.isValid() then
(
append sea.maps tex
append tech #(
MAT_NORMAL_MAP,
#(tex.type(),tex)
)
)
)
if (seaconfig_texture and mat.paint_map_on and mat.paint_map != undefined) then
(
local tex = appendTexture mat.paint_map mat.name "Paint Map" false
if tex.isValid() then
(
append sea.maps tex
append tech #(
tex.diffuseType(),
#(tex.type(),tex)
)
)
)
return sea
)
fn compileVRayMaterial mat =
(
local sea = SEAMaterial mat
local opacity = mat.refraction.value
local spec = mat.reflection.value
if spec > 0 do spec = 1.0
sea.twoSided = mat.option_doubleSided
sea.containsAlpha = opacity != 255.0
sea.opacity = opacity/255.0
local tech = sea.tech
append tech #(
MAT_DEFAULT,
#(DT_COLOR, (color 50 50 50)),
#(DT_COLOR, mat.diffuse),
#(DT_COLOR, mat.reflection),
#(DT_FLOAT, spec),-- specular level
#(DT_FLOAT, mat.reflection_glossiness)
)
if (seaconfig_texture and mat.texmap_diffuse_on and texmap_diffuse != undefined) then
(
local tex = appendTexture mat.texmap_diffuse mat.name "Diffuse Map" true
if tex.isValid() then
(
append sea.maps tex
append tech #(
tex.diffuseType(),
#(tex.type(),tex)
)
)
)
return sea
)
fn compileVRayLightMaterial mat =
(
local sea = SEAMaterial mat
local opacity = mat.refraction.value
local mult = mat.multiplier * 255
if mult > 255 do mult = 255
sea.twoSided = mat.twoSided
local tech = sea.tech
append tech #(
MAT_DEFAULT,
#(DT_COLOR, (color mult mult mult)),
#(DT_COLOR, mat.color),
#(DT_COLOR, mat.reflection),
#(DT_FLOAT, 0.0),-- specular level
#(DT_FLOAT, 10)
)
if (seaconfig_texture and mat.texmap_on and texmap != undefined) then
(
local tex = appendTexture mat.texmap mat.name "Diffuse Map" true
if tex.isValid() then
(
append sea.maps tex
append tech #(
tex.diffuseType(),
#(tex.type(),tex)
)
)
)
return sea
)
fn compileMaterial mat names mats =
(
if mat == undefined do return undefined
local matat = (findItem names mat.name)
if (matat > 0) do
(
if (isValidInstancing()) == false or mats[matat].obj != mat then
(
if seaconfig_auto_rename then
(
mat.name = getValidName mat.name names
)
else
(
error1002 mat.name
return undefined
)
)
else
(
return mats[matat]
)
)
local sea = undefined
if classof mat