/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ /************************************************** OpenSpace 3D Editor Type converter Author: Bastien BOURINEAU / I-maginer Last update: 11.16.2010 **************************************************/ typeof mainChn = Chn;; fun InitMainChannel()= set mainChn = _channel;; /* ********************************************************************************************* / Os type converter / ********************************************************************************************* */ var iTypeVal = 0;; var iTypeScene = 1;; var iTypeNode = 2;; var iTypeLight = 4;; var iTypeCamera = 8;; var iTypeEntity = 16;; var iTypeMaterial = 32;; var iTypeAnim = 64;; var iTypeSkeleton = 128;; var iTypeGroup = 256;; var iTypeSkyDome = 512;; var iTypeSkyBox = 1024;; var iTypeSkyPlane = 2048;; var iTypeCompositor = 4096;; var iTypeBone = 8192;; var iTypeParticle = 16384;; var iTypeFile = 32768;; var iTypeCubeMap = 65536;; var iTypeReflectionMap = 131072;; var iTypeCinematics = 262144;; var lOS3DTypesName = [0 "value"]:: [1 "scene"]:: [2 "node"]:: [4 "light"]:: [8 "camera"]:: [16 "mesh"]:: [32 "material"]:: [64 "anim"]:: [128 "skeleton"]:: [256 "group"]:: [512 "skyDome"]:: [1024 "skyBox"]:: [2048 "skyPlane"]:: [4096 "compositor"]:: [8192 "bone"]:: [16384 "particle"]:: [32768 "file"]:: [65536 "cubeMap"]:: [131072 "reflectionMap"]:: [262144 "cinematics"]:: nil;; var lOS3DNamesType = ["value" 0]:: ["scene" 1]:: ["node" 2]:: ["light" 4]:: ["camera" 8]:: ["mesh" 16]:: ["material" 32]:: ["anim" 64]:: ["skeleton" 128]:: ["group" 256]:: ["skyDome" 512]:: ["skyBox" 1024]:: ["skyPlane" 2048]:: ["compositor" 4096]:: ["bone" 8192]:: ["particle" 16384]:: ["file" 32768]:: ["cubeMap" 65536]:: ["reflectionMap" 131072]:: ["cinematics" 262144]:: nil;; /*! \brief Retrieve the resource type by name * * Prototype: fun [S] I * * \param S : then resource type name * * \return I : the resource type flag **/ fun getOS3DResourceTypeByName(name)= switchstr lOS3DNamesType name;; /*! \brief Retrieve the resource name by type * * Prototype: fun [I] S * * \param I : then resource type flag * * \return S : the resource type name **/ fun getOS3DResourceNameByType(type)= switch lOS3DTypesName type;; fun getOgreFogType(stype)= if !strcmpi stype "linear" then SO3_FOG_LINEAR else if !strcmpi stype "exp" then SO3_FOG_EXP else if !strcmpi stype "exp2" then SO3_FOG_EXP2 else SO3_FOG_NONE;; fun getOgreFogByType(type)= if type == SO3_FOG_LINEAR then "linear" else if type == SO3_FOG_EXP then "exp" else if type == SO3_FOG_EXP2 then "exp2" else "none";; fun getOgreAnimationInterpolationType(stype)= if !strcmpi stype "linear" then SO3_IM_LINEAR else if !strcmpi stype "spline" then SO3_IM_SPLINE else SO3_IM_LINEAR;; fun getOgreAnimationInterpolationByType(type)= if type == SO3_IM_LINEAR then "linear" else if type == SO3_IM_SPLINE then "spline" else "linear";; fun getOgreAnimationRotInterpolationType(stype)= if !strcmpi stype "linear" then SO3_RIM_LINEAR else if !strcmpi stype "spherical" then SO3_RIM_SPHERICAL else SO3_RIM_LINEAR;; fun getOgreAnimationRotInterpolationByType(type)= if type == SO3_RIM_LINEAR then "linear" else if type == SO3_RIM_SPHERICAL then "spherical" else "linear";; fun getOgreMaxLightType(stype)= if !strcmpi stype "point" then SO3_POINT_LIGHT else if !strcmpi stype "directional" then SO3_DIRECTIONAL_LIGHT else if !strcmpi stype "spot" then SO3_SPOT_LIGHT else if !strcmpi stype "rect" then SO3_RECT_LIGHT else SO3_POINT_LIGHT;; fun getOgreMaxLightByType(type)= if type == SO3_POINT_LIGHT then "point" else if type == SO3_DIRECTIONAL_LIGHT then "directional" else if type == SO3_SPOT_LIGHT then "spot" else if type == SO3_RECT_LIGHT then "rect" else "point";; fun getOgreMaxCameraShadowType(stype)= if !strcmpi stype "planeOptimal" then SO3_PLANE_SHADOW_CAMERA else if !strcmpi stype "uniformFocused" then SO3_FOCUSED_SHADOW_CAMERA else if !strcmpi stype "uniform" then SO3_DEFAULT_SHADOW_CAMERA else if !strcmpi stype "LiSPSM" then SO3_LISPSM_SHADOW_CAMERA else SO3_DEFAULT_SHADOW_CAMERA;; fun getOgreMaxCameraShadowByType(type)= if type == SO3_PLANE_SHADOW_CAMERA then "planeOptimal" else if type == SO3_FOCUSED_SHADOW_CAMERA then "uniformFocused" else if type == SO3_DEFAULT_SHADOW_CAMERA then "uniform" else if type == SO3_LISPSM_SHADOW_CAMERA then "LiSPSM" else "uniform";; fun getOgreMaxShadowMethod(stype)= if !strcmpi stype "textureModulative" then SO3_SHADOWTYPE_TEXTURE_MODULATIVE else if !strcmpi stype "textureAdditive" then SO3_SHADOWTYPE_TEXTURE_ADDITIVE else if !strcmpi stype "textureAdditiveIntegrated" then SO3_SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED else if !strcmpi stype "textureModulativeIntegrated" then SO3_SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED else if !strcmpi stype "stencilModulative" then SO3_SHADOWTYPE_STENCIL_MODULATIVE else if !strcmpi stype "stencilAdditive" then SO3_SHADOWTYPE_STENCIL_ADDITIVE else SO3_SHADOWTYPE_NONE;; fun getOgreMaxShadowMethodByType(type)= if (type == SO3_SHADOWTYPE_TEXTURE_MODULATIVE) then "textureModulative" else if (type == SO3_SHADOWTYPE_TEXTURE_ADDITIVE) then "textureAdditive" else if (type == SO3_SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED) then "textureAdditiveIntegrated" else if (type == SO3_SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED) then "textureModulativeIntegrated" else if (type == SO3_SHADOWTYPE_STENCIL_MODULATIVE) then "stencilModulative" else if (type == SO3_SHADOWTYPE_STENCIL_ADDITIVE) then "stencilAdditive" else "none";; fun getOgreMaxShadowPreset(stype)= if !strcmpi stype "presetStencil" then SO3_SHADOWS_PRESET_STENCIL else if !strcmpi stype "presetLISPSM" then SO3_SHADOWS_PRESET_LISPSM else if !strcmpi stype "presetPSSM" then SO3_SHADOWS_PRESET_PSSM else if !strcmpi stype "presetCSM" then SO3_SHADOWS_PRESET_CSM else SO3_SHADOWS_PRESET_NONE;; fun getOgreMaxShadowPresetByType(type)= if (type == SO3_SHADOWS_PRESET_STENCIL) then "presetStencil" else if (type == SO3_SHADOWS_PRESET_LISPSM) then "presetLISPSM" else if (type == SO3_SHADOWS_PRESET_PSSM) then "presetPSSM" else if (type == SO3_SHADOWS_PRESET_CSM) then "presetCSM" else "none";; fun getOgreMaxShadowPresetQuality(stype)= if !strcmpi stype "presetVeryLow" then SO3_SHADOWS_QUALITY_VERYLOW else if !strcmpi stype "presetLow" then SO3_SHADOWS_QUALITY_LOW else if !strcmpi stype "presetMedium" then SO3_SHADOWS_QUALITY_MEDIUM else if !strcmpi stype "presetHigh" then SO3_SHADOWS_QUALITY_HIGH else if !strcmpi stype "presetVeryHigh" then SO3_SHADOWS_QUALITY_VERYHIGH else SO3_SHADOWS_QUALITY_MEDIUM;; fun getOgreMaxShadowPresetQualityByType(type)= if (type == SO3_SHADOWS_QUALITY_VERYLOW) then "presetVeryLow" else if (type == SO3_SHADOWS_QUALITY_LOW) then "presetLow" else if (type == SO3_SHADOWS_QUALITY_MEDIUM) then "presetMedium" else if (type == SO3_SHADOWS_QUALITY_HIGH) then "presetHigh" else if (type == SO3_SHADOWS_QUALITY_VERYHIGH) then "presetVeryHigh" else "presetMedium";; fun getOgreMaxShadowPresetMode(stype)= if !strcmpi stype "presetAdditive" then SO3_ADDITIVE_SHADOWS_PRESET_TECHNIQUE else if !strcmpi stype "presetModulative" then SO3_MODULATIVE_SHADOWS_PRESET_TECHNIQUE else SO3_MODULATIVE_SHADOWS_PRESET_TECHNIQUE;; fun getOgreMaxShadowPresetModeByType(type)= if (type == SO3_ADDITIVE_SHADOWS_PRESET_TECHNIQUE) then "presetAdditive" else if (type == SO3_MODULATIVE_SHADOWS_PRESET_TECHNIQUE) then "presetModulative" else "presetModulative";; fun getResourceTypeByName(name)= if !strcmpi name "mesh" then SO3_RESOURCE_MESH else if !strcmpi name "material" then SO3_RESOURCE_MATERIAL else if !strcmpi name "compositor" then SO3_RESOURCE_COMPOSITOR else if !strcmpi name "particle" then SO3_RESOURCE_PARTICLE_SYSTEM else if !strcmpi name "texture" then SO3_RESOURCE_TEXTURE else if !strcmpi name "skeleton" then SO3_RESOURCE_SKELETON else if !strcmpi name "shader" then SO3_RESOURCE_GPUPROGRAM else if !strcmpi name "highshader" then SO3_RESOURCE_HIGHLEVELGPUPROGRAM else if !strcmpi name "zip" then -1 else nil;; fun getResourceNameByType(type)= if type == SO3_RESOURCE_MESH then "mesh" else if type == SO3_RESOURCE_MATERIAL then "material" else if type == SO3_RESOURCE_COMPOSITOR then "compositor" else if type == SO3_RESOURCE_PARTICLE_SYSTEM then "particle" else if type == SO3_RESOURCE_TEXTURE then "texture" else if type == SO3_RESOURCE_SKELETON then "skeleton" else if type == SO3_RESOURCE_GPUPROGRAM then "shader" else if type == SO3_RESOURCE_HIGHLEVELGPUPROGRAM then "highshader" else "other";; fun getFileResourceType(file)= let getFileExt file -> ext in if (!strcmpi ext "material") then SO3_RESOURCE_MATERIAL else if (!strcmpi ext "compositor") then SO3_RESOURCE_COMPOSITOR else if (!strcmpi ext "particle") then SO3_RESOURCE_PARTICLE_SYSTEM else if (!strcmpi ext "pu") then SO3_RESOURCE_PARTICLE_SYSTEM else if (!strcmpi ext "program") then SO3_RESOURCE_GPUPROGRAM else if (!strcmpi ext "cg") /*|| (!strcmpi ext "fx") || (!strcmpi ext "cgfx")*/ || (!strcmpi ext "glsles") || (!strcmpi ext "hlsl") || (!strcmpi ext "glsl") || (!strcmpi ext "frag") || (!strcmpi ext "vert") || (!strcmpi ext "source") || (!strcmpi ext "asm") then SO3_RESOURCE_HIGHLEVELGPUPROGRAM else if (!strcmpi ext "skeleton") then SO3_RESOURCE_SKELETON else if (!strcmpi ext "mesh") then SO3_RESOURCE_MESH else if (!strcmpi ext "jpg") || (!strcmpi ext "png") || (!strcmpi ext "psd") || (!strcmpi ext "tga") || (!strcmpi ext "tiff") || (!strcmpi ext "bmp") || (!strcmpi ext "dds") then SO3_RESOURCE_TEXTURE else -1 ;; fun getFormatedNumber(n)= if (n < 10) then strcat "0" (itoa n) else itoa n;; fun cbGetVarDate(mode)= let if ((mode == 1) || (mode == 4)) then 1 else 0 -> gmt in if (mode != 6) then let getCurrentDateTime gmt -> [day month year hours minutes seconds] in ( if ((mode == 0) || (mode == 1)) then ( strcatn (getFormatedNumber hours)::":"::(getFormatedNumber minutes)::":"::(getFormatedNumber seconds)::nil; ) else if (mode == 2) then ( strcatn (itoa year)::"-"::(getFormatedNumber month)::"-"::(getFormatedNumber day)::nil; ) else if (mode == 5) then ( itoa abs time; ) else ( strcatn (itoa year)::"-"::(getFormatedNumber month)::"-"::(getFormatedNumber day)::" "::(getFormatedNumber hours)::":"::(getFormatedNumber minutes)::":"::(getFormatedNumber seconds)::nil; ); ) else ctime time;; fun cbGetVarRandom()= itoa (mod rand 65535);; fun cbGetVarIP()= let hd _hostIPall -> ip in if (ip == nil) then "127.0.0.1" else ip;; fun cbGetVarLanguage()= currentLanguage;; fun cbGetVarLangCode()= locDef "LANGCODE" "en";; fun InitDefaultGlobalVar()= srand time; _DMSsetGlobalVarFun "Time" mkfun1 @cbGetVarDate 0; _DMSsetGlobalVarFun "TimeGmt" mkfun1 @cbGetVarDate 1; _DMSsetGlobalVarFun "Date" mkfun1 @cbGetVarDate 2; _DMSsetGlobalVarFun "DateTime" mkfun1 @cbGetVarDate 3; _DMSsetGlobalVarFun "DateTimeGmt" mkfun1 @cbGetVarDate 4; _DMSsetGlobalVarFun "TimeStamp" mkfun1 @cbGetVarDate 5; _DMSsetGlobalVarFun "DateString" mkfun1 @cbGetVarDate 6; _DMSsetGlobalVarFun "Language" @cbGetVarLanguage; _DMSsetGlobalVarFun "Lang" @cbGetVarLangCode; _DMSsetGlobalVarFun "Random" @cbGetVarRandom; _DMSsetGlobalVarFun "IP" @cbGetVarIP; 0;;