/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ //TODO diff texture alpha rejection //check material name on new to be sure there is no doublon // PBS material // Lightmap / ambient check box, lightmap * diff // roughtness texture / specular ? var SMAT_EDITOR_HELP_URL = "http://www.openspace3d.com/documentation/en/materialeditor.html";; struct MatTextureControl = [ MTC_baseBmp : ObjBitmap, MTC_buffBmp : ObjBitmap, MTC_ctrlPicture : EdControl, MTC_ctrlFile : EdControl, MTC_ctrlFillColor : EdControl, MTC_ctrlInvert : EdControl, MTC_ctrlBrightness : EdControl, MTC_ctrlContrast : EdControl, MTC_ctrlBlur : EdControl, MTC_ctrlNormalBlur : EdControl, MTC_ctrlNormalStrength : EdControl, MTC_ctrlNormalLevel : EdControl, MTC_iDropRect : [I I I I], MTC_iFlags : I, MTC_iUser : I, MTC_bState : I ]mkMatTextureControl;; var iMTCfilePath = 1;; var iMTCfillColor = 2;; var iMTCnormal = 4;; var iMTCinvert = 8;; var iMTCbright = 16;; var iMTCblur = 32;; var iMTCgray = 64;; var iMTCcompR = 128;; var iMTCcompG = 256;; var iMTCcompB = 512;; var iMTCcompA = 1024;; typeof winMaterialEditor = [EdWindow SO3_MATERIAL V3Dsession [EdWindow EdToolBar CompRollOver EdToolBar CompCheck CompCheck CompCheck EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl EdControl]];; typeof winOrmEditor = [EdWindow Group S MatTextureControl MatTextureControl MatTextureControl];; typeof winNormalEditor = [EdWindow Group S MatTextureControl MatTextureControl MatTextureControl EdControl I];; typeof lModifiedMaterialList = [[SO3_MATERIAL [P Group]] r1];; typeof lMaterialScriptsList = [S r1];; proto assignMaterialToObj = fun [SO3_MATERIAL] I;; typeof mMaterialSphere = SO3_OBJECT;; typeof mMaterialCube = SO3_OBJECT;; typeof mMaterialCylinder = SO3_OBJECT;; typeof mMaterialplane = SO3_OBJECT;; var iMaterialModeState = 1;; fun addModifiedMaterial(mat, npath, groupstr)= let SO3MaterialGetScriptPath mat -> path in let if (path == nil) then npath else path -> path in let switch lModifiedMaterialList mat -> regpath in if (regpath != nil) then nil else ( //addLogMessage strcat "Mat path : " _PtoScol path; set lModifiedMaterialList = [mat [path groupstr]]::lModifiedMaterialList; ); 0;; fun isMaterialScriptModified(path)= let 0 -> found in ( let 0 -> i in let sizelist lModifiedMaterialList -> lsize in while (i < lsize && !found) do ( let nth_list lModifiedMaterialList i -> [mat [pfile groupstr]] in let _PtoScol pfile -> fpath in if (!strcmpi fpath path) then set found = 1 else nil; set i = i + 1; ); found; );; fun removeMatFromList(l, mat)= if l==nil then nil else let hd l -> [regmat _] in if regmat == mat then tl l else (hd l)::removeMatFromList tl l mat;; fun removeModifiedMaterial(mat)= set lModifiedMaterialList = removeMatFromList lModifiedMaterialList mat; 0;; /* Mat Texture control */ fun getMaxTextureSize8(bmp8, w, h)= if (bmp8 == nil) then nil else let _GETbitmap8Size bmp8 -> [bw bh] in ( set w = max w bw; set h = max h bh; ); [w h];; fun getMaxSizedBmp8(bmp8, w, h)= let _GETbitmap8Size bmp8 -> [bw bh] in if ((bw == w) && (bh == h)) then bmp8 else ( let _BTCPbitmapRect8 (_CRbitmap8 _channel w h) [0 0 w h] bmp8 [0 0 bw bh] -> nbmp8 in ( _DSbitmap8 bmp8; nbmp8; ); );; fun getMaxSizedBmp(bmp, w, h)= let _GETbitmapSize bmp -> [bw bh] in if ((bw == w) && (bh == h)) then bmp else ( let _BTCPbitmapRect (_CRbitmap _channel w h) [0 0 w h] bmp [0 0 bw bh] -> nbmp in ( _DSbitmap bmp; nbmp; ); );; fun getMaxTextureSize(bmp, w, h)= if (bmp == nil) then nil else let _GETbitmapSize bmp -> [bw bh] in ( set w = max w bw; set h = max h bh; ); [w h];; fun resetMtcValues(mtcstr)= setEdCtrlCheckState mtcstr.MTC_ctrlInvert 0; setEdCtrlSliderValue mtcstr.MTC_ctrlBrightness 0.0; setEdCtrlSliderValue mtcstr.MTC_ctrlContrast 1.0; setEdCtrlSliderValue mtcstr.MTC_ctrlBlur 0.0; setEdCtrlSliderValue mtcstr.MTC_ctrlNormalBlur 0.0; setEdCtrlSliderValue mtcstr.MTC_ctrlNormalStrength 2.5; setEdCtrlSliderValue mtcstr.MTC_ctrlNormalLevel 7.0; 0;; fun isMtcInRect(mtcstr, x, y)= let mtcstr.MTC_iDropRect -> [ox oy ow oh] in if ((x >= ox) && (x <= (ox + ow)) && (y >= oy) && (y <= (oy + oh))) then 1 else 0;; fun updateMTC(mtcstr)= let getEdCtrlSliderValue mtcstr.MTC_ctrlBrightness -> brightness in let getEdCtrlSliderValue mtcstr.MTC_ctrlContrast -> contrast in let getEdCtrlSliderValue mtcstr.MTC_ctrlBlur -> blur in let getEdCtrlCheckState mtcstr.MTC_ctrlInvert -> invert in let getEdCtrlSliderValue mtcstr.MTC_ctrlNormalStrength -> nstrength in let getEdCtrlSliderValue mtcstr.MTC_ctrlNormalLevel -> nlevel in let getEdCtrlSliderValue mtcstr.MTC_ctrlNormalBlur -> nblur in let _GETbitmapSize mtcstr.MTC_baseBmp -> [bw bh] in let _BTCPbitmapRect (_CRbitmap _channel bw bh) [0 0 bw bh] mtcstr.MTC_baseBmp [0 0 bw bh] -> nbmp in ( _DSbitmap mtcstr.MTC_buffBmp; if (!mtcstr.MTC_bState) then nil else ( if (!(mtcstr.MTC_iFlags & iMTCinvert) || (!invert)) then nil else _BTINVERTbitmap nbmp; if (!(mtcstr.MTC_iFlags & iMTCbright) || ((brightness == 0.0) && (contrast == 1.0))) then nil else _BTBRIGHTNESSbitmap nbmp contrast brightness; if (!(mtcstr.MTC_iFlags & iMTCblur) || (blur == 0.0)) then nil else let _GETbitmapSize nbmp -> [kw kh] in let ftoi (((itof (max kw kh)) /. 256.0 *. 5.0) *. blur) -> k in _BTBLURbitmap nbmp k k; if !(mtcstr.MTC_iFlags & iMTCnormal) then nil else _BTNORMALbitmap nbmp nstrength nlevel nblur; ); setEdCtrlBitmap2 mtcstr.MTC_ctrlPicture nbmp; set mtcstr.MTC_buffBmp = nbmp; ); 0;; fun setMtcBaseBitmap(mtcstr, bmp)= _DSbitmap mtcstr.MTC_baseBmp; let _GETbitmapSize bmp -> [bw bh] in let _BTCPbitmapRect (_CRbitmap _channel bw bh) [0 0 bw bh] bmp [0 0 bw bh] -> nbmp in ( if !((mtcstr.MTC_iFlags & iMTCgray) || (mtcstr.MTC_iFlags & iMTCcompR) || (mtcstr.MTC_iFlags & iMTCcompG) || (mtcstr.MTC_iFlags & iMTCcompB) || (mtcstr.MTC_iFlags & iMTCcompA)) then nil else _BTGRAYSCALEbitmap nbmp; set mtcstr.MTC_baseBmp = nbmp; ); resetMtcValues mtcstr; updateMTC mtcstr; 0;; //init with origin bmp fun setMtcOriginBitmap(mtcstr, abmp)= let _GETalphaBitmaps abmp -> [bmp bmp8] in let _GETbitmapSize bmp -> [bw bh] in let if !((mtcstr.MTC_iFlags & iMTCcompR) || (mtcstr.MTC_iFlags & iMTCcompG) || (mtcstr.MTC_iFlags & iMTCcompB) || (mtcstr.MTC_iFlags & iMTCcompA)) then _BTCPbitmapRect (_CRbitmap _channel bw bh) [0 0 bw bh] bmp [0 0 bw bh] else if (mtcstr.MTC_iFlags & iMTCcompA) then _SETbitmapBGR (_CRbitmap _channel bw bh) [bmp8 bmp8 bmp8] else let _GETbitmapBGR _channel bmp -> [bmpb8 bmpg8 bmpr8] in let if (mtcstr.MTC_iFlags & iMTCcompR) then bmpr8 else if (mtcstr.MTC_iFlags & iMTCcompG) then bmpg8 else bmpb8 -> nbmp8 in let _SETbitmapBGR (_CRbitmap _channel bw bh) [nbmp8 nbmp8 nbmp8] -> cbmp in ( _DSbitmap8 bmpr8; _DSbitmap8 bmpg8; _DSbitmap8 bmpb8; cbmp; ) -> nbmp in ( setMtcBaseBitmap mtcstr nbmp; _DSbitmap nbmp; ); 0;; fun updateMTCpath(mtcstr, pfile, cbfun)= let G2DloadAlphaBmpFile _channel pfile -> abmp in if (abmp == nil) then nil else ( let _PtoScol pfile -> file in if (file == nil) then nil else ( let getPathFile file "" -> [fpath fname] in setEdCtrlTextLineValue mtcstr.MTC_ctrlFile fname; ); let _GETalphaBitmaps abmp -> [bmp bmp8] in let _GETbitmapSize bmp -> [bw bh] in ( setMtcBaseBitmap mtcstr bmp; _DSalphaBitmap abmp; ); exec cbfun with [mtcstr iMTCfilePath mtcstr.MTC_iUser]; ); 0;; fun cbDlgGetMTCpath(pfile, p)= let p -> [ewinstr ctrlbtn mtcstr cbfun] in ( if pfile == nil then nil else let _PtoScol pfile -> file in if (file == nil) then ( _DLGMessageBox _channel ewinstr.EDW_win (loc "OS3D_0155") (loc "OS3D_0472") 0; 0; ) else ( set sLastDirectory = getFileDirectory file; updateMTCpath mtcstr pfile cbfun; 0; ); setEdCtrlButtonEnable ctrlbtn 1; ); 0;; fun cbMTCbtnPickFile(ctrlbtn, p)= let p -> [ewinstr mtcstr cbfun] in let sLastDirectory -> path in ( setEdCtrlButtonEnable ctrlbtn 0; let _GETdesktopSize -> [sw sh] in let getEdWindowPos mainInterf.MINT_winMain -> [nx ny] in let getEdWindowSize mainInterf.MINT_winMain -> [nmw nmh] in let [750 450] -> [iw ih] in let crEdOpenFileBitmapDialog _channel ewinstr nx + ((nmw / 2) - (iw / 2)) ny + ((nmh / 2) - (ih / 2)) iw ih (loc "OS3D_0613") ["Bitmaps" "bmp"::"jpg"::"png"::"tga"::nil]::["Bitmaps with alpha" "png"::"tga"::nil]::["All" "*.*"::nil]::nil EDFILE_DIALOG_LIST_FOLDERS|EDFILE_DIALOG_SHOW_INFOS|EDFILE_DIALOG_SHOW_TOOLBAR nil path -> dlgfstr in ( setEdWindowIcon dlgfstr.EDFD_dialog sWinDlgIcon; setEdOpenFileDialogCb dlgfstr mkfun2 @cbDlgGetMTCpath [ewinstr ctrlbtn mtcstr cbfun]; 0; ); ); 0;; fun cbMtcColor(ctrlstr, color, p)= let p -> [mtcstr cbfun] in ( _FILLbitmap mtcstr.MTC_baseBmp color; resetMtcValues mtcstr; updateMTC mtcstr; exec cbfun with [mtcstr iMTCfillColor mtcstr.MTC_iUser]; ); 0;; fun cbMtcSliderUpdate(ctrlstr, val, p)= let p -> [mtcstr cbfun] in ( updateMTC mtcstr; let if (ctrlstr == mtcstr.MTC_ctrlBlur) then iMTCblur else if (ctrlstr == mtcstr.MTC_ctrlBrightness) || (ctrlstr == mtcstr.MTC_ctrlContrast) then iMTCbright else if (ctrlstr == mtcstr.MTC_ctrlNormalBlur) || (ctrlstr == mtcstr.MTC_ctrlNormalLevel) || (ctrlstr == mtcstr.MTC_ctrlNormalStrength) then iMTCnormal else 0 -> flag in exec cbfun with [mtcstr flag mtcstr.MTC_iUser]; ); 0;; fun cbMtcCheck(ctrlstr, state, p)= let p -> [mtcstr cbfun] in ( updateMTC mtcstr; exec cbfun with [mtcstr iMTCinvert mtcstr.MTC_iUser]; ); 0;; fun setMTCstate(mtcstr, state)= set mtcstr.MTC_bState = state; 0;; fun getMTCstate(mtcstr)= mtcstr.MTC_bState;; fun crMatTextureControl(ewinstr, label, x, y, flags, abmp, user, state, cbfun)= let y -> ypos in let crEdCtrlLabel ewinstr x ypos + 2 186 20 label nil -> labelh in let crEdCtrlBitmap2 ewinstr x (set ypos = ypos + 20) 256 256 nil 0x000000 nil -> bmpctrl in let [x ypos 256 256] -> pictrect in let ypos + 256 + 10 - 25 -> ypos in let if !(flags & iMTCfilePath) then nil else crEdCtrlTextLine ewinstr x (set ypos = ypos + 25) 186 20 "" nil EDWIN_RESIZE_MW -> filectrl in let if !(flags & iMTCfilePath) then nil else crEdCtrlButton ewinstr x + 196 ypos 55 20 "..." nil -> pickbtn in let if !(flags & iMTCfillColor) then nil else crEdCtrlLabel ewinstr x ((set ypos = ypos + 25) + 2) 186 20 (loc "OS3D_0853") nil -> labelocc in let if !(flags & iMTCfillColor) then nil else crEdCtrlColorButton ewinstr x + 196 ypos 60 20 0xfffffff (-1) nil nil -> ctrlocolor in let if !(flags & iMTCnormal) then nil else crEdCtrlLabel ewinstr x (set ypos = ypos + 25) 256 20 (loc "OS3D_0857") nil -> labels in let if !(flags & iMTCnormal) then nil else crEdCtrlSlider ewinstr x (set ypos = ypos + 25) 256 20 2.5 (-.5.0) 5.0 nil EDWIN_RESIZE_MW nil -> strengthctrl in let if !(flags & iMTCnormal) then nil else crEdCtrlLabel ewinstr x (set ypos = ypos + 25) 256 20 (loc "OS3D_0858") nil -> labell in let if !(flags & iMTCnormal) then nil else crEdCtrlSlider ewinstr x (set ypos = ypos + 25) 256 20 7.0 (4.0) 10.0 nil EDWIN_RESIZE_MW nil -> levelctrl in let if !(flags & iMTCnormal) then nil else crEdCtrlLabel ewinstr x (set ypos = ypos + 25) 256 20 (loc "OS3D_0859") nil -> labelb in let if !(flags & iMTCnormal) then nil else crEdCtrlSlider ewinstr x (set ypos = ypos + 25) 256 20 0.0 (-.1.0) 1.0 nil EDWIN_RESIZE_MW nil -> nblurctrl in let if !(flags & iMTCbright) then nil else crEdCtrlLabel ewinstr x (set ypos = ypos + 25) 256 20 (loc "OS3D_0860") nil -> labell in let if !(flags & iMTCbright) then nil else crEdCtrlSlider ewinstr x (set ypos = ypos + 25) 256 20 0.0 (-.2.0) 2.0 nil EDWIN_RESIZE_MW nil -> brightctrl in let if !(flags & iMTCbright) then nil else crEdCtrlLabel ewinstr x (set ypos = ypos + 25) 256 20 (loc "OS3D_0861") nil -> labels in let if !(flags & iMTCbright) then nil else crEdCtrlSlider ewinstr x (set ypos = ypos + 25) 256 20 1.0 0.0 3.0 nil EDWIN_RESIZE_MW nil -> contctrl in let if !(flags & iMTCblur) then nil else crEdCtrlLabel ewinstr x (set ypos = ypos + 25) 256 20 (loc "OS3D_0865") nil -> labels in let if !(flags & iMTCblur) then nil else crEdCtrlSlider ewinstr x (set ypos = ypos + 25) 256 20 0.0 0.0 10.0 nil EDWIN_RESIZE_MW nil -> blurctrl in let if !(flags & iMTCinvert) then nil else crEdCtrlCheck ewinstr x (set ypos = ypos + 25) 256 20 (loc "OS3D_0862") nil -> ctrlpinvert in let mkMatTextureControl [nil nil bmpctrl filectrl ctrlocolor ctrlpinvert brightctrl contctrl blurctrl nblurctrl strengthctrl levelctrl pictrect flags user state] -> mtcstr in ( setEdCtrlButtonCb pickbtn mkfun2 @cbMTCbtnPickFile [ewinstr mtcstr cbfun]; setEdCtrlColorButtonCb ctrlocolor mkfun3 @cbMtcColor [mtcstr cbfun]; setEdCtrlSliderCbValue strengthctrl mkfun3 @cbMtcSliderUpdate [mtcstr cbfun]; setEdCtrlSliderCbValue levelctrl mkfun3 @cbMtcSliderUpdate [mtcstr cbfun]; setEdCtrlSliderCbValue nblurctrl mkfun3 @cbMtcSliderUpdate [mtcstr cbfun]; setEdCtrlSliderCbValue brightctrl mkfun3 @cbMtcSliderUpdate [mtcstr cbfun]; setEdCtrlSliderCbValue contctrl mkfun3 @cbMtcSliderUpdate [mtcstr cbfun]; setEdCtrlSliderCbValue blurctrl mkfun3 @cbMtcSliderUpdate [mtcstr cbfun]; setEdCtrlCheckCbState ctrlpinvert mkfun3 @cbMtcCheck [mtcstr cbfun]; setMtcOriginBitmap mtcstr abmp; mtcstr; );; fun destroyMTC(mtcstr)= _DSbitmap mtcstr.MTC_baseBmp; _DSbitmap mtcstr.MTC_buffBmp; 0;; /* NORMAL Editor */ fun cbDestroyNormalEditor(winstr)= let winNormalEditor -> [_ _ _ mtcheight mtcnormal mtcparallax ctrlparallax parallax] in ( destroyMTC mtcheight; destroyMTC mtcnormal; destroyMTC mtcparallax; ); set winNormalEditor = nil; 0;; fun cbApplyNormalTexture(btn)= let winMaterialEditor -> [winstr mat sessionstr ctrls] in let ctrls -> [ewinstr tbstrhelp btnassignmat tbstrmode btnmatsphere btnmatcube btnmatcylinder ctrlmatview ctrl2sided ctrltransparent ctrlreject ctrllight ctrlsolid ctrlwire ctrlpoint ctrlpointsize ctrlvcolor ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor ctrlshininess ctrlopacity ctrlambpath ctrldiffpath ctrlspecpath ctrlemitpath ctrlnmpath ctrlrefpath ctrlrefpower ctrlroughpath // ctrlrefmaskpath pickambbtn refreshambpath pickdiffbtn refreshdiffpath pickspecbtn refreshspecpath pickemitbtn refreshemitpath picknmbtn refreshnmpath pickrefbtn refreshrefpath pickroughbtn refreshroughpath createroughpath createnmpath] in //pickrefmaskbtn refreshrefmaskpath] in let winNormalEditor -> [ewinstr groupstr path mtcheight mtcnormal mtcparallax ctrlparallax parallax] in let mtcnormal.MTC_buffBmp -> nmbmp in let _GETbitmapSize nmbmp -> [bw bh] in let if (!parallax) then nil else let _GETbitmapBGR _channel mtcparallax.MTC_buffBmp -> [mb8 mg8 mr8] in let getMaxSizedBmp8 mr8 bw bh -> mr8 in ( _DSbitmap8 mg8; _DSbitmap8 mb8; mr8 ) -> bmp8 in let _CRalphaBitmap _channel nmbmp bmp8 nil nil -> normalbmp in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 (SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_ROUGHNESS) -> roughpath in let getFileNameWithoutExt path -> fname in let if (((strfindi "parallax_occlusion" fname 0) != nil) || ((strfindi "parallax_oc" fname 0) != nil) || ((strfindi "parallax" fname 0) != nil) || ((strfindi "normheight" fname 0) != nil)) then 0 else 1 -> padd in let strcat (getFilePathWithoutExt path) if (parallax == 1) then if (padd) then "_parallax_occlusion.png" else ".png" else ".jpg" -> path in let if (parallax == 1) then _BTSAVEalphaBitmap normalbmp _getmodifypack path else let _GETalphaBitmaps normalbmp -> [bmp _] in ( _SAVEjpeg bmp _getmodifypack path 90; _checkpack path; ) -> pfile in let SO3GetSceneTexture (V3DgetSession s3dMainSession) groupstr.GRP_sName path -> tex in ( _DSbitmap8 bmp8; _DSalphaBitmap normalbmp; if (tex == nil) then nil else SO3TextureDestroy tex; set tex = SO3TextureCreate (V3DgetSession s3dMainSession) path pfile groupstr.GRP_sName nil nil; SO3MaterialSetTextureByType mat tex 0 0 SO3_MAP_NORMAL; addModifiedMaterial mat nil groupstr; let getPathFile path "" -> [_ nmfile] in setEdCtrlTextLineValue ctrlnmpath nmfile; ); 0;; fun cbCancelNormalEditor(btn)= let winNormalEditor -> [ewinstr _ _ _ _ _ _ _] in ( cbDestroyNormalEditor ewinstr; dsEdWindow ewinstr; ); 0;; fun cbOkNormalEditor(btnstr)= cbApplyNormalTexture btnstr; cbCancelNormalEditor btnstr; 0;; fun cbDropNormalTexture(winstr, x, y, lp)= let hd lp -> file in let winNormalEditor -> [ewinstr groupstr path mtcheight mtcnormal mtcparallax ctrlparallax parallax] in ( if (isMtcInRect mtcheight x y) then ( setMTCstate mtcnormal 1; resetMtcValues mtcnormal; updateMTCpath mtcheight file nil; setMtcBaseBitmap mtcnormal mtcheight.MTC_buffBmp; ) else if (isMtcInRect mtcparallax x y) then ( mutate winNormalEditor <- [_ _ _ _ _ _ _ 1]; setEdCtrlCheckState ctrlparallax 1; updateMTCpath mtcparallax file nil; ) else nil; ); 0;; fun cbNormalEditorHeight(mtcstr, flag, user)= let winNormalEditor -> [ewinstr groupstr path mtcheight mtcnormal mtcparallax ctrlparallax parallax] in // if (flag == iMTCfilePath) then ( setMTCstate mtcnormal 1; setMtcBaseBitmap mtcnormal mtcheight.MTC_buffBmp; ); 0;; fun cbNormalEditorSettings(mtcstr, flag, user)= let winNormalEditor -> [ewinstr groupstr path mtcheight mtcnormal mtcparallax ctrlparallax parallax] in ( if (getMTCstate mtcnormal) then nil else ( setMTCstate mtcnormal 1; updateMTC mtcnormal; ); ); 0;; fun cbNormalEditorParallax(mtcstr, flag, user)= let winNormalEditor -> [ewinstr groupstr path mtcheight mtcnormal mtcparallax ctrlparallax parallax] in if (flag != iMTCfilePath) then nil else ( mutate winNormalEditor <- [_ _ _ _ _ _ _ 1]; setEdCtrlCheckState ctrlparallax 1; ); 0;; fun cbNormalEditorParallaxCheck(ctrlstr, state)= mutate winNormalEditor <- [_ _ _ _ _ _ _ state]; 0;; fun openNormalEditor(groupstr)= let winMaterialEditor -> [winstr mat sessionstr ctrls] in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 (SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_NORMAL) -> nmpath in let G2DloadAlphaBmpFile _channel _checkpack nmpath -> oabmp in let getFileNameWithoutExt nmpath -> fname in let getFileExt nmpath -> ext in let if (((!strcmpi ext "png") || (!strcmpi ext "tga")) && (((strfindi "parallax" fname 0) != nil) || ((strfindi "normheight" fname 0) != nil))) then 1 else 0 -> parallax in let if (nmpath == nil) then let getFileDirectory (_PtoScol SO3MaterialGetScriptPath mat) -> dir in let if (dir == nil) || (!strcmp dir "/") || (!strcmp dir "\\") || (!strcmp dir "") then let switch lModifiedMaterialList mat -> [pf _] in getFileDirectory (_PtoScol pf) else dir -> dir in let if (dir == nil) || (!strcmp dir "/") || (!strcmp dir "\\") then "" else dir -> dir in strcatn dir::(getShortName SO3MaterialGetName mat)::"_normal.jpg"::nil else nmpath -> path in let _GETalphaBitmaps oabmp -> [nmbmp nmbmp8] in let if (nmbmp == nil) then [256 256] else _GETbitmapSize nmbmp -> [bw bh] in let if (oabmp != nil) then oabmp else let _FILLbitmap (_CRbitmap _channel bw bh) 0x888888 -> nbmp in let _CRalphaBitmap _channel nbmp nil 0xffffff nil -> nabmp in ( _DSbitmap nbmp; nabmp; ) -> oabmp in ( if (winNormalEditor != nil) then let winNormalEditor -> [_ _ _ mtcheight mtcnormal mtcparallax ctrlparallax _] in ( setEdCtrlCheckState ctrlparallax parallax; mutate winNormalEditor <- [_ groupstr path _ _ _ _ parallax]; setMTCstate mtcnormal 0; setMtcOriginBitmap mtcheight oabmp; setMtcOriginBitmap mtcnormal oabmp; setMtcOriginBitmap mtcparallax oabmp; _DSalphaBitmap oabmp; 0; ) else ( let _GETdesktopSize -> [sw sh] in let _GETscreenPos -> [mx my] in let [808 580] -> [iw ih] in let iw - 20 -> wiw in let [(if ((mx + iw) > sw) then (sw - iw) else mx) (if ((my + ih) > sh) then (sh - ih - 100) else my)] -> [x y] in let setEdWindowIcon (crEdWindow _channel winstr x y iw ih WN_MENU|WN_HIDDEN|WN_DRAGDROP nil nil (loc "OS3D_0864")) sWinDlgIcon -> ewinstr in let crMatTextureControl ewinstr (loc "OS3D_0854") 10 10 iMTCfillColor|iMTCfilePath|iMTCinvert|iMTCblur|iMTCbright|iMTCgray oabmp 1 1 @cbNormalEditorHeight -> mtcheight in let crMatTextureControl ewinstr (loc "OS3D_0855") 276 10 iMTCnormal oabmp 2 0 @cbNormalEditorSettings -> mtcnormal in let crMatTextureControl ewinstr (loc "OS3D_0856") 542 10 iMTCfillColor|iMTCfilePath|iMTCinvert|iMTCblur|iMTCbright|iMTCcompA oabmp 3 1 @cbNormalEditorParallax -> mtcparallax in let crEdCtrlCheck ewinstr 542 521 256 20 (loc "OS3D_0863") nil -> ctrlparallax in let crEdCtrlButton ewinstr ((iw / 2) - 145) (ih - 30) 90 20 (loc "OS3D_0282") EDWIN_RESIZE_RH|EDWIN_RESIZE_LW -> okbtn in let crEdCtrlButton ewinstr ((iw / 2) - 45) (ih - 30) 90 20 (loc "OS3D_0051") EDWIN_RESIZE_RH|EDWIN_RESIZE_LW -> applybtn in let crEdCtrlButton ewinstr ((iw / 2) + 55) (ih - 30) 90 20 (loc "OS3D_0084") EDWIN_RESIZE_RH|EDWIN_RESIZE_LW -> cancelbtn in ( setEdCtrlButtonCb okbtn @cbOkNormalEditor; setEdCtrlButtonCb applybtn @cbApplyNormalTexture; setEdCtrlButtonCb cancelbtn @cbCancelNormalEditor; setEdCtrlCheckState ctrlparallax parallax; setEdCtrlCheckCbState ctrlparallax @cbNormalEditorParallaxCheck; setEdwindowCbDrop ewinstr @cbDropNormalTexture; set winNormalEditor = [ewinstr groupstr path mtcheight mtcnormal mtcparallax ctrlparallax parallax]; setEdwindowCbDestroy ewinstr @cbDestroyNormalEditor; _DSalphaBitmap oabmp; setEdWindowVisible ewinstr 1; ); 0; ); ); 0;; /* ORM Editor */ fun cbDestroyOrmEditor(winstr)= let winOrmEditor -> [ewinstr groupstr path occmtcstr roughmtcstr metalmtcstr] in ( destroyMTC occmtcstr; destroyMTC roughmtcstr; destroyMTC metalmtcstr; ); set winOrmEditor = nil; 0;; fun cbApplyOrmTexture(btn)= let winMaterialEditor -> [winstr mat sessionstr ctrls] in let ctrls -> [ewinstr tbstrhelp btnassignmat tbstrmode btnmatsphere btnmatcube btnmatcylinder ctrlmatview ctrl2sided ctrltransparent ctrlreject ctrllight ctrlsolid ctrlwire ctrlpoint ctrlpointsize ctrlvcolor ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor ctrlshininess ctrlopacity ctrlambpath ctrldiffpath ctrlspecpath ctrlemitpath ctrlnmpath ctrlrefpath ctrlrefpower ctrlroughpath // ctrlrefmaskpath pickambbtn refreshambpath pickdiffbtn refreshdiffpath pickspecbtn refreshspecpath pickemitbtn refreshemitpath picknmbtn refreshnmpath pickrefbtn refreshrefpath pickroughbtn refreshroughpath createroughpath createnmpath] in //pickrefmaskbtn refreshrefmaskpath] in let winOrmEditor -> [ewinstr groupstr path occmtcstr roughmtcstr metalmtcstr] in let _GETbitmapBGR _channel occmtcstr.MTC_buffBmp -> [ob8 og8 or8] in let _GETbitmapBGR _channel roughmtcstr.MTC_buffBmp -> [rb8 rg8 rr8] in let _GETbitmapBGR _channel metalmtcstr.MTC_buffBmp -> [mb8 mg8 mr8] in let getMaxTextureSize8 ob8 256 256 -> [w h] in let getMaxTextureSize8 rb8 256 256 -> [w h] in let getMaxTextureSize8 mb8 256 256 -> [w h] in let getMaxSizedBmp8 ob8 w h -> ob8 in let getMaxSizedBmp8 rb8 w h -> rb8 in let getMaxSizedBmp8 mb8 w h -> mb8 in let _SETbitmapBGR (_CRbitmap _channel w h) [mb8 rb8 ob8] -> ormbmp in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 (SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_ROUGHNESS) -> roughpath in //let _BTSAVEbitmap ormbmp _getmodifypack path -> pfile in let _SAVEjpeg ormbmp _getmodifypack path 90 -> sret in let _checkpack path -> pfile in let SO3GetSceneTexture (V3DgetSession s3dMainSession) groupstr.GRP_sName path -> tex in ( _DSbitmap8 ob8; _DSbitmap8 og8; _DSbitmap8 or8; _DSbitmap8 rb8; _DSbitmap8 rg8; _DSbitmap8 rr8; _DSbitmap8 mb8; _DSbitmap8 mg8; _DSbitmap8 mr8; _DSbitmap ormbmp; if (tex == nil) then nil else SO3TextureDestroy tex; set tex = SO3TextureCreate (V3DgetSession s3dMainSession) path pfile groupstr.GRP_sName nil nil; SO3MaterialSetTextureByType mat tex 0 0 SO3_MAP_ROUGHNESS; addModifiedMaterial mat nil groupstr; let getPathFile path "" -> [_ roughfile] in setEdCtrlTextLineValue ctrlroughpath roughfile; ); 0;; fun cbCancelOrmTexture(btn)= let winOrmEditor -> [ewinstr _ _ _ _ _] in ( cbDestroyOrmEditor ewinstr; dsEdWindow ewinstr; ); 0;; fun cbOkOrmTexture(btnstr)= cbApplyOrmTexture btnstr; cbCancelOrmTexture btnstr; 0;; fun cbDropOrmTexture(winstr, x, y, lp)= let hd lp -> file in let winOrmEditor -> [ewinstr groupstr path occmtcstr roughmtcstr metalmtcstr] in ( if (isMtcInRect occmtcstr x y) then ( updateMTCpath occmtcstr file nil; ) else if (isMtcInRect roughmtcstr x y) then ( updateMTCpath roughmtcstr file nil; ) else if (isMtcInRect metalmtcstr x y) then ( updateMTCpath metalmtcstr file nil; ) else nil; ); 0;; // Occlusion Roughness Metalness texture fun openOrmEditor(groupstr)= let winMaterialEditor -> [winstr mat sessionstr ctrls] in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 (SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_ROUGHNESS) -> roughpath in let G2DloadAlphaBmpFile _channel _checkpack roughpath -> oabmp in let if (roughpath == nil) then let getFileDirectory (_PtoScol SO3MaterialGetScriptPath mat) -> dir in let if (dir == nil) || (!strcmp dir "/") || (!strcmp dir "\\") || (!strcmp dir "") then let switch lModifiedMaterialList mat -> [pf _] in getFileDirectory (_PtoScol pf) else dir -> dir in let if (dir == nil) || (!strcmp dir "/") || (!strcmp dir "\\") then "" else dir -> dir in strcatn dir::(getShortName SO3MaterialGetName mat)::"_orm.jpg"::nil else roughpath -> path in let _GETalphaBitmaps oabmp -> [ormbmp _] in let if (ormbmp == nil) then [256 256] else _GETbitmapSize ormbmp -> [bw bh] in let if (oabmp != nil) then oabmp else let [(_FILLbitmap8 (_CRbitmap8 _channel bw bh) 0) (_FILLbitmap8 (_CRbitmap8 _channel bw bh) 0) (_FILLbitmap8 (_CRbitmap8 _channel bw bh) 255)] -> [bbmp8 gbmp8 rbmp8] in let _SETbitmapBGR (_CRbitmap _channel bw bh) [bbmp8 gbmp8 rbmp8] -> nbmp in let _CRalphaBitmap _channel nbmp nil 0xffffff nil -> nabmp in ( _DSbitmap8 bbmp8; _DSbitmap8 gbmp8; _DSbitmap8 rbmp8; _DSbitmap nbmp; nabmp; ) -> oabmp in ( if (winOrmEditor != nil) then ( let winOrmEditor -> [_ groupstr _ occmtcstr roughmtcstr metalmtcstr] in ( mutate winOrmEditor <- [_ groupstr path _ _ _]; setMtcOriginBitmap occmtcstr oabmp; setMtcOriginBitmap roughmtcstr oabmp; setMtcOriginBitmap metalmtcstr oabmp; _DSalphaBitmap oabmp; ); 0; ) else ( let _GETdesktopSize -> [sw sh] in let _GETscreenPos -> [mx my] in let [808 560] -> [iw ih] in let [(if ((mx + iw) > sw) then (sw - iw) else mx) (if ((my + ih) > sh) then (sh - ih - 100) else my)] -> [x y] in let setEdWindowIcon (crEdWindow _channel winstr x y iw ih WN_MENU|WN_HIDDEN|WN_DRAGDROP nil nil (loc "OS3D_0849")) sWinDlgIcon -> ewinstr in let crMatTextureControl ewinstr (loc "OS3D_0850") 10 10 iMTCfillColor|iMTCfilePath|iMTCinvert|iMTCblur|iMTCbright|iMTCcompR oabmp nil 1 nil -> occmtcstr in let crMatTextureControl ewinstr (loc "OS3D_0851") 276 10 iMTCfillColor|iMTCfilePath|iMTCinvert|iMTCblur|iMTCbright|iMTCcompG oabmp nil 1 nil -> roughmtcstr in let crMatTextureControl ewinstr (loc "OS3D_0852") 542 10 iMTCfillColor|iMTCfilePath|iMTCinvert|iMTCblur|iMTCbright|iMTCcompB oabmp nil 1 nil -> metalmtcstr in let crEdCtrlButton ewinstr ((iw / 2) - 145) (ih - 30) 90 20 (loc "OS3D_0282") EDWIN_RESIZE_RH|EDWIN_RESIZE_LW -> okbtn in let crEdCtrlButton ewinstr ((iw / 2) - 45) (ih - 30) 90 20 (loc "OS3D_0051") EDWIN_RESIZE_RH|EDWIN_RESIZE_LW -> applybtn in let crEdCtrlButton ewinstr ((iw / 2) + 55) (ih - 30) 90 20 (loc "OS3D_0084") EDWIN_RESIZE_RH|EDWIN_RESIZE_LW -> cancelbtn in ( setEdCtrlButtonCb okbtn @cbOkOrmTexture; setEdCtrlButtonCb applybtn @cbApplyOrmTexture; setEdCtrlButtonCb cancelbtn @cbCancelOrmTexture; setEdwindowCbDrop ewinstr @cbDropOrmTexture; set winOrmEditor = [ewinstr groupstr path occmtcstr roughmtcstr metalmtcstr]; setEdwindowCbDestroy ewinstr @cbDestroyOrmEditor; _DSalphaBitmap oabmp; setEdWindowVisible ewinstr 1; ); 0; ); ); 0;; fun cbTbBtnAssignMaterialEditor(tbstr, cmproll, btn, mask, mat)= assignMaterialToObj mat; 0;; fun cbTbBtnMaterialMode(tbstr, cmpcheck, btn, mask, state, mode)= let winMaterialEditor -> [winstr mat sessionstr ctrls] in let ctrls -> [ewinstr tbstrhelp btnassignmat tbstrmode btnmatsphere btnmatcube btnmatcylinder ctrlmatview ctrl2sided ctrltransparent ctrlreject ctrllight ctrlsolid ctrlwire ctrlpoint ctrlpointsize ctrlvcolor ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor ctrlshininess ctrlopacity ctrlambpath ctrldiffpath ctrlspecpath ctrlemitpath ctrlnmpath ctrlrefpath ctrlrefpower ctrlroughpath // ctrlrefmaskpath pickambbtn refreshambpath pickdiffbtn refreshdiffpath pickspecbtn refreshspecpath pickemitbtn refreshemitpath picknmbtn refreshnmpath pickrefbtn refreshrefpath pickroughbtn refreshroughpath createroughpath createnmpath] in //pickrefmaskbtn refreshrefmaskpath] in ( set iMaterialModeState = mode; if (iMaterialModeState == 2) then ( SO3ObjectSetVisible mMaterialSphere 0 0; SO3ObjectSetVisible mMaterialCube 1 0; SO3ObjectSetVisible mMaterialCylinder 0 0; setEdToolBarCheckState tbstr btnmatsphere 0; setEdToolBarCheckState tbstr btnmatcube 1; setEdToolBarCheckState tbstr btnmatcylinder 0; ) else if (iMaterialModeState == 3) then ( SO3ObjectSetVisible mMaterialSphere 0 0; SO3ObjectSetVisible mMaterialCube 0 0; SO3ObjectSetVisible mMaterialCylinder 1 0; setEdToolBarCheckState tbstr btnmatsphere 0; setEdToolBarCheckState tbstr btnmatcube 0; setEdToolBarCheckState tbstr btnmatcylinder 1; ) else ( SO3ObjectSetVisible mMaterialSphere 1 0; SO3ObjectSetVisible mMaterialCube 0 0; SO3ObjectSetVisible mMaterialCylinder 0 0; setEdToolBarCheckState tbstr btnmatsphere 1; setEdToolBarCheckState tbstr btnmatcube 0; setEdToolBarCheckState tbstr btnmatcylinder 0; ); ); 0;; fun cbTbBtnMaterialEditorgHelp(tbstr, check, btn, mask)= _openbrowserhttp SMAT_EDITOR_HELP_URL; 0;; fun replaceTextureInMatRec(l, d, src, dest, opts)= if (l == nil) then d else ( let l -> [elt next] in if ((strfind src elt 1) == nil) then replaceTextureInMatRec tl l (lcat d elt::nil) src dest opts else replaceTextureInMatRec tl l (lcat d (lcat dest::nil opts)) src dest opts; );; fun replaceTextureInMat(buff, src, dest, opts)= let lineextr buff -> ln in listToString replaceTextureInMatRec ln nil src dest opts;; //list all script materials //list all 2D textures units in materials and make them unique //calc the final texture size //fill the atlas texture with bitmaps and replace associated texture unit with scale and scroll //save new material file fun makeMaterialAtlas(matfile, texsize)= //Get 2D textures list let nil -> ltex in let getPathFile matfile nil -> [matdir matscript] in let strcatn matdir::(getFilePathWithoutExt matscript)::"_atlas.png"::nil -> destbmpname in let strcatn matdir::(getFilePathWithoutExt matscript)::"_atlas.material"::nil -> destscriptname in let _checkpack matfile -> pfile in if (pfile == nil) then nil else ( let strToListOpenCloseSep (_getpack pfile) "texture_unit " "}" -> lunit in while (lunit != nil) do ( let hd lunit -> unit in if ((strfind "env_map" unit 0) != nil) then nil else ( let strextr unit -> lcont in while (lcont != nil) do ( let hd lcont -> line in let strtrim (hd line) -> fword in ( if (!strcmpi "texture" fword) then ( if (isLastWordfromString "cubic" fword) || (isLastWordfromString "cubic_texture" fword) then nil else if (_checkpack strtrim(hd tl line)) != nil then set ltex = addUniqueStr ltex (strtrim (hd tl line)); ) else nil; ); set lcont = tl lcont; ); ); set lunit = tl lunit; ); //create the atlas alphabitmap let _getpack pfile -> smat in let (sqrt (itof (sizelist ltex))) -> resqrt in let if (resqrt -. (itof (ftoi resqrt))) >. 0.0 then resqrt +. 1.0 else resqrt -> resqrt in let (ftoi resqrt) * texsize -> bw in let _FILLbitmap _CRbitmap _channel bw bw 0xffffff -> bmp24 in let _FILLbitmap8 _CRbitmap8 _channel bw bw 0x00 -> bmp8 in let _CRalphaBitmap _channel bmp24 bmp8 nil nil -> abmp in ( _DSbitmap bmp24; _DSbitmap8 bmp8; let 0 -> xp in let 0 -> yp in let bw / texsize -> nbx in while (ltex != nil) do ( let hd ltex -> texpath in let G2DloadAlphaBmp _channel texpath -> oabmp in let _GETalphaBitmapSize oabmp -> [ow oh] in ( _BTCPalphaBitmapRect abmp [(xp * texsize) (yp * texsize) texsize texsize] oabmp [0 0 ow oh]; _DSalphaBitmap oabmp; let (1.0 /. (itof nbx)) -> coef in let 0.5 -. (1.0 /. (2.0 *. (itof nbx))) -> offw in let coef *. (itof xp) -. offw -> offx in let coef *. (itof yp) -. offw -> offy in set smat = replaceTextureInMat smat (strcat "texture " texpath) (strcat " texture " destbmpname) (strcatn " scale "::(itoa nbx)::" "::(itoa nbx)::nil)::(strcatn " scroll "::(ftoa offx)::" "::(ftoa offy)::nil)::nil; ); if (xp < (nbx - 1)) then set xp = xp + 1 else ( set xp = 0; set yp = yp + 1; ); set ltex = tl ltex; ); _BTSAVEalphaBitmap abmp (_getmodifypack destbmpname); _DSalphaBitmap abmp; _storepack smat destscriptname; ); ); 0;; fun cbTbBtnSaveMaterial(tbstr, check, btn, mask, mat)= //TODO ask to file path if this is a new material //TODO add new resources to OS3D xml SO3MaterialExport mat nil; 0;; fun cbDestroyMaterialEditor(winstr)= set winMaterialEditor = nil; 0;; fun cbApplyViewMaterial(sessionstr, obj, p)= let p -> [groupstr mat] in SO3EntitySetMaterial obj mat nil; 0;; fun materialDestroyEditor()= let winMaterialEditor -> [winstr mat sessionstr _] in ( SO3GroupDelete (V3DgetSession sessionstr) sV3DResourcesGroup; dsEdWindow winstr; ); cbCancelOrmTexture nil; cbCancelNormalEditor nil; set winMaterialEditor = nil; 0;; fun cbMatSetPolygonMode(ctrlstr, state, p)= let p -> [mat groupstr ctrlsolid ctrlwire ctrlpoint pmode] in if (!state) then nil else ( if (pmode == SO3_POLYGONMODE_WIREFRAME) then ( setEdCtrlCheckState ctrlsolid 0; setEdCtrlCheckState ctrlwire 1; setEdCtrlCheckState ctrlpoint 0; ) else if (pmode == SO3_POLYGONMODE_POINTS) then ( setEdCtrlCheckState ctrlsolid 0; setEdCtrlCheckState ctrlwire 0; setEdCtrlCheckState ctrlpoint 1; ) else ( setEdCtrlCheckState ctrlsolid 1; setEdCtrlCheckState ctrlwire 0; setEdCtrlCheckState ctrlpoint 0; ); SO3MaterialSetPassPolygonMode mat 0 0 pmode; addModifiedMaterial mat nil groupstr; ); 0;; fun cbMatRejection(ctrlstr, state, p)= let p -> [mat groupstr] in ( if (!state) then SO3MaterialSetPassAlphaRejection mat 0 0 SO3_COMPARE_FUNCTION_ALWAYS_PASS 0 0 else SO3MaterialSetPassAlphaRejection mat 0 0 SO3_COMPARE_FUNCTION_GREATER 128 1; addModifiedMaterial mat nil groupstr; ); 0;; fun cbMatPointSize(ctrlstr, value, p)= let p -> [mat groupstr] in ( SO3MaterialSetPassPointSize mat 0 0 value; addModifiedMaterial mat nil groupstr; ); 0;; fun cbMatTransparent(ctrlstr, state, p)= let p -> [mat groupstr] in ( SO3MaterialSetPassDepthWriteEnabled mat 0 0 !state; if (state) then SO3MaterialSetPassSceneBlending mat 0 0 SO3_SCENE_BLEND_FACTOR_SOURCE_ALPHA SO3_SCENE_BLEND_FACTOR_ONE_MINUS_SOURCE_ALPHA nil nil else SO3MaterialSetPassSceneBlending mat 0 0 SO3_SCENE_BLEND_FACTOR_ONE SO3_SCENE_BLEND_FACTOR_ZERO nil nil; addModifiedMaterial mat nil groupstr; ); 0;; fun cbMatLighting(ctrlstr, state, p)= let p -> [mat groupstr ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor ctrlshininess ctrlopacity ctrlvcolor] in let getEdCtrlCheckState ctrlvcolor -> vcolor in let !(vcolor || state) -> ectrl in let !((vcolor && state) || state) -> ectrl2 in ( setEdCtrlColorButtonEnable ctrlambcolor ectrl; setEdCtrlColorButtonEnable ctrldiffcolor ectrl; setEdCtrlColorButtonEnable ctrlspeccolor ectrl2; setEdCtrlColorButtonEnable ctrlemitcolor ectrl2; setEdCtrlFloatEnable ctrlshininess ectrl2; setEdCtrlFloatEnable ctrlopacity ectrl; SO3MaterialSetPassLighting mat 0 0 !state; addModifiedMaterial mat nil groupstr; ); 0;; fun cbMatCullingMode(ctrlstr, state, p)= let p -> [mat groupstr] in ( SO3MaterialSetPassCullingEnable mat 0 0 !state; addModifiedMaterial mat nil groupstr; ); 0;; fun cbMatSetUserVertexColor(ctrlstr, state, p)= let p -> [mat groupstr ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor ctrlshininess ctrlopacity ctrllight] in let getEdCtrlCheckState ctrllight -> light in let !(light || state) -> ectrl in let !((light && state) || light) -> ectrl2 in ( setEdCtrlColorButtonEnable ctrlambcolor ectrl; setEdCtrlColorButtonEnable ctrldiffcolor ectrl; setEdCtrlColorButtonEnable ctrlspeccolor ectrl2; setEdCtrlColorButtonEnable ctrlemitcolor ectrl2; setEdCtrlFloatEnable ctrlshininess ectrl2; setEdCtrlFloatEnable ctrlopacity ectrl; SO3MaterialSetPassUseVertexColor mat 0 0 state; addModifiedMaterial mat nil groupstr; ); 0;; fun cbAmbientColor(ctrlstr, color, p)= let p -> [mat groupstr] in ( SO3MaterialSetAmbientByTechAndPass mat 0 0 color; addModifiedMaterial mat nil groupstr; ); 0;; fun cbDiffuseColor(ctrlstr, color, p)= let p -> [mat groupstr] in ( SO3MaterialSetDiffuseByTechAndPass mat 0 0 color; addModifiedMaterial mat nil groupstr; ); 0;; fun cbSpecularColor(ctrlstr, color, p)= let p -> [mat groupstr] in ( SO3MaterialSetSpecularByTechAndPass mat 0 0 color; addModifiedMaterial mat nil groupstr; ); 0;; fun cbEmissiveColor(ctrlstr, color, p)= let p -> [mat groupstr] in ( SO3MaterialSetSelfIlluminationByTechAndPass mat 0 0 color; addModifiedMaterial mat nil groupstr; ); 0;; fun cbShininess(ctrlstr, value, p)= let p -> [mat groupstr] in ( SO3MaterialSetShininessByTechAndPass mat 0 0 value; addModifiedMaterial mat nil groupstr; ); 0;; fun cbMatOpacity(ctrlstr, value, p)= let p -> [mat groupstr ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor] in let (value *. 1.27) -> falpha in let if (itof (ftoi falpha)) <. falpha then falpha +. 1.0 else falpha -> falpha in let if (falpha >. 127.0) then 127 else ftoi falpha -> alpha in ( let G2Dgetrgb G2Drgba2rgb (SO3MaterialGetAmbientByTechAndPass mat 0 0) -> [r g b] in let make_rgba r g b alpha -> ncol in ( SO3MaterialSetAmbientByTechAndPass mat 0 0 ncol; setEdCtrlColorButtonColor ctrlambcolor ncol; ); let G2Dgetrgb G2Drgba2rgb (SO3MaterialGetDiffuseByTechAndPass mat 0 0) -> [r g b] in let make_rgba r g b alpha -> ncol in ( SO3MaterialSetDiffuseByTechAndPass mat 0 0 ncol; setEdCtrlColorButtonColor ctrldiffcolor ncol; ); let G2Dgetrgb G2Drgba2rgb (SO3MaterialGetSpecularByTechAndPass mat 0 0) -> [r g b] in let make_rgba r g b alpha -> ncol in ( SO3MaterialSetSpecularByTechAndPass mat 0 0 ncol; setEdCtrlColorButtonColor ctrlspeccolor ncol; ); let G2Dgetrgb G2Drgba2rgb (SO3MaterialGetSelfIlluminationByTechAndPass mat 0 0) -> [r g b] in let make_rgba r g b alpha -> ncol in ( SO3MaterialSetSelfIlluminationByTechAndPass mat 0 0 ncol; setEdCtrlColorButtonColor ctrlemitcolor ncol; ); addModifiedMaterial mat nil groupstr; ); 0;; fun cbDlgGetTexturePath(pfile, p)= let p -> [ctrlbtn np] in let np -> [winstr ctrlpath npath mat type groupstr ctrlval] in ( if pfile == nil then nil else let _PtoScol pfile -> file in if file == nil then ( _DLGMessageBox _channel winstr.EDW_win (loc "OS3D_0155") (loc "OS3D_0472") 0; 0; ) else ( set sLastDirectory = getFileDirectory file; mutate np <- [_ _ file _ _ _ _]; let getPathFile file "" -> [fpath fname] in setEdCtrlTextLineValue ctrlpath fname; let SO3GetSceneTexture (V3DgetSession s3dMainSession) groupstr.GRP_sName file -> tex in ( if (tex != nil) then nil else set tex = SO3TextureCreate (V3DgetSession s3dMainSession) file pfile groupstr.GRP_sName nil nil; SO3MaterialSetTextureByType mat tex 0 0 type; if ((type != SO3_MAP_REFLECTION) || (ctrlval == nil)) then nil else ( let (getEdCtrlFloatValue ctrlval) /. 100.0 -> factor in let if (factor >=. 0.999) then 1.0 else factor -> factor in // precision SO3MaterialSetTextureBlendFactor mat 0 0 (SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_REFLECTION) factor; ); addModifiedMaterial mat nil groupstr; ); 0; ); setEdCtrlButtonEnable ctrlbtn 1; ); 0;; fun cbBtnPickTextureFile(ctrlbtn, p)= let p -> [winstr ctrlpath npath mat type groupstr ctrlval] in let if (npath == nil) || (!strcmp npath "") then sLastDirectory else npath -> path in ( setEdCtrlButtonEnable ctrlbtn 0; let _GETdesktopSize -> [sw sh] in let getEdWindowPos mainInterf.MINT_winMain -> [nx ny] in let getEdWindowSize mainInterf.MINT_winMain -> [nmw nmh] in let [750 450] -> [iw ih] in let crEdOpenFileBitmapDialog _channel winstr nx + ((nmw / 2) - (iw / 2)) ny + ((nmh / 2) - (ih / 2)) iw ih (loc "OS3D_0613") ["Bitmaps" "bmp"::"jpg"::"png"::"tga"::"dds"::"ktx"::nil]::["Bitmaps with alpha" "png"::"tga"::"dds"::nil]::["DDS bitmaps" "dds"::nil]::["All" "*.*"::nil]::nil EDFILE_DIALOG_LIST_FOLDERS|EDFILE_DIALOG_SHOW_INFOS|EDFILE_DIALOG_SHOW_TOOLBAR nil path -> dlgfstr in ( setEdWindowIcon dlgfstr.EDFD_dialog sWinDlgIcon; setEdOpenFileDialogCb dlgfstr mkfun2 @cbDlgGetTexturePath [ctrlbtn p]; 0; ); ); 0;; fun cbRefreshTextureBtn(ctrlbtn, p)= let p -> [ctrlpath mat type groupstr] in ( setEdCtrlTextLineValue ctrlpath ""; SO3MaterialRemoveTexture mat 0 0 (SO3MaterialTextureUnitGetIndexByType mat 0 0 type); addModifiedMaterial mat nil groupstr; ); 0;; fun cbMatRefFactor(ctrlstr, value, p)= let p -> [mat groupstr] in let value /. 100.0 -> factor in let if (factor >=. 0.999) then 1.0 else factor -> factor in // precision ( SO3MaterialSetTextureBlendFactor mat 0 0 (SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_REFLECTION) factor; addModifiedMaterial mat nil groupstr; ); 0;; fun setMatDirectionFromMouse(viewstr, sessionstr, ang)= let V3DgetLastMouseMove viewstr 0 -> [x y] in let [viewstr.V3D_iWinW viewstr.V3D_iWinH] -> [w h] in let if (x > w) then w else if (x < 0) then 0 else x -> x in let if (y > h) then h else if (y < 0) then 0 else y -> y in let V3DgetDefaultCamera sessionstr -> cam in let SO3ObjectGetGlobalOrientation cam -> camquat in let [(x - (w / 2)) (y - (h / 2))] -> [ix iy] in let [((itof ix) /. (itof (w / 2))) ((itof iy) /. (itof (h / 2)))] -> [fx fy] in let [SO3MathsDegreeToRadian (ang *. fx) SO3MathsDegreeToRadian (ang *. fy)] -> [dx dy] in let SO3MathsQuatAdd camquat [0.0 1.0 0.0 0.0] -> camquat in SO3ObjectSetGlobalOrientation (V3DgetDefaultLight sessionstr) SO3MathsQuatAdd camquat (SO3MathsEulerPYRToQuat [(-.dy) dx 0.0]); 0;; fun cbMaterialEditorPreRender(viewstr, sessionstr)= if !(viewstr.V3D_iMoveClickStatus & V3DCLICK_RIGHT) then nil else setMatDirectionFromMouse viewstr sessionstr 90.0; 0;; fun cbCreateRoughTexture(btnstr, groupstr)= openOrmEditor groupstr; 0;; fun cbCreateNormalTexture(btnstr, groupstr)= openNormalEditor groupstr; 0;; fun loadMaterialEditor(groupstr, mat)= let winMaterialEditor -> [winstr _ sessionstr ctrls] in let ctrls -> [ewinstr tbstrhelp btnassignmat tbstrmode btnmatsphere btnmatcube btnmatcylinder ctrlmatview ctrl2sided ctrltransparent ctrlreject ctrllight ctrlsolid ctrlwire ctrlpoint ctrlpointsize ctrlvcolor ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor ctrlshininess ctrlopacity ctrlambpath ctrldiffpath ctrlspecpath ctrlemitpath ctrlnmpath ctrlrefpath ctrlrefpower ctrlroughpath // ctrlrefmaskpath pickambbtn refreshambpath pickdiffbtn refreshdiffpath pickspecbtn refreshspecpath pickemitbtn refreshemitpath picknmbtn refreshnmpath pickrefbtn refreshrefpath pickroughbtn refreshroughpath createroughpath createnmpath] in //pickrefmaskbtn refreshrefmaskpath] in let SO3MaterialGetName mat -> matname in ( cbCancelOrmTexture nil; cbCancelNormalEditor nil; //reset callbacks before we change the values! setEdCtrlCheckCbState ctrlsolid nil; setEdCtrlCheckCbState ctrlwire nil; setEdCtrlCheckCbState ctrlpoint nil; setEdCtrlCheckCbState ctrl2sided nil; setEdCtrlCheckCbState ctrltransparent nil; setEdCtrlCheckCbState ctrllight nil; setEdCtrlCheckCbState ctrlreject nil; setEdCtrlFloatCbChange ctrlpointsize nil; setEdCtrlColorButtonCb ctrlambcolor nil; setEdCtrlColorButtonCb ctrldiffcolor nil; setEdCtrlColorButtonCb ctrlspeccolor nil; setEdCtrlColorButtonCb ctrlemitcolor nil; setEdCtrlFloatCbChange ctrlshininess nil; setEdCtrlFloatCbChange ctrlopacity nil; setEdCtrlFloatCbChange ctrlrefpower nil; //Get material parameters // how do I manage passes / techniques ? // schemename if tech > 0 // get technique and pass, create them if not available // set uv channels on each texture //save material in original file http://ogre3d.org/forums/viewtopic.php?f=2&t=68482 let SO3MaterialGetPassAlphaRejectionFunction mat 0 0 -> rejectfunc in let SO3MaterialGetPassAlphaRejectionValue mat 0 0 -> rejectval in let if ((rejectfunc == SO3_COMPARE_FUNCTION_GREATER) && (rejectval == 128)) then 1 else 0 -> reject in let SO3MaterialGetPassCullingEnable mat 0 0 -> culling in let SO3MaterialGetPassDepthWriteEnabled mat 0 0 -> depthwrite in let SO3MaterialGetPassLighting mat 0 0 -> lightstate in let SO3MaterialGetPassPointSize mat 0 0 -> psize in let SO3MaterialGetPassPolygonMode mat 0 0 -> pmode in let SO3MaterialGetPassUseVertexColor mat 0 0 -> usevcolor in let SO3MaterialGetAmbientByTechAndPass mat 0 0 -> ambcolor in let SO3MaterialGetDiffuseByTechAndPass mat 0 0 -> diffcolor in let SO3MaterialGetSpecularByTechAndPass mat 0 0 -> speccolor in let SO3MaterialGetShininessByTechAndPass mat 0 0 -> shininess in let SO3MaterialGetSelfIlluminationByTechAndPass mat 0 0 -> emitcolor in let itof (G2DgetAlphaFromColor diffcolor) -> alpha in let if (alpha == 127.0) then 100.0 else (alpha *. 100.0) /. 127.0 -> opacity in let if ((itof (ftoi opacity)) <. opacity) then opacity +. 1.0 else opacity -> opacity in let if (opacity >. 99.0) then 100.0 else opacity -> opacity in //precision issue let SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_AMBIENT -> ambunit in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 ambunit -> ambpath in let getPathFile ambpath "" -> [_ ambfile] in let if (ambunit != nil) && ((ambfile == nil) || (!strcmp "" ambfile)) then "Undefined" else ambfile -> ambfile in let SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_DIFFUSE -> diffunit in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 diffunit -> diffpath in let getPathFile diffpath "" -> [_ difffile] in let if (diffunit != nil) && ((difffile == nil) || (!strcmp "" difffile)) then "Undefined" else difffile -> difffile in let SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_SPECULAR -> specunit in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 specunit -> specpath in let getPathFile specpath "" -> [_ specfile] in let if (specunit != nil) && ((specfile == nil) || (!strcmp "" specfile)) then "Undefined" else specfile -> specfile in let SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_EMISSIVE -> emiunit in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 emiunit -> emitpath in let getPathFile emitpath "" -> [_ emitfile] in let if (emiunit != nil) && ((emitfile == nil) || (!strcmp "" emitfile)) then "Undefined" else emitfile -> emitfile in let SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_NORMAL -> nmunit in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 nmunit -> nmpath in let getPathFile nmpath "" -> [_ nmfile] in let if (nmunit != nil) && ((nmfile == nil) || (!strcmp "" nmfile)) then "Undefined" else nmfile -> nmfile in let SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_REFLECTION -> refunit in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 refunit -> refpath in let getPathFile refpath "" -> [_ reffile] in let if (refunit != nil) && ((reffile == nil) || (!strcmp "" reffile)) then "Undefined" else reffile -> reffile in let (SO3MaterialGetTextureBlendFactor mat 0 0 refunit) *. 100.0 -> reffactor in let if (reffactor <. 1.0) then 25.0 else if (reffactor >. 99.0) then 100.0 else reffactor -> reffactor in //precision issue //let SO3TextureGetName SO3MaterialGetTexture mat 0 0 (SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_REFMASK) -> refmaskpath in //let getPathFile refmaskpath "" -> [_ refmaskfile] in let SO3TextureGetName SO3MaterialGetTexture mat 0 0 (SO3MaterialTextureUnitGetIndexByType mat 0 0 SO3_MAP_ROUGHNESS) -> roughpath in let getPathFile roughpath "" -> [_ roughfile] in ( setEdWindowName ewinstr strcatn (loc "OS3D_0595")::": "::matname::nil; V3DresetSession sessionstr; setEdToolBarButtonCbClick tbstrhelp btnassignmat mkfun5 @cbTbBtnAssignMaterialEditor mat; setEdCtrlColorButtonEnable ctrlambcolor lightstate; setEdCtrlColorButtonEnable ctrldiffcolor lightstate; setEdCtrlColorButtonEnable ctrldiffcolor lightstate; setEdCtrlColorButtonEnable ctrlspeccolor lightstate; setEdCtrlColorButtonEnable ctrlemitcolor lightstate; setEdCtrlFloatEnable ctrlshininess lightstate; setEdCtrlFloatEnable ctrlopacity lightstate; setEdCtrlCheckCbState ctrlvcolor mkfun3 @cbMatSetUserVertexColor [mat groupstr ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor ctrlshininess ctrlopacity ctrllight]; setEdCtrlCheckState ctrlvcolor usevcolor; if (!usevcolor) then nil else ( setEdCtrlColorButtonEnable ctrlambcolor 0; setEdCtrlColorButtonEnable ctrldiffcolor 0; setEdCtrlFloatEnable ctrlopacity 0; ); setEdCtrlButtonCb pickambbtn mkfun2 @cbBtnPickTextureFile [ewinstr ctrlambpath ambpath mat SO3_MAP_AMBIENT groupstr nil]; setEdCtrlButtonCb refreshambpath mkfun2 @cbRefreshTextureBtn [ctrlambpath mat SO3_MAP_AMBIENT groupstr]; setEdCtrlButtonCb pickdiffbtn mkfun2 @cbBtnPickTextureFile [ewinstr ctrldiffpath diffpath mat SO3_MAP_DIFFUSE groupstr nil]; setEdCtrlButtonCb refreshdiffpath mkfun2 @cbRefreshTextureBtn [ctrldiffpath mat SO3_MAP_DIFFUSE groupstr]; setEdCtrlButtonCb pickspecbtn mkfun2 @cbBtnPickTextureFile [ewinstr ctrlspecpath specpath mat SO3_MAP_SPECULAR groupstr nil]; setEdCtrlButtonCb refreshspecpath mkfun2 @cbRefreshTextureBtn [ctrlspecpath mat SO3_MAP_SPECULAR groupstr]; setEdCtrlButtonCb pickemitbtn mkfun2 @cbBtnPickTextureFile [ewinstr ctrlemitpath emitpath mat SO3_MAP_EMISSIVE groupstr nil]; setEdCtrlButtonCb refreshemitpath mkfun2 @cbRefreshTextureBtn [ctrlemitpath mat SO3_MAP_EMISSIVE groupstr]; setEdCtrlButtonCb picknmbtn mkfun2 @cbBtnPickTextureFile [ewinstr ctrlnmpath nmpath mat SO3_MAP_NORMAL groupstr nil]; setEdCtrlButtonCb refreshnmpath mkfun2 @cbRefreshTextureBtn [ctrlnmpath mat SO3_MAP_NORMAL groupstr]; setEdCtrlButtonCb pickrefbtn mkfun2 @cbBtnPickTextureFile [ewinstr ctrlrefpath refpath mat SO3_MAP_REFLECTION groupstr ctrlrefpower]; setEdCtrlButtonCb refreshrefpath mkfun2 @cbRefreshTextureBtn [ctrlrefpath mat SO3_MAP_REFLECTION groupstr]; //setEdCtrlButtonCb pickrefmaskbtn mkfun2 @cbBtnPickTextureFile [ewinstr ctrlrefmaskpath refmaskpath mat SO3_MAP_REFMASK groupstr nil]; //setEdCtrlButtonCb refreshrefmaskpath mkfun2 @cbRefreshTextureBtn [ctrlrefmaskpath mat SO3_MAP_REFMASK groupstr]; setEdCtrlButtonCb pickroughbtn mkfun2 @cbBtnPickTextureFile [ewinstr ctrlroughpath roughpath mat SO3_MAP_ROUGHNESS groupstr nil]; setEdCtrlButtonCb refreshroughpath mkfun2 @cbRefreshTextureBtn [ctrlroughpath mat SO3_MAP_ROUGHNESS groupstr]; setEdCtrlButtonCb createroughpath mkfun2 @cbCreateRoughTexture groupstr; setEdCtrlButtonCb createnmpath mkfun2 @cbCreateNormalTexture groupstr; setEdCtrlFloatValue ctrlpointsize psize; setEdCtrlColorButtonColor ctrlambcolor ambcolor; setEdCtrlColorButtonColor ctrldiffcolor diffcolor; setEdCtrlColorButtonColor ctrlspeccolor speccolor; setEdCtrlColorButtonColor ctrlemitcolor emitcolor; setEdCtrlFloatValue ctrlshininess shininess; setEdCtrlFloatValue ctrlopacity opacity; setEdCtrlCheckState ctrl2sided !culling; setEdCtrlCheckState ctrltransparent !depthwrite; setEdCtrlCheckState ctrllight !lightstate; setEdCtrlCheckState ctrlreject reject; setEdCtrlTextLineValue ctrlambpath ambfile; setEdCtrlTextLineValue ctrldiffpath difffile; setEdCtrlTextLineValue ctrlspecpath specfile; setEdCtrlTextLineValue ctrlemitpath emitfile; setEdCtrlTextLineValue ctrlnmpath nmfile; setEdCtrlTextLineValue ctrlrefpath reffile; setEdCtrlFloatValue ctrlrefpower reffactor; //setEdCtrlTextLineValue ctrlrefmaskpath refmaskfile; setEdCtrlTextLineValue ctrlroughpath roughfile; if (pmode == SO3_POLYGONMODE_WIREFRAME) then ( setEdCtrlCheckState ctrlsolid 0; setEdCtrlCheckState ctrlwire 1; setEdCtrlCheckState ctrlpoint 0; ) else if (pmode == SO3_POLYGONMODE_POINTS) then ( setEdCtrlCheckState ctrlsolid 0; setEdCtrlCheckState ctrlwire 0; setEdCtrlCheckState ctrlpoint 1; ) else ( setEdCtrlCheckState ctrlsolid 1; setEdCtrlCheckState ctrlwire 0; setEdCtrlCheckState ctrlpoint 0; ); let V3DaddShell sessionstr "matshell" "" nil [0.0 0.0 0.0] [0.0 0.0 0.0 1.0] -> shell in ( set mMaterialSphere = V3DloadMesh sessionstr (strcat sV3DDEFAULTRESOURCESPATH "helpers/msphere.mesh") "matsphere" "" sV3DResourcesGroup shell mkfun3 @cbApplyViewMaterial [groupstr mat]; set mMaterialCube = V3DloadMesh sessionstr (strcat sV3DDEFAULTRESOURCESPATH "helpers/mcube.mesh") "matcube" "" sV3DResourcesGroup shell mkfun3 @cbApplyViewMaterial [groupstr mat]; set mMaterialCylinder = V3DloadMesh sessionstr (strcat sV3DDEFAULTRESOURCESPATH "helpers/mcylinder.mesh") "matcylinder" "" sV3DResourcesGroup shell mkfun3 @cbApplyViewMaterial [groupstr mat]; set mMaterialplane = V3DloadMesh sessionstr (strcat sV3DDEFAULTRESOURCESPATH "helpers/mplane.mesh") "matplane" "" sV3DResourcesGroup shell mkfun3 @cbApplyViewMaterial [groupstr mat]; SO3ObjectSetScale mMaterialSphere [0.75 0.75 0.75]; SO3ObjectSetScale mMaterialCube [0.75 0.75 0.75]; SO3ObjectSetScale mMaterialCylinder [0.75 0.75 0.75]; SO3ObjectSetPosition mMaterialCylinder [0.0 (-.0.38) 0.0]; SO3ObjectSetPosition mMaterialplane [0.0 (-.0.38) 0.0]; cbTbBtnMaterialMode tbstrmode nil 1 0 1 iMaterialModeState; ); SO3ObjectSetPosition (V3DgetDefaultCamera sessionstr) [0.0 0.0 (1.0 *. itof(iGlobalUnit))]; V3DsetAmbientLight sessionstr (make_rgba iDefaultAmbiantRColor iDefaultAmbiantGColor iDefaultAmbiantBColor 0); V3DuseDefaultLight sessionstr 1; V3DenableNavigate sessionstr 1; V3DshowSceneGrid sessionstr 1; V3DenableView ctrlmatview.EDC_view3d 1; V3DenableKeyboard ctrlmatview.EDC_view3d 1; V3DenableMouse ctrlmatview.EDC_view3d 1; V3DaddViewport ctrlmatview.EDC_view3d 0.0 0.0 1.0 1.0 (make_rgba iDefaultBackGroundRColor iDefaultBackGroundGColor iDefaultBackGroundBColor 0); V3DsetCamera (V3DgetDefaultCamera sessionstr) nil 1.0 0.01 100.0; V3DchangeCameraViewport sessionstr nil (V3DgetDefaultCamera sessionstr); V3DsetCbPreRender ctrlmatview.EDC_view3d mkfun2 @cbMaterialEditorPreRender sessionstr; SO3ObjectSetCastShadows (V3DgetDefaultLight sessionstr) 1; let (V3DgetDefaultViewport ctrlmatview.EDC_view3d) -> viewportstr in ( SO3SceneSetShadowFarDistance (V3DgetSession sessionstr) SO3SceneGetShadowFarDistance (V3DgetSession c3dXsession); SO3SceneSetShadowDirectionalLightExtrusionDistance (V3DgetSession sessionstr) SO3SceneGetShadowDirectionalLightExtrusionDistance (V3DgetSession c3dXsession); SO3SceneSetShadowLightingTechnique (V3DgetSession sessionstr) SO3SceneGetShadowLightingTechnique (V3DgetSession c3dXsession); SO3SceneSetShadowQuality (V3DgetSession c3dXsession) SO3SceneGetShadowQuality (V3DgetSession c3dXsession); SO3SceneSetShadowPreset (V3DgetSession sessionstr) SO3SceneGetShadowPreset (V3DgetSession c3dXsession); SO3ViewportSetOverlayEnable viewportstr.V3D_viewport 0; SO3ViewportSetShadowEnabled viewportstr.V3D_viewport 1; ); setEdCtrlCheckCbState ctrlsolid mkfun3 @cbMatSetPolygonMode [mat groupstr ctrlsolid ctrlwire ctrlpoint SO3_POLYGONMODE_SOLID]; setEdCtrlCheckCbState ctrlwire mkfun3 @cbMatSetPolygonMode [mat groupstr ctrlsolid ctrlwire ctrlpoint SO3_POLYGONMODE_WIREFRAME]; setEdCtrlCheckCbState ctrlpoint mkfun3 @cbMatSetPolygonMode [mat groupstr ctrlsolid ctrlwire ctrlpoint SO3_POLYGONMODE_POINTS]; setEdCtrlCheckCbState ctrl2sided mkfun3 @cbMatCullingMode [mat groupstr]; setEdCtrlCheckCbState ctrltransparent mkfun3 @cbMatTransparent [mat groupstr]; setEdCtrlCheckCbState ctrllight mkfun3 @cbMatLighting [mat groupstr ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor ctrlshininess ctrlopacity ctrlvcolor]; setEdCtrlCheckCbState ctrlreject mkfun3 @cbMatRejection [mat groupstr]; setEdCtrlFloatCbChange ctrlpointsize mkfun3 @cbMatPointSize [mat groupstr]; setEdCtrlColorButtonCb ctrlambcolor mkfun3 @cbAmbientColor [mat groupstr]; setEdCtrlColorButtonCb ctrldiffcolor mkfun3 @cbDiffuseColor [mat groupstr]; setEdCtrlColorButtonCb ctrlspeccolor mkfun3 @cbSpecularColor [mat groupstr]; setEdCtrlColorButtonCb ctrlemitcolor mkfun3 @cbEmissiveColor [mat groupstr]; setEdCtrlFloatCbChange ctrlshininess mkfun3 @cbShininess [mat groupstr]; setEdCtrlFloatCbChange ctrlopacity mkfun3 @cbMatOpacity [mat groupstr ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor]; setEdCtrlFloatCbChange ctrlrefpower mkfun3 @cbMatRefFactor [mat groupstr]; ); ); 0;; fun openMaterialEditor(groupstr, mat)= let _GETdesktopSize -> [sw sh] in let _GETscreenPos -> [mx my] in let [470 822] -> [iw ih] in let if (ih > (sh - 100)) then (sh - 100) else ih -> ih in let 820 -> sih in let iw - 20 -> wiw in let 10 -> ypos in let [(if ((mx + iw) > sw) then (sw - iw) else mx) (if ((my + ih) > sh) then (sh - ih) else my)] -> [x y] in ( if (winMaterialEditor != nil) then ( let winMaterialEditor -> [winstr omat sessionstr ctrls] in set winMaterialEditor = [winstr mat sessionstr ctrls]; loadMaterialEditor groupstr mat; ) else ( let ((iw - 140) / 3) -> stw in let setEdWindowIcon (crEdWindow _channel mainInterf.MINT_winMain x y iw ih WN_MENU|WN_SIZEBOX|WN_HIDDEN nil nil "") sWinDlgIcon -> ewinstr in let crEdWindowToolBar ewinstr 0 0 iw 28 5 1 EdDefaultTheme.EDT_iToolBarColor ETB_HORIZONTAL -> tbstrhelp in //let _LDalphaBitmap _channel _checkpack strcat APPBASEDIR "os3deditor/res/tb_save.png" -> spng in //let crEdToolBarButton tbstrhelp spng ETB_ALIGN_LEFT (loc "OS3D_0186") mkfun5 @cbTbBtnSaveMaterial mat -> tbsavemat in let _LDalphaBitmap _channel _checkpack strcat APPBASEDIR "os3deditor/res/tb_matassign.png" -> amassign in let crEdToolBarButton tbstrhelp amassign ETB_ALIGN_LEFT (loc "OS3D_0624") nil -> btnassignmat in let _LDalphaBitmap _channel _checkpack strcat APPBASEDIR "os3deditor/res/tb_help.png" -> apng in let crEdToolBarButton tbstrhelp apng ETB_ALIGN_RIGHT (loc "OS3D_0186") @cbTbBtnMaterialEditorgHelp -> tbhelp in let crEdScrollWindow _channel ewinstr 0 28 iw ih WN_CHILDINSIDE|WN_VSCROLL EDWIN_RESIZE_MW|EDWIN_RESIZE_MH EDWIN_GROUP nil -> gwinstr in let crEdWindow _channel gwinstr 0 0 iw sih WN_CHILDINSIDE|WN_NOBORDER nil EDWIN_GROUP nil -> iwinstr in let crEdFrameWindow _channel iwinstr 0 0 wiw 230 EDWIN_RESIZE_MW nil (loc "OS3D_0596") (loc "OS3D_0250") -> winfrm in let crEdWindow _channel winfrm 0 18 wiw 213 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrl3D winstr 0 0 wiw 213 EDWIN_RESIZE_MW|EDWIN_RESIZE_MH -> ctrlmatview in let crEdToolBar winstr.EDW_channel ctrlmatview.EDC_view3d.V3D_win 0 119 28 94 1 5 EdDefaultTheme.EDT_iToolBarColor ETB_VERTICAL -> tbstrmode in let _LDalphaBitmap _channel _checkpack strcat APPBASEDIR "os3deditor/res/tb_material_sphere.png" -> amsphere in let crEdToolBarCheck tbstrmode amsphere ETB_ALIGN_TOP nil mkfun6 @cbTbBtnMaterialMode 1 -> btnmatsphere in let _LDalphaBitmap _channel _checkpack strcat APPBASEDIR "os3deditor/res/tb_material_cube.png" -> amcube in let crEdToolBarCheck tbstrmode amcube ETB_ALIGN_TOP nil mkfun6 @cbTbBtnMaterialMode 2 -> btnmatcube in let _LDalphaBitmap _channel _checkpack strcat APPBASEDIR "os3deditor/res/tb_material_cylinder.png" -> amcylinder in let crEdToolBarCheck tbstrmode amcylinder ETB_ALIGN_TOP nil mkfun6 @cbTbBtnMaterialMode 3 -> btnmatcylinder in let crEdFrameWindow _channel iwinstr 0 0 wiw 110 EDWIN_RESIZE_MW nil (loc "OS3D_0597") (loc "OS3D_0250") -> winfrm in let crEdWindow _channel winfrm 0 18 wiw 90 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlCheck winstr 10 (set ypos = 10) 90 20 (loc "OS3D_0598") nil -> ctrl2sided in let crEdCtrlCheck winstr 110 ypos stw 20 (loc "OS3D_0599") nil -> ctrltransparent in let crEdCtrlCheck winstr stw + 110 ypos stw 20 (loc "OS3D_0630") nil -> ctrlreject in let crEdCtrlCheck winstr (stw * 2) + 110 ypos stw 20 (loc "OS3D_0611") nil -> ctrllight in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0600") nil -> labelpmode in let crEdCtrlRadio winstr 110 ypos stw 20 (loc "OS3D_0601") nil -> ctrlsolid in let crEdCtrlRadio winstr stw + 110 ypos stw 20 (loc "OS3D_0602") nil -> ctrlwire in let crEdCtrlRadio winstr (stw * 2) + 110 ypos stw 20 (loc "OS3D_0603") nil -> ctrlpoint in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0604") nil -> labelpoint in let crEdCtrlFloat winstr 110 ypos 90 20 1.0 0.001 100.0 0.1 5 nil nil -> ctrlpointsize in let crEdFrameWindow _channel iwinstr 0 0 wiw 210 EDWIN_RESIZE_MW nil (loc "OS3D_0605") (loc "OS3D_0250") -> winfrm in let crEdWindow _channel winfrm 0 18 wiw 190 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlCheck winstr 10 (set ypos = 10) (wiw - 20) 20 (loc "OS3D_0631") nil -> ctrlvcolor in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) (wiw - 80) 20 (loc "OS3D_0606") nil -> labelamb in let crEdCtrlColorButton winstr (wiw - 75) ypos 60 20 0x000000f 1 nil nil -> ctrlambcolor in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) (wiw - 80) 20 (loc "OS3D_0607") nil -> labeldiff in let crEdCtrlColorButton winstr (wiw - 75) ypos 60 20 0xfffffff 1 nil nil -> ctrldiffcolor in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) (wiw - 80) 20 (loc "OS3D_0608") nil -> labelspec in let crEdCtrlColorButton winstr (wiw - 75) ypos 60 20 0x555555f 1 nil nil -> ctrlspeccolor in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) (wiw - 80) 20 (loc "OS3D_0609") nil -> labelemit in let crEdCtrlColorButton winstr (wiw - 75) ypos 60 20 0x000000f 1 nil nil -> ctrlemitcolor in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0610") nil -> labelshininess in let crEdCtrlFloat winstr 110 ypos 90 20 100.0 0.01 255.0 0.1 2 nil nil -> ctrlshininess in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0612") nil -> labelopacity in let crEdCtrlFloat winstr 110 ypos 90 20 100.0 0.0 100.0 1.0 0 nil nil -> ctrlopacity in let crEdFrameWindow _channel iwinstr 0 0 wiw 235 EDWIN_RESIZE_MW nil (loc "OS3D_0613") (loc "OS3D_0250") -> winfrm in let crEdWindow _channel winfrm 0 18 wiw 215 WN_CHILDINSIDE|WN_NOBORDER EDWIN_RESIZE_MW nil nil -> winstr in let crEdCtrlLabel winstr 10 ((set ypos = 10) + 2) 90 20 (loc "OS3D_0614") nil -> labelambtex in let crEdCtrlTextLine winstr 110 ypos 200 20 "" nil EDWIN_RESIZE_MW -> ctrlambpath in let crEdCtrlButton winstr 320 ypos 55 20 "..." nil -> pickambbtn in let crEdCtrlButton winstr 380 ypos 35 20 "X" nil -> refreshambpath in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0615") nil -> labeldifftex in let crEdCtrlTextLine winstr 110 ypos 200 20 "" nil EDWIN_RESIZE_MW -> ctrldiffpath in let crEdCtrlButton winstr 320 ypos 55 20 "..." nil -> pickdiffbtn in let crEdCtrlButton winstr 380 ypos 35 20 "X" nil -> refreshdiffpath in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0616") nil -> labelspectex in let crEdCtrlTextLine winstr 110 ypos 200 20 "" nil EDWIN_RESIZE_MW -> ctrlspecpath in let crEdCtrlButton winstr 320 ypos 55 20 "..." nil -> pickspecbtn in let crEdCtrlButton winstr 380 ypos 35 20 "X" nil -> refreshspecpath in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0617") nil -> labelemittex in let crEdCtrlTextLine winstr 110 ypos 200 20 "" nil EDWIN_RESIZE_MW -> ctrlemitpath in let crEdCtrlButton winstr 320 ypos 55 20 "..." nil -> pickemitbtn in let crEdCtrlButton winstr 380 ypos 35 20 "X" nil -> refreshemitpath in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0618") nil -> labelnmtex in let crEdCtrlTextLine winstr 110 ypos 200 20 "" nil EDWIN_RESIZE_MW -> ctrlnmpath in let crEdCtrlButton winstr 320 ypos 55 20 "..." nil -> picknmbtn in let crEdCtrlButton winstr 380 ypos 35 20 "X" nil -> refreshnmpath in let crEdCtrlButton winstr 420 ypos 30 20 "E" nil -> createnmpath in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0848") nil -> labelroughtex in let crEdCtrlTextLine winstr 110 ypos 200 20 "" nil EDWIN_RESIZE_MW -> ctrlroughpath in let crEdCtrlButton winstr 320 ypos 55 20 "..." nil -> pickroughkbtn in let crEdCtrlButton winstr 380 ypos 35 20 "X" nil -> refreshroughpath in let crEdCtrlButton winstr 420 ypos 30 20 "E" nil -> createroughpath in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0619") nil -> labelreftex in let crEdCtrlTextLine winstr 110 ypos 200 20 "" nil EDWIN_RESIZE_MW -> ctrlrefpath in let crEdCtrlButton winstr 320 ypos 55 20 "..." nil -> pickrefbtn in let crEdCtrlButton winstr 380 ypos 35 20 "X" nil -> refreshrefpath in let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0620") nil -> labelpower in let crEdCtrlFloat winstr 110 ypos 90 20 1.0 1.0 100.0 1.0 0 nil nil -> ctrlrefpower in /* let crEdCtrlLabel winstr 10 ((set ypos = ypos + 25) + 2) 90 20 (loc "OS3D_0632") nil -> labelrefmtex in let crEdCtrlTextLine winstr 110 ypos 200 20 "" nil EDWIN_RESIZE_MW -> ctrlrefmaskpath in let crEdCtrlButton winstr 320 ypos 55 20 "..." nil -> pickrefmaskbtn in let crEdCtrlButton winstr 380 ypos 35 20 "X" nil -> refreshrefmaskpath in */ let [ewinstr tbstrhelp btnassignmat tbstrmode btnmatsphere btnmatcube btnmatcylinder ctrlmatview ctrl2sided ctrltransparent ctrlreject ctrllight ctrlsolid ctrlwire ctrlpoint ctrlpointsize ctrlvcolor ctrlambcolor ctrldiffcolor ctrlspeccolor ctrlemitcolor ctrlshininess ctrlopacity ctrlambpath ctrldiffpath ctrlspecpath ctrlemitpath ctrlnmpath ctrlrefpath ctrlrefpower ctrlroughpath //ctrlrefmaskpath pickambbtn refreshambpath pickdiffbtn refreshdiffpath pickspecbtn refreshspecpath pickemitbtn refreshemitpath picknmbtn refreshnmpath pickrefbtn refreshrefpath pickroughkbtn refreshroughpath createroughpath createnmpath] //pickrefmaskbtn refreshrefmaskpath] -> ctrls in ( setEdCtrlTextLineEnable ctrlambpath 0; setEdCtrlTextLineEnable ctrldiffpath 0; setEdCtrlTextLineEnable ctrlspecpath 0; setEdCtrlTextLineEnable ctrlemitpath 0; setEdCtrlTextLineEnable ctrlnmpath 0; setEdCtrlTextLineEnable ctrlrefpath 0; //setEdCtrlTextLineEnable ctrlrefmaskpath 0; setEdCtrlTextLineEnable ctrlroughpath 0; //init 3D view let V3DgetDefaultSession ctrlmatview.EDC_view3d -> sessionstr in set winMaterialEditor = [ewinstr mat sessionstr ctrls]; let getEdWindowSize ewinstr -> [nw nh] in ( setEdWindowMinimumSize ewinstr nw 250; setEdWindowMaximumSize ewinstr nw sh - 40; ); setEdwindowCbDestroy ewinstr @cbDestroyMaterialEditor; setEdToolBarVisible tbstrhelp 1; paintEdToolBar tbstrhelp; setEdToolBarVisible tbstrmode 1; paintEdToolBar tbstrmode; setEdWindowVisible ewinstr 1; 0; ); loadMaterialEditor groupstr mat; ); ); 0;;