/* *********************************************************************
This source file is a part of the standard library of Scol
For the latest info, see http://www.scolring.org
Copyright (c) 2013 Stephane Bisaro aka Iri, based on a work of Bastien BOURINEAU
(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
********************************************************************* */
/*
* 3D functions for basic manipulations
* See http://redmine.scolring.org/projects/tutorials/wiki/Scol_usage
* for more informations
*/
/*! \file base3d.pkg
* \author Scol team
* \version 0.1
* \copyright GNU Lesser General Public License 2.0 or later
* \brief Scol 3D Library - 3D basic API
*
* \example 3d_test/test_3d.scol
* \example 3d_test/test_3dinit.pkg_
* \example 3d_test/test_3d.pkg_
**/
/* */
/* */
/* */
/* VARIABLES AND TYPES */
/* */
/* */
/* */
// see base3dstruct.pkg
/* */
/* */
/* */
/* ERROR OBJECT */
/* */
/* */
/* */
// see base3derror.pkg
/* */
/* */
/* */
/* MISCELLANEOUS */
/* */
/* */
/* */
// fun [[[I u0] r1] u0] [[I u0] r1]
fun b3d_misc_listIU0_removeElt (l, u0)=
if l == nil then
nil
else
let hd l -> [_ u] in
if u == u0 then
tl l
else
b3d_misc_listIU0_removeElt tl l u0;;
fun b3d_misc_listCamerasRemove (l, cam)=
if l == nil then
nil
else
let hd l -> [_ [_ c]] in
if std_objIsEqual cam c then
tl l
else
b3d_misc_listCamerasRemove tl l cam;;
// fun [[[I u0] r1] u0] [I u0]
fun b3d_misc_listIU0GetEltFromU0 (l, u0)=
if l == nil then
nil
else
let hd l -> [_ u] in
if u == u0 then
hd l
else
b3d_misc_listIU0GetEltFromU0 tl l u0;;
/* */
/* */
/* */
/* SESSION OBJECT */
/* */
/* */
/* */
/*! \ingroup b3d_session
* \brief Return the Scol session object from the library session object.
*
* Prototype : fun [LIB3D_Session] SO3_SCENE
*
* \param LIB3D_Session : a basic 3d session object
* \return SO3_SCENE : the Scol session object
*/
fun b3d_sessionGet (strSession)=
strSession.lib3d_session;;
/*! \ingroup b3d_session
* \brief Destroys session object.
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a basic 3d session object
* \return I : 0 if success, 1 if error
*/
fun b3d_sessionDestroy (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
let b3d_sessionGet strSession -> s in
let SO3GroupList s ->lg in
(
exec strSession.lib3d_sessionCB.lib3d_cbSceneDestroy with [strSession];
while lg != nil do
(
SO3GroupDelete s hd lg;
set lg = tl lg
);
b3d_physicsEnable strSession 0;
let strSession.lib3d_sessionView -> v in
set v.lib3d_lSessions = std_lRemoveElt v.lib3d_lSessions strSession;
SO3SceneDelete s;
exec strSession.lib3d_sessionCB.lib3d_cbSceneDestroyed with [];
set strSession = nil;
0
);;
/*! \ingroup b3d_session
* \brief Set the callback when an axis is clicked.
*
* Prototype : fun [LIB3D_Session fun [LIB3D_Session SO3_OBJECT I I I I] I] I
*
* \param LIB3D_Session : a basic 3d session object
* \param fun [LIB3D_Session SO3_OBJECT I I I I] I : the supplemental arguments are :
* the axis father object, the axis (iLIB3D_AXIS_X, iLIB3D_AXIS_Y or iLIB3D_AXIS_Z),
* the x, y coordinates and the button number.
* \return I : 0 if success, nil 1 if error
*/
fun b3d_sessionCbAxisClick (strSession, cbfun)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strSession.lib3d_sessionCB.lib3d_cbAxisClick = cbfun;
0
);;
/*! \ingroup b3d_session
* \brief Set the callback when an axis is unclicked.
*
* Prototype : fun [LIB3D_Session fun [LIB3D_Session SO3_OBJECT I I I I] I] I
*
* \param LIB3D_Session : a basic 3d session object
* \param fun [LIB3D_Session SO3_OBJECT I I I I] I : the supplemental arguments are :
* the axis father object, the axis (iLIB3D_AXIS_X, iLIB3D_AXIS_Y or iLIB3D_AXIS_Z),
* the x, y coordinates and the button number.
* \return I : 0 if success, nil 1 if error
*/
fun b3d_sessionCbAxisUnClick (strSession, cbfun)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strSession.lib3d_sessionCB.lib3d_cbAxisUnClick = cbfun;
0
);;
/*! \ingroup b3d_session
* \brief Set the callback when an axis is moved.
*
* Prototype : fun [LIB3D_Session fun [LIB3D_Session SO3_OBJECT I I I I] I] I
*
* \param LIB3D_Session : a basic 3d session object
* \param fun [LIB3D_Session SO3_OBJECT I I I I F] I : the supplemental arguments are :
* the axis father object, the axis (iLIB3D_AXIS_X, iLIB3D_AXIS_Y or iLIB3D_AXIS_Z),
* the x, y coordinates, the button number, the scale coefficient.
* \return I : 0 if success, nil 1 if error
*/
fun b3d_sessionCbAxisMove (strSession, cbfun)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strSession.lib3d_sessionCB.lib3d_cbAxisMove = cbfun;
0
);;
/*! \ingroup b3d_session
* \brief Set the callback to the pre redering.
*
* Prototype : fun [LIB3D_Session fun [LIB3D_Session I] I] I
*
* \param LIB3D_Session : a basic 3d session object
* \param fun [LIB3D_Session I] I : the supplemental argument is :
* the elapsed time from the last render
* \return I : 0 if success, nil 1 if error
*/
fun b3d_sessionCbPreRender (strSession, cbfun)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strSession.lib3d_sessionCB.lib3d_cbScenePreRender = cbfun;
0
);;
/*! \ingroup b3d_session
* \brief Set the callback to the end of the pre-rendering
*
* Prototype : fun [LIB3D_Session fun [LIB3D_Session I] I] I
*
* \param LIB3D_Session : a basic 3d session object
* \param fun [LIB3D_Session I] I : the supplemental argument is :
* the elapsed time from the last render
* \return I : 0 if success, nil 1 if error
*/
fun b3d_sessionCbPreRenderEnd (strSession, cbfun)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strSession.lib3d_sessionCB.lib3d_cbScenePreRender2 = cbfun;
0
);;
/*! \ingroup b3d_session
* \brief Set the callback to the physics pre-rendering
*
* Prototype : fun [LIB3D_Session fun [LIB3D_Session I] I] I
*
* \param LIB3D_Session : a basic 3d session object
* \param fun [LIB3D_Session I] I : the supplemental argument is :
* the elapsed time from the last render
* \return I : 0 if success, nil 1 if error
*/
fun b3d_sessionCbPreRenderPhysics (strSession, cbfun)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strSession.lib3d_sessionCB.lib3d_cbScenePreRenderPhysic = cbfun;
0
);;
/*! \ingroup b3d_session
* \brief Set the callback to post-rendering
*
* Prototype : fun [LIB3D_Session fun [LIB3D_Session I] I] I
*
* \param LIB3D_Session : a basic 3d session object
* \param fun [LIB3D_Session I] I : the supplemental argument is :
* the elapsed time from the last render
* \return I : 0 if success, nil 1 if error
*/
fun b3d_sessionCbPostRender (strSession, cbfun)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strSession.lib3d_sessionCB.lib3d_cbScenePostRender = cbfun;
0
);;
/*! \ingroup b3d_session
* \brief Return the 3D view object used by the 3D Session object.
*
* Prototype : fun [LIB3D_Session] LIB3D_View
*
* \param LIB3D_Session : a basic 3d session object
* \return LIB3D_View : the 3d view if success, nil if error
*/
fun b3d_sessionGetView (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strSession.lib3d_sessionView;;
/* internal rendering callbacks */
fun b3d_sessionCBprerender (scn, strSession, elapsedTime)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
let strSession.lib3d_sessionView -> strView in
(
exec strSession.lib3d_sessionCB.lib3d_cbScenePreRender with [strSession elapsedTime];
// to do several things here ...
0
);;
fun b3d_sessionCBprerenderphysic (scn, strSession, elapsedTime)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
exec strSession.lib3d_sessionCB.lib3d_cbScenePreRenderPhysic with [strSession elapsedTime];;
fun b3d_sessionCBprerender2 (scn, strSession, elapsedTime)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
exec strSession.lib3d_sessionCB.lib3d_cbScenePreRender2 with [strSession elapsedTime];;
fun b3d_sessionCBpostrender (scn, strSession, elapsedTime)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
exec strSession.lib3d_sessionCB.lib3d_cbScenePostRender with [strSession elapsedTime];;
// create a grid - return 0 if a grid is created, 1 if it was already created
// todo : check each return
fun b3d_sessiongridcreate (strSession)=
if std_objIsNil strSession.lib3d_helperGrid then
let b3d_sessionGet strSession -> session in
let SO3SceneNodeCreate session "defaultHelperGrid" -> node in
let SO3SceneLoadEntity session b3d_resourcesGetGroupNameDefault strSession "default_helper_grid_square" _checkpack strcat szLIB3D_RSCPATH "helpers/default_grid_helper.mesh" -> square in
let square::nil -> lobj in
(
SO3ObjectSetScale square [(0.01 *. (itof iLIB3D_GlobalUnit)) (0.01 *. (itof iLIB3D_GlobalUnit)) (0.01 *. (itof iLIB3D_GlobalUnit))];
SO3ObjectLink square node;
SO3ObjectSetMouseClick square 0;
SO3ObjectSetCastShadows square 0;
let (-5) * iLIB3D_GlobalUnit -> i in
while i < (5 * iLIB3D_GlobalUnit) do
let SO3SceneLoadEntity
session
b3d_resourcesGetGroupNameDefault strSession
strcat "default_helper_grid_hline_" itoa i
_checkpack strcat szLIB3D_RSCPATH
if i == 0 then "helpers/h_line_b.mesh"
else "helpers/h_line_w.mesh"
-> hline in
let SO3SceneLoadEntity
session
b3d_resourcesGetGroupNameDefault strSession
strcat "default_helper_grid_vline_" itoa i
_checkpack strcat szLIB3D_RSCPATH
if i == 0 then "helpers/v_line_b.mesh"
else "helpers/v_line_w.mesh"
-> vline in
(
SO3ObjectSetScale hline [(0.01 *. (itof iLIB3D_GlobalUnit)) (0.01 *. (itof iLIB3D_GlobalUnit)) (0.01 *. (itof iLIB3D_GlobalUnit))];
SO3ObjectSetScale vline [(0.01 *. (itof iLIB3D_GlobalUnit)) (0.01 *. (itof iLIB3D_GlobalUnit)) (0.01 *. (itof iLIB3D_GlobalUnit))];
SO3ObjectLink hline node;
SO3ObjectLink vline node;
SO3ObjectSetMouseClick hline 0;
SO3ObjectSetMouseClick vline 0;
SO3ObjectSetCastShadows hline 0;
SO3ObjectSetCastShadows vline 0;
SO3ObjectSetPosition hline [0.0 0.0 (itof i)];
SO3ObjectSetPosition vline [(itof i) 0.0 0.0];
set lobj = hline::vline::lobj;
set i = i + iLIB3D_GlobalUnit
);
set strSession.lib3d_helperGrid = [node lobj];
0
)
else
1;;
fun b3d_sessiongriddestroy (strSession)=
let strSession.lib3d_helperGrid -> [node lobj] in
let sizelist lobj -> size in
let 0 -> i in
let 0 -> res in
(
while i < size do
let nth_list lobj i -> obj in
(
if std_objIsNil SO3ObjectDestroy obj then
set res = 1
else
0;
set i = i + 1;
);
if std_objIsNil SO3ObjectDestroy node then
set res = 1
else
0;
set strSession.lib3d_helperGrid = nil;
res
);;
/*! \ingroup b3d_session
* \brief Show / Hide a grid.
*
* Prototype : fun [LIB3D_Session I] I
*
* \param LIB3D_Session : a basic 3d session object
* \param I : state : show (1) or hide (0)
* \return I : 0 if success, a positive value if error :
* - 1 : 3d session is nil
* - 2 : the grid is already shown (state = show)
* - 3 : unable to create the grid correctly (state = show)
* - 4 : unable to destroy the grid (state = hide)
* - 5 : nothing to do (typically, state = hide and the grid is already hidden)
*/
fun b3d_gridShow (strSession, state)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set state = std_clamp state 0 1;
if (state && !std_objIsNil strSession.lib3d_helperGrid) then // already show
2
else if state then
if !b3d_sessiongridcreate strSession then
0
else
3
else if !std_objIsNil strSession.lib3d_helperGrid then // should be hidden (destroyed in fact)
if !b3d_sessiongriddestroy strSession then
0
else
4
else
5
);;
/* */
/* */
/* */
/* 3D VIEW OBJECT */
/* */
/* */
/* */
/*! \ingroup b3d_view
* \brief Set the window mode to the 3d window. The size is unchanged.
*
* Prototype : fun [LIB3D_View I] I
*
* \param LIB3D_View : a 3d view object
* \param I : a state : iLIB3D_WINDOWED or iLIB3D_FULLSCREEN
* \return I : 0 if success or a positive value if error
* - 1 : the given 3d view object is nil
* - 2 : the internal buffer is nil
* - 3 : the set failed
*/
fun b3d_viewSetWindowMode (strView, state)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil strView.lib3d_buffer then
(
b3d_errprint iLIB3D_ERR_BUFFER_NIL iLIB3D_ERR_MASK_ERROR;
2
)
else
(
set state = std_clamp state iLIB3D_WINDOWED iLIB3D_FULLSCREEN;
if ((!strView.lib3d_bFullScreen) && (state == iLIB3D_WINDOWED)) ||
((strView.lib3d_bFullScreen) && (state == iLIB3D_FULLSCREEN)) then
0
else
if state == iLIB3D_WINDOWED then
(
let strView.lib3d_iSize -> [w h] in
if std_objIsNil SO3BufferSetProperties strView.lib3d_buffer 0 w h then
(
b3d_errprint iLIB3D_ERR_BUFFER_NIL iLIB3D_ERR_MASK_ERROR;
3
)
else
(
set strView.lib3d_bFullScreen = 0;
b3d_winSetFocus strView 1;
0
)
)
else
(
let strView.lib3d_iSize -> [w h] in
if std_objIsNil SO3BufferSetProperties strView.lib3d_buffer 1 w h then
(
b3d_errprint iLIB3D_ERR_BUFFER_NIL iLIB3D_ERR_MASK_ERROR;
3
)
else
(
set strView.lib3d_bFullScreen = 1;
b3d_winSetFocus strView 1;
0
)
)
);;
/*! \ingroup b3d_view
* \brief Destroy the 3D view. All associated buffer, sessions and viewport
* will be destroyed too.
*
* Prototype : fun [LIB3D_View ] I
*
* \param LIB3D_View : a 3d view object
* \return I : 0 if success or a positive value if error
* - 1 : the given 3d view object is nil
* - 2 : the internal ObjWin is nil
* - 4 : a viewport object is nil or already destroyed
* - 5 : unable to destroy an internal viewport object
* - 11, 12, 13 : the 3d session is nil or already destroyed
* - 29, 30, 31, 32 : unable to destroy the 2d buffer (nil or already destroyed)
*/
fun b3d_viewDestroy (strView)=
exec strView.lib3d_viewCB.lib3dview_cbDestroy with [strView];
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
if std_objIsNil strView.lib3d_win then
(
b3d_errprint iLIB3D_ERR_WINNIL iLIB3D_ERR_MASK_ERROR;
2
)
else
let 0 -> i in
let 0 -> res in
(
// viewport
let sizelist strView.lib3d_lViewport -> size in
while (i < size) do
(
let nth_list strView.lib3d_lViewport i -> [_ vp] in
set res = b3d_viewportDestroy strView vp;
set i = i+1;
);
// session
set i = 0;
let sizelist strView.lib3d_lSessions -> size in
while (i < size) do
let nth_list strView.lib3d_lSessions i -> s in
(
set res = res + 7 + b3d_sessionDestroy s;
set i = i+1
);
// buffer
set res = res + 17 + b3d_bufferDestroy strView;
// 2D
// remove the ds callback to avoid cb looooooop : thks Ark !
_CBwinDestroy strView.lib3d_win nil nil;
_DSwindow strView.lib3d_win;
set strView = nil;
exec strView.lib3d_viewCB.lib3dview_cbDestroy2 with [res];
if !res then
0
else
3+res;
);;
/*! \ingroup b3d_view
* \brief Return the first viewport (default) for this 3d view.
*
* Prototype : fun [LIB3D_View] LIB3D_Viewport
*
* \param LIB3D_View : a 3d view object
* \return LIB3D_Viewport : this viewport object if success or nil if error
*/
fun b3d_viewGetViewportDefault (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let hd strView.lib3d_lViewport -> [_ vp] in
vp;;
/*! \ingroup b3d_view
* \brief Return all viewports for this 3d view.
*
* Prototype : fun [LIB3D_View] [LIB3D_Viewport r1]
*
* \param LIB3D_View : a 3d view object
* \return [LIB3D_Viewport r1] : a list of viewport objects if success or nil if error
*/
fun b3d_viewGetViewportAll (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let strView.lib3d_lViewport -> tmp in
let nil -> l in
(
while tmp != nil do
let hd tmp -> [_ vp] in
(
set l = vp :: l;
set tmp = tl tmp
);
l
);;
/*! \ingroup b3d_view
* \brief Set the first viewport (default) for this 3d view.
*
* Prototype : fun [LIB3D_View LIB3D_Viewport] I
*
* \param LIB3D_View : a 3d view object
* \param LIB3D_Viewport : the viewport object defined as default
*
* \return I : 0 if success, a positive value if error :
* - 1 : 3D view object is nil
* - 2 : 3D viewport object is nil
*/
fun b3d_viewSetViewportDefault (strView, strViewport)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
2
)
else
(
set strView.lib3d_lViewport = b3d_misc_listIU0_removeElt strView.lib3d_lViewport strViewport;
set strView.lib3d_lViewport = (b3d_misc_listIU0GetEltFromU0 strView.lib3d_lViewport strViewport) :: strView.lib3d_lViewport;
0
);;
/* callbacks */
/*! \ingroup b3d_view
* \brief Set the callback when the 3D view destroying is asked.
*
* This function is called before the destruction.
*
* Prototype : fun [LIB3D_View fun [LIB3D_View] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View] I : the callback.
*
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbDestroy (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbDestroy = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the 3D view destroying is done.
*
* This function is called after the destruction.
*
* Prototype : fun [LIB3D_View fun [I] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [I] I : the callback. The argument is the result of the destruction :
* - 0 : done successfully
* - 1 : the 3D view is nil
* - 2 : no window (ObjWin) in the 3d view
* - 3 and + : other errors (3d viewport, buffer, ...have some errors in their destruction)
*
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbEnd (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbDestroy2 = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback to the pre rendering effects
*
* Prototype : fun [LIB3D_View fun [LIB3D_View] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View] I : the callback.
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbPreRenderFX (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbPreRenderEffects = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback to the pre rendering
*
* Prototype : fun [LIB3D_View fun [LIB3D_View] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View] I : the callback.
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbPreRender (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbPreRender = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback to the post rendering
*
* Prototype : fun [LIB3D_View fun [LIB3D_View] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View] I : the callback.
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbPostRender (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbPostRender = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the mouse is clicked (pressed) on the 3d view
*
* Prototype : fun [LIB3D_View fun [LIB3D_View I I I] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View I I I] I : the callback. The supplemental arguments are :
* the x, y coordinates and the button number.
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbClick (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbClick = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the mouse is double clicked on the 3d view
*
* Prototype : fun [LIB3D_View fun [LIB3D_View I I I] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View I I I] I : the callback. The supplemental arguments are :
* the x, y coordinates and the button number.
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbDbClick (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbDbClick = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the mouse is released (unclicked) on the 3d view
*
* Prototype : fun [LIB3D_View fun [LIB3D_View I I I] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View I I I] I : the callback. The supplemental arguments are :
* the x, y coordinates and the button number.
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbUnClick (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbUnClick = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback
*
* Prototype : fun [LIB3D_View fun [LIB3D_View I I I I] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View I I I I] I : the callback. The supplemental arguments are :
* the x, y coordinates, the direction and the mask (from the keyboard for example).
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbWheel (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbWheel = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the mouse moves on the 3d view
*
* Prototype : fun [LIB3D_View fun [LIB3D_View I I I] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View I I I] I : the callback. The supplemental arguments are :
* the x, y coordinates and the mask (from the keyboard for example).
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbMouseMove (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbCursorMove = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the a key is pressed from the keyboard
*
* Prototype : fun [LIB3D_View fun [LIB3D_View I I] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View I I] I : the callback. The supplemental arguments are :
* the a scancode which can be specific at the keyboard, and the ascii value.
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbKeyDown (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbKeyDown = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the a key is released from the keyboard
*
* Prototype : fun [LIB3D_View fun [LIB3D_View I] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View I] I : the callback. The supplemental argument is :
* the a scancode which can be specific at the keyboard.
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbKeyUp (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbKeyUp = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when a drop file event occurs on the 3d view.
*
* Prototype : fun [LIB3D_View fun [LIB3D_View I I [P r1]] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View I I [P r1]] I : the callback. The supplemental arguments are :
* the x, y coordinates and the list of read-reference files
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbDropFile (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbDropFile = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the default camera changes.
*
* Prototype : fun [LIB3D_View fun [LIB3D_View LIB3D_Session SO3_OBJECT] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View LIB3D_Session SO3_OBJECT] I : the callback. The supplemental arguments are :
* the current 3d view, the current session and the new camera object
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbChangeCamera (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbCameraChange = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the 3d view is resized.
*
* Prototype : fun [LIB3D_View fun [LIB3D_View I I] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View I I] I : the callback. The supplemental arguments are :
* the new width and height
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbResize (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbResizeView = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the 3d view moves.
*
* Prototype : fun [LIB3D_View fun [LIB3D_View I I] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View I I] I : the callback. The supplemental arguments are :
* the new x and y coordinates
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbMove (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbMoveView = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the 3d view has the focus.
*
* Prototype : fun [LIB3D_View fun [LIB3D_View] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View] I : the callback
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbHasFocus (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbFocusView = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Set the callback when the 3d view loses the focus.
*
* Prototype : fun [LIB3D_View fun [LIB3D_View] I] I
*
* \param LIB3D_View : a 3d view object
* \param fun [LIB3D_View] I : the callback
* \return I : 0 if success, 1 if error.
*/
fun b3d_viewSetCbLoseFocus (strView, cbfun)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_viewCB.lib3dview_cbKillFocusView = cbfun;
0
);;
/*! \ingroup b3d_view
* \brief Get the first session structure object
*
* Prototype : fun [LIB3D_View] LIB3D_Session
*
* \param LIB3D_View : a 3d view object
* \return LIB3D_Session : this object if success, nil if error (or no 3d session opened).
*/
fun b3d_viewGetSessionFirst (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
hd strView.lib3d_lSessions;;
/*! \ingroup b3d_view
* \brief Enable (Disable) the rendering
*
* Prototype : fun [LIB3D_View I] I
*
* \param LIB3D_View : a 3d view object
* \param I : 1 to enable, 0 to disable
* \return I : 0 if success, 1 if error.
* \see b3d_viewEnable
*/
fun b3d_renderEnable (strView, state)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set state = std_clamp state 0 1;
set strView.lib3d_bState = state;
0
);;
/*! \ingroup b3d_view
* \brief Enable (Disable) a 3d view.
* if enabled, the 3d window is shown else it is hidden.
*
* Prototype : fun [LIB3D_View I] I
*
* \param LIB3D_View : a 3d view object
* \param I : 1 to enable, 0 to disable
* \return I : 0 if success, a positive value if error :
* - 1 : the render state has been not changed
* - 2 : the 3d view is nil
* \see b3d_renderEnable
*/
fun b3d_viewEnable (strView, state)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
2
)
else
(
set state = std_clamp state 0 1;
if state then
(
_SHOWwindow strView.lib3d_win WINDOW_UNHIDDEN;
b3d_renderEnable strView state;
)
else
(
_SHOWwindow strView.lib3d_win WINDOW_HIDDEN;
b3d_renderEnable strView state;
)
);;
/*! \ingroup b3d_view
* \brief Convert a pixel dimension to a relative dimension (from the size of 3d view).
*
* Prototype : fun [LIB3D_View I I] [F F]
*
* \param LIB3D_View : a 3d view object
* \param I : a width to convert (can be nil, in this case, it is ignored)
* \param I : a height to convert (can be nil, in this case, it is ignored)
* \return [F F] : a relative width and height if success, nil if error.
*/
fun b3d_viewConvertSizePixel2Relative (strView, pxWidth, pxHeight)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let strView.lib3d_iSize -> [w h] in
let nil -> fWidth in
let nil -> fHeight in
(
if std_objIsNil pxWidth then
nil
else
set fWidth = divf itof pxWidth itof w;
if std_objIsNil pxHeight then
nil
else
set fHeight = divf itof pxHeight itof h;
[fWidth fHeight]
);;
/*! \ingroup b3d_view
* \brief Resize a Viewport and the 2d buffer object from the
* current size of the 3d view (no fullscreen).
*
* Prototype : fun [LIB3D_View LIB3D_Viewport] I
*
* \param LIB3D_View : a 3d view object
* \param LIB3D_Viewport : a Viewport object
* \return I : 0 if success, a positive value if error :
* - 1 : unable to resize the 2d buffer
* - 2 : the Viewport object is nil
* - 3 : the 3d View object is nil
* - 4 : unable to resize the Viewport
* - 5 : current mode is fullscreen, not compatible
*/
fun b3d_viewSetViewportSizeFromFullViewSize (strView, strViewport)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
3
)
else if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
2
)
else if strView.lib3d_bFullScreen then
5
else
if !b3d_viewportSetPosSize strViewport 0.0 0.0 1.0 1.0 then
let strView.lib3d_iSize -> [w h] in
SO3BufferSetProperties strView.lib3d_buffer w h 0
else
4;;
/*! \ingroup b3d_view
* \brief Define if the 3d view is resizable or not.
*
* Prototype : fun [LIB3D_View I] I
*
* \param LIB3D_View : a 3d view object
* \param I : 0 if resizable, 1 if fixed
* \return I : 0 if success, a positive value if error :
* - 1 : the 3d View object is nil
*/
fun b3d_viewSetSizeFixed (strView, state)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set state = std_clamp state 0 1;
set strView.lib3d_iSizeFixed = state;
0
);;
/*! \ingroup b3d_view
* \brief Returns if the 3d view is resizable or not.
*
* Prototype : fun [LIB3D_View] I
*
* \param LIB3D_View : a 3d view object
* \return I : 0 if resizable, 1 if fixe, nil if error.
*/
fun b3d_viewGetSizeFixed (strView, state)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strView.lib3d_iSizeFixed;;
/*! \ingroup b3d_view
* \brief Define the minimal and the maximal size of the 3d view
*
* Prototype : fun [LIB3D_View [I I] [I I]] I
*
* \param LIB3D_View : a 3d view object
* \param [I I] : the minimal size, in pixels. Can be nil, in this case, this limit will be ignored.
* One of these two value can be nil. Example [640 nil], only the width is set.
* \param [I I] : the maximal size, in pixels. Can be nil, in this case, this limit will be ignored.
* see remark in the minimal limits, above.
* \return I : 0 if success, a positive value if error :
* - 1 : the 3d View object is nil
*/
fun b3d_viewSetSizeMinMax (strView, tSizeMin, tSizeMax)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if (std_tupleIsNil tSizeMin) && (std_tupleIsNil tSizeMax) then
(
set strView.lib3d_iSizeMin = nil;
set strView.lib3d_iSizeMax = nil;
0
)
else if (std_tupleIsNil tSizeMin) then
(
set strView.lib3d_iSizeMin = nil;
let tSizeMax -> [iW iH] in
set strView.lib3d_iSizeMax = [if iW < 1 then 1 else iW if iH < 1 then 1 else iH];
0
)
else if (std_tupleIsNil tSizeMax) then
(
let tSizeMin -> [iw ih] in
set strView.lib3d_iSizeMin = [if iw < 0 then 0 else iw if ih < 0 then 0 else ih];
set strView.lib3d_iSizeMax = nil;
0
)
else
let tSizeMin -> [iw ih] in
let tSizeMax -> [iW iH] in
(
set strView.lib3d_iSizeMin = [if iw < 0 then 0 else iw if ih < 0 then 0 else ih];
set strView.lib3d_iSizeMax = [if iW < 1 then 1 else iW if iH < 1 then 1 else iH];
0
);;
/*! \ingroup b3d_view
* \brief Returns if the limits of the 3d view size, in pixels.
*
* Prototype : fun [LIB3D_View] [[I I] [I I]]
*
* \param LIB3D_View : a 3d view object
* \return [I I] [I I] : the minimal and the maximal size limits, if success, nil if error.
* \remark If an error occurs, the return is nil.
* If one limit is nil, one tuple is nil. Example [nil [640 480]]
* If the two limits are nil, the return is [nil nil]
*/
fun b3d_viewGetSizeMinMax (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
[strView.lib3d_iSizeMin strView.lib3d_iSizeMax];;
/*! \ingroup b3d_view
* \brief Get the current size of the 3d window
*
* Prototype : fun [LIB3D_View] [I I]
*
* \param LIB3D_View : a 3d view object
* \return [I I] : the (width, height) if success or nil if error
*/
fun b3d_viewGetSize (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let _GETwindowSizePosition strView.lib3d_win -> [w h _ _] in
if std_tupleCmp [w h] strView.lib3d_iSize @std_cmpI then
strView.lib3d_iSize
else
(
set strView.lib3d_iOldSize = strView.lib3d_iSize;
set strView.lib3d_iSize = [w h]
);;
/*! \ingroup b3d_view
* \brief Get the last known size of the 3d window (before the current size)
*
* Prototype : fun [LIB3D_View] [I I]
*
* \param LIB3D_View : a 3d view object
* \return [I I] : the (width, height) if success or nil if error
*/
fun b3d_viewGetOldSize (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strView.lib3d_iOldSize;;
/*! \ingroup b3d_view
* \brief Resize the 3d view
*
* Prototype : fun [LIB3D_View I I] I
*
* \param LIB3D_View : a 3d view object
* \param I : the new width, in pixels. Nil if unchanged.
* \param I : the new height, in pixels. Nil if unchanged.
* \return I : 0 if success or a positive value if error :
* - 1 : the 3d view is nil
* - 2 (warning only) : the given new size is the same than the old size.
*/
fun b3d_viewSetSize (strView, neww, newh)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
let b3d_viewGetSize strView -> [curw curh] in
let strView.lib3d_iSizeMin -> [minw minh] in
let strView.lib3d_iSizeMax -> [maxw maxh] in
let strView.lib3d_iPosition -> [x y] in
let [curw curh] -> [w h] in
(
set w = if std_objIsNil neww then curw
else if (std_objIsNil minw) && (std_objIsNil maxw) then neww
else if (std_objIsNil minw) && (neww <= maxw) then neww
else if (std_objIsNil minw) && (neww > maxw) then maxw
else if (neww >= minw) && (std_objIsNil maxw) then neww
else if (neww < minw) && (std_objIsNil maxw) then minw
else if (neww >= minw) && (neww <= maxw) then neww
else if (neww < minw) then minw
else if (neww > maxw) then maxw
else neww;
set h = if std_objIsNil newh then curh
else if (std_objIsNil minh) && (std_objIsNil maxh) then newh
else if (std_objIsNil minh) && (newh <= maxh) then newh
else if (std_objIsNil minh) && (newh > maxh) then maxh
else if (newh >= minh) && (std_objIsNil maxh) then newh
else if (newh < minh) && (std_objIsNil maxh) then minh
else if (newh >= minh) && (newh <= maxh) then newh
else if (newh < minh) then minh
else if (newh > maxh) then maxh
else newh;
if std_tupleCmp [w h] strView.lib3d_iSize @std_cmpI then // same size than the older
(
b3d_errprint iLIB3D_ERR_WINNOCHANGE iLIB3D_ERR_MASK_WARN;
2
)
else
(
set strView.lib3d_iOldSize = strView.lib3d_iSize;
set strView.lib3d_iSize = [w h];
_SIZEwindow strView.lib3d_win w h x y;
0
)
);;
/*! \ingroup b3d_view
* \brief Activate or desactivate the focus to the 3d window
*
* Prototype : fun [LIB3D_View I] I
*
* \param LIB3D_View : a 3d view object
* \param I : 1 to activate, 0 to desactivate (and activate the mother window)
* \return I : 0 if success or 1 if error
*/
fun b3d_viewSetFocus (strView, state)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set state = std_clamp state 0 1;
if state then
_SETfocus strView.lib3d_win
else
_SETfocus strView.lib3d_motherwin;
0
);;
/*! \ingroup b3d_view
* \brief Get the current position of the 3d window (inside its mother)
*
* Prototype : fun [LIB3D_View] [I I]
*
* \param LIB3D_View : a 3d view object
* \return [I I] : the (x, y coordinates) if success or nil if error
*/
fun b3d_viewGetPos (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let _GETwindowPositionSize strView.lib3d_win -> [x y _ _] in
if std_tupleCmp [x y] strView.lib3d_iPosition @std_cmpI then
strView.lib3d_iPosition
else
set strView.lib3d_iPosition = [x y];;
/*! \ingroup b3d_view
* \brief Set the position of the 3d window (inside its mother)
*
* Prototype : fun [LIB3D_View I I] I
*
* \param LIB3D_View : a 3d view object
* \param I : the new width. Can be nil if unchanged.
* \param I : the new height. Can be nil if unchanged.
* \return I : 0 if success or 1 if error (3d view is nil), 2 if no change applied (same position than the previous)
* \remark This function only moves the 3d view, not the window mother.
*/
fun b3d_viewSetPos (strView, newx, newy)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
let strView.lib3d_iPosition -> [curx cury] in
let [curx cury] -> [x y] in
(
set x = if std_objIsNil newx then curx
else newx;
set y = if std_objIsNil newy then cury
else newy;
if std_tupleCmp [x y] strView.lib3d_iPosition @std_cmpI then // same position than the older
(
b3d_errprint iLIB3D_ERR_WINNOCHANGE iLIB3D_ERR_MASK_WARN;
2
)
else
(
_MVwindow strView.lib3d_win x y;
set strView.lib3d_iPosition = [x y];
0
)
);;
/* */
/* */
/* */
/* BUFFER OBJECT */
/* */
/* */
/* */
/*! \ingroup b3d_buffer
* \brief Destroy the buffer.
*
* Prototype : fun [LIB3D_View] I
*
* \param LIB3D_View : a 3d viewt object
* \return I : o if success or a positive value if error :
* - 1 : 3D view object is nil
* - 2 : unable to destroy the buffer, it was probably already destroyed (or not created yet)
*/
fun b3d_bufferDestroy (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_BUFFER_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
if std_objIsNil SO3DestroyBuffer strView.lib3d_buffer then
(
b3d_errprint iLIB3D_OBJ_ALREADY_DESTROYED iLIB3D_ERR_MASK_INFO;
2
)
else
0;;
fun b3d_cbbufferprerender (buffer, strView)=
exec strView.lib3d_viewCB.lib3dview_cbPreRender with [strView];
if strView.lib3d_bPaused then
nil // nothing to do
else
exec strView.lib3d_viewCB.lib3dview_cbPreRenderEffects with [strView];
0;;
fun b3d_cbbufferpostrender (buffer, strView)=
exec strView.lib3d_viewCB.lib3dview_cbPostRender with [strView];
0;;
fun b3d_initbuffer (buffer, strView)=
if buffer == nil then
(
b3d_errprint iLIB3D_ERR_BUFFER iLIB3D_ERR_MASK_ERROR;
iLIB3D_ERR_BUFFER
)
else
(
SO3CbBufferPreRender buffer @b3d_cbbufferprerender strView;
SO3CbBufferPostRender buffer @b3d_cbbufferpostrender strView;
0
);;
/*! \ingroup b3d_buffer
* \brief Get the SO3_BUFFER object from the 3d view object.
*
* Prototype : fun [LIB3D_View] SO3_BUFFER
*
* \param LIB3D_View : a 3d viewt object
* \return SO3_BUFFER : this buffer object or nil if error
*/
fun b3d_bufferGetObj (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_BUFFER_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strView.lib3d_buffer;;
/* */
/* */
/* */
/* 3D VIEWPORT OBJECT */
/* */
/* */
/* */
/*!\brief Create a new viewport with the default parameters.
*
* The defaults are :
* - The position at 0,0;
* - the size of the current 3d view;
* - a background grey
* - the polygon render mode set to SO3_POLY_SOLID
*
* \ingroup b3d_viewport
*
* Prototype : fun [LIB3D_View SO3_OBJECT] LIB3D_Viewport
*
* \param LIB3D_View : a 3d view object
* \param SO3_OBJECT : a camera object
* \return LIB3D_Viewport : a new viewport object if success or nil if error
* \see b3d_cameraGetCameraFromId
*/
fun b3d_viewportNew (strView, camera)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let SO3ViewportCreate strView.lib3d_channel strView.lib3d_buffer camera 0.0 0.0 1.0 1.0 (set iLIB3D_Index = iLIB3D_Index+1;) -> vp in
if std_objIsNil vp then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let mkLIB3D_Viewport [iLIB3D_Index vp [0.0 0.0] [1.0 1.0] nil iLIB3D_GREY SO3_POLY_SOLID nil] -> strViewport in
(
set strView.lib3d_lViewport = [iLIB3D_Index strViewport] :: strView.lib3d_lViewport;
strViewport
);;
/*! \ingroup b3d_viewport
* \brief Move and resize a viewport object. Values are from the father object.
*
* Prototype : fun [LIB3D_Viewport F F F F] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \param F : the new x coordinate (0 and 1)
* \param F : the new y coordinate (0 and 1)
* \param F : the new width (0 and 1)
* \param F : the new height (0 and 1)
* \return I : 0 if success or a positive value if error
* - 1 : given viewport object is nil
* - 2 : the resizing failed
*/
fun b3d_viewportSetPosSize (strViewport, x, y, width, height)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set x = std_fClamp x 0.0 1.0;
set y = std_fClamp y 0.0 1.0;
set width = std_fClamp width 0.0 1.0;
set height = std_fClamp height 0.0 1.0;
if std_objIsNil SO3ViewportSetPositionSize strViewport.lib3d_viewport x y width height then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_SET iLIB3D_ERR_MASK_ERROR;
2
)
else
(
set strViewport.lib3d_iViewportSize = [width height];
set strViewport.lib3d_iViewportPos = [x y];
0
)
);;
/*! \ingroup b3d_viewport
* \brief Get the position and the size of a viewport object.
*
* Prototype : fun [LIB3D_Viewport] [F F F F]
*
* \param LIB3D_Viewport : a 3d viewport object
* \return [F F F F] : x y w h if success or nil if error
*/
fun b3d_viewportGetPosSize (strViewport)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let SO3ViewportGetPositionSize strViewport.lib3d_viewport -> [x y w h] in
let strViewport.lib3d_iViewportPos -> [xx yy] in
let strViewport.lib3d_iViewportSize -> [ww hh] in
if std_tupleCmp [x y w h] [xx yy ww hh] @std_cmpF then
[x y w h]
else
(
set strViewport.lib3d_iViewportSize = [w h];
set strViewport.lib3d_iViewportPos = [x y];
[x y w h]
);;
/*! \ingroup b3d_viewport
* \brief Set the background color to a given viewport object
*
* Prototype : fun [LIB3D_Viewport I] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \param I : a rgba color
* \return I : 0 if success or a positive value if error
* - 1 : given viewport object is nil
* - 2 : the given operation failed
*/
fun b3d_viewportSetBgcolor (strViewport, color)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
if std_objIsNil SO3ViewportSetBackgroundColor strViewport.lib3d_viewport color then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_SET iLIB3D_ERR_MASK_ERROR;
2
)
else
(
set strViewport.lib3d_iBgColor = color;
0
);;
/*! \ingroup b3d_viewport
* \brief Return the background color to a given viewport object
*
* Prototype : fun [LIB3D_Viewport] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \return I : this background color if success or nil if error
*/
fun b3d_viewportGetBgcolor (strViewport)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let SO3ViewportGetBackgroundColor strViewport.lib3d_viewport -> color in
if color == strViewport.lib3d_iBgColor then
color
else
set strViewport.lib3d_iBgColor = color;;
/*! \ingroup b3d_viewport
* \brief Set if the given viewport clear the color and the depth buffer or not.
*
* Prototype : fun [LIB3D_Viewport I I] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \param I : 1 to clear the color, else 0
* \param I : 1 to clear the depth, else 0
* \return I : 0 if success or a positive value if error
* - 1 : given viewport object is nil
* - 2 : the 'clear color' operation failed
* - 3 : the 'clear depth' operation failed
* - 5 : the two 'clear' operation failed
*/
fun b3d_viewportSetClearBufferColorDepth (strViewport, stateColor, stateDepth)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
let 0 -> res in
(
set stateColor = std_clamp stateColor 0 1;
set stateDepth = std_clamp stateDepth 0 1;
if std_objIsNil SO3ViewportSetClearColor strViewport.lib3d_viewport stateColor then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_SET iLIB3D_ERR_MASK_ERROR;
set res = 2
)
else
0;
if std_objIsNil SO3ViewportSetClearDepth strViewport.lib3d_viewport stateDepth then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_SET iLIB3D_ERR_MASK_ERROR;
set res = 3
)
else
0;
res
);;
/*! \ingroup b3d_viewport
* \brief Get if the given viewport clear the color and the depth buffer or not.
*
* Prototype : fun [LIB3D_Viewport] [I I]
*
* \param LIB3D_Viewport : a 3d viewport object
* \return [I I] : 1 if clear else 0 or nil if error
*/
fun b3d_viewportGetClearBufferColorDepth (strViewport)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
[SO3ViewportGetClearColor strViewport.lib3d_viewport SO3ViewportGetClearDepth strViewport.lib3d_viewport];;
/*! \ingroup b3d_viewport
* \brief Enable / Disable the shadows on a given viewport.
*
* Prototype : fun [LIB3D_Viewport I] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \param I : 1 to enable, 0 to disable
* \return I : 0 if success or a positive value if error
* - 1 : given viewport object is nil
* - 2 : this operation failed
*/
fun b3d_viewportSetShadow (strViewport, state)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set state = std_clamp state 0 1;
if std_objIsNil SO3ViewportSetShadowEnabled strViewport.lib3d_viewport state then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_SET iLIB3D_ERR_MASK_ERROR;
2
)
else
0
);;
/*! \ingroup b3d_viewport
* \brief Get if the shadow is enabled or disabled on a given viewport.
*
* Prototype : fun [LIB3D_Viewport] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \return I : 1 if enabled, 0 if disabled or nil if error
*/
fun b3d_viewportGetShadow (strViewport)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3ViewportGetShadowEnabled strViewport.lib3d_viewport;;
/*! \ingroup b3d_viewport
* \brief Set the skies visibility state on a given viewport.
*
* Prototype : fun [LIB3D_Viewport I] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \param I : 1 to enable, 0 to disable
* \return I : 0 if success or a positive value if error
* - 1 : given viewport object is nil
* - 2 : this operation failed
*/
fun b3d_viewportSetSky (strViewport, state)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set state = std_clamp state 0 1;
if std_objIsNil SO3ViewportSetSkyEnable strViewport.lib3d_viewport state then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_SET iLIB3D_ERR_MASK_ERROR;
2
)
else
0
);;
/*! \ingroup b3d_viewport
* \brief Get the skies visibility state on a given viewport.
*
* Prototype : fun [LIB3D_Viewport] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \return I : 1 if enabled, 0 if disabled or nil if error
*/
fun b3d_viewportGetSky (strViewport)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3ViewportGetSkyEnable strViewport.lib3d_viewport;;
/*! \ingroup b3d_viewport
* \brief Get the SO3_VIEWPORT obj from the 3d viewport.
*
* Prototype : fun [LIB3D_Viewport] SO3_VIEWPORT
*
* \param LIB3D_Viewport : a 3d viewport object
* \return SO3_VIEWPORT : this object or nil if error
*/
fun b3d_viewportGet (strViewport)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strViewport.lib3d_viewport;;
/*! \ingroup b3d_viewport
* \brief Destroy a 3d viewport.
*
* Prototype : fun [LIB3D_Viewport] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \return I : 0 if success or 1 if the given object is nil, 2 if unable
* to destroy the internal SO3_VIEWPORT object.
*/
fun b3d_viewportDestroy (strView, strViewport)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strView.lib3d_lViewport = b3d_misc_listIU0_removeElt strView.lib3d_lViewport strViewport;
if std_objIsNil SO3ViewportDestroy strViewport.lib3d_viewport then
(
b3d_errprint iLIB3D_OBJ_ALREADY_DESTROYED iLIB3D_ERR_MASK_ERROR;
2
)
else
(
set strViewport.lib3d_viewport = nil;
set strViewport = nil;
0
)
);;
/*! \ingroup b3d_viewport
* \brief Set the camera to a given 3d viewport.
*
* Prototype : fun [LIB3D_Viewport SO3_OBJECT] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \param SO3_OBJECT : the camera object
*
* \return I : 0 if success or a positive value if error :
* - 1 : the 3d viewport is nil
* - 2 : the camera is nil
* - 3 : for an internal reason, the camera can not set to the given 3d viewport.
*/
fun b3d_viewportSetCamera (strViewport, camera)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil camera then
(
b3d_errprint iLIB3D_MISC_ARG_NIL iLIB3D_ERR_MASK_ERROR;
2
)
else
if std_objIsNil SO3CameraSetViewport strViewport.lib3d_viewport camera then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_SET iLIB3D_ERR_MASK_ERROR;
3
)
else
0;;
/*! \ingroup b3d_viewport
* \brief Return the current camera to a given 3d viewport.
*
* Prototype : fun [LIB3D_Viewport] SO3_OBJECT
*
* \param LIB3D_Viewport : a 3d viewport object
* \return SO3_OBJECT : the camera object if success or nil if error
*/
fun b3d_viewportGetCamera (strViewport)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3ViewportGetCamera strViewport.lib3d_viewport;;
/*! \ingroup b3d_viewport
* \brief Set the polygon rendering mode for a given viewport.
*
* Prototype : fun [LIB3D_Viewport I] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \param I : the choosen mode, one of these following values :
* - SO3_POLY_POINTS
* - SO3_POLY_SOLID
* - SO3_POLY_WIREFRAME
* \return I : 0 if success or a positive value if error
* - 1 : given viewport object is nil
* - 2 : the given mode value is incorrect
* - 3 : this operation failed for an internal reason
*/
fun b3d_viewportSetPolygonMode (strViewport, mode)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
if std_tupleIsFound [SO3_POLY_POINTS SO3_POLY_SOLID SO3_POLY_WIREFRAME] mode then
(
set strViewport.lib3d_iPolygonMode = mode;
if std_objIsNil SO3CameraSetPolygonMode b3d_viewportGetCamera strViewport strViewport.lib3d_iPolygonMode then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_SET iLIB3D_ERR_MASK_ERROR;
3
)
else
0
)
else
(
b3d_errprint iLIB3D_MISC_ARG_BAD iLIB3D_ERR_MASK_ERROR;
2
);;
/*! \ingroup b3d_viewport
* \brief Get the polygon rendering mode for a given viewport.
*
* Prototype : fun [LIB3D_Viewport] I
*
* \param LIB3D_Viewport : a 3d viewport object
* \return I : the current mode or nil if error
* - SO3_POLY_POINTS
* - SO3_POLY_SOLID
* - SO3_POLY_WIREFRAME
*/
fun b3d_viewportGetPolygonMode (strViewport, mode)=
if std_objIsNil strViewport then
(
b3d_errprint iLIB3D_ERR_3DVIEWPORT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
let SO3CameraGetPolygonMode b3d_viewportGetCamera strViewport -> mode in
if std_cmpI mode strViewport.lib3d_iPolygonMode then
mode
else
set strViewport.lib3d_iPolygonMode = mode;;
/* */
/* */
/* */
/* 3D OBJ OBJECT */
/* */
/* */
/* */
/*! \ingroup b3d_object
* \brief Set the 3d object position.
*
* Prototype : fun [SO3_OBJECT [F F F]] I
*
* \param SO3_OBJECT : a 3d object
* \param [F F F] : position
* \return I : 0 if success, another positive value if error
* - 1 : the given object is nil
* - 2 : unable to set this new position
*/
fun b3d_objSetPosition (obj, posF)=
if std_objIsNil obj then
(
b3d_errprint iLIB3D_ERR_OBJ_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil SO3ObjectSetPosition obj posF then
let posF -> [a b c] in
let [SO3ObjectGetName obj a b c] -> p in
(
b3d_errprintS sprintf "The position of 3d object named '%s' has not been set - given coordinates : %f %f %f" p iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_OBJ_POS iLIB3D_ERR_MASK_ERROR;
2
)
else
0;;
/*! \ingroup b3d_object
* \brief Set the 3d object position.
*
* Prototype : fun [SO3_OBJECT] [F F F]
*
* \param SO3_OBJECT : a 3d object
* \return [F F F] : the position if success, nil if error
*/
fun b3d_objGetPosition (obj)=
if std_objIsNil obj then
(
b3d_errprint iLIB3D_ERR_OBJ_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3ObjectGetPosition obj;;
/*! \ingroup b3d_object
* \brief Set the pitch of an 3d object.
*
* Prototype : fun [SO3_OBJECT F I] I
*
* \param SO3_OBJECT : a 3d object
* \param F : a pitch value
* \param I : a flag, one of these following values : SO3_LOCAL_TS, SO3_PARENT_TS or SO3_WORLD_TS
* \return I : 0 if success, another positive value if error
* - 1 : given 3d object is nil
* - 2 : unable to perform this operation
*/
fun b3d_objSetRotatePitch (obj, pitch, flag)=
if std_objIsNil obj then
(
b3d_errprint iLIB3D_ERR_OBJ_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil SO3ObjectRotatePitch obj pitch flag then
let [SO3ObjectGetName obj pitch flag] -> p in
(
b3d_errprintS sprintf "The pitch of 3d object named '%s' has not been set - given data : %f %i" p iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_OBJ_ROT iLIB3D_ERR_MASK_ERROR;
2
)
else
0;;
/*! \ingroup b3d_object
* \brief Rotate an 3d object.
*
* Prototype : fun [SO3_OBJECT F [F F F] I] I
*
* \param SO3_OBJECT : a 3d object
* \param F : a rotation value
* \param [F F F] : vector (values by axes)
* \param I : a flag, one of these following values : SO3_LOCAL_TS, SO3_PARENT_TS or SO3_WORLD_TS
* \return I : 0 if success, another positive value if error
* - 1 : given 3d object is nil
* - 2 : unable to perform this operation
*/
fun b3d_objSetRotate (obj, rot, tuple, flag)=
if std_objIsNil obj then
(
b3d_errprint iLIB3D_ERR_OBJ_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil SO3ObjectRotate obj rot tuple flag then
let [SO3ObjectGetName obj rot flag] -> p in
(
b3d_errprintS sprintf "The rotate of 3d object named '%s' has not been set - given data : %f %i" p iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_OBJ_ROT iLIB3D_ERR_MASK_ERROR;
2
)
else
0;;
/*! \ingroup b3d_object
* \brief Link an 3d object to another 3d object
*
* Prototype : fun [SO3_OBJECT SO3_OBJECT] I
*
* \param SO3_OBJECT : a 3d object (child)
* \param SO3_OBJECT : another 3d object (father)
* \return I : 0 if success, another positive value if error
* - 1 : one of given 3d objects is nil
* - 2 : unable to link the child object to the father object
*/
fun b3d_objLink (obj, father)=
if (std_objIsNil obj) || (std_objIsNil father) then
(
b3d_errprint iLIB3D_ERR_OBJ_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil SO3ObjectLink obj father then
let [SO3ObjectGetName obj SO3ObjectGetName father] -> p in
(
b3d_errprintS sprintf "The 3d child object named '%s' has not been linked with the 3d father object named '%s'" p iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_OBJ_LINK iLIB3D_ERR_MASK_ERROR;
2
)
else
0;;
/*! \ingroup b3d_object
* \brief Set the orientation of an 3d object
*
* Prototype : fun [SO3_OBJECT [F F F]] I
*
* \param SO3_OBJECT : a 3d object (child)
* \param [F F F] : new angle, in degree. If nil, the vector will be [0.0 0.0 0.0].
* \return I : 0 if success, another positive value if error
* - 1 : the 3d objects is nil.
* - 2 : unable to set this change.
*/
fun b3d_objSetOrientation (obj, angDeg)=
set angDeg = if std_objIsNil angDeg then std_vectorSet 0.0 else angDeg;
if std_objIsNil obj then
(
b3d_errprint iLIB3D_ERR_OBJ_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
let angDeg -> [ax ay az] in
let [(SO3MathsDegreeToRadian ax) (SO3MathsDegreeToRadian ay) (SO3MathsDegreeToRadian az)] -> angRad in
if std_objIsNil SO3ObjectSetOrientation obj SO3MathsEulerXYZToQuat angRad then
let [SO3ObjectGetName obj ax ay az] -> p in
(
b3d_errprintS sprintf "Unable to set the orientation of the 3d object named '%s' - ang : %f %f %f" p iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_OBJ_ORIENT iLIB3D_ERR_MASK_WARN;
2
)
else
0;;
/*! \ingroup b3d_object
* \brief Set the global orientation of an 3d object
*
* Prototype : fun [SO3_OBJECT [F F F]] I
*
* \param SO3_OBJECT : a 3d object (child)
* \param [F F F] : new angle, in degree. If nil, the vector will be [0.0 0.0 0.0].
* \return I : 0 if success, another positive value if error
* - 1 : the 3d objects is nil.
* - 2 : unable to set this change.
*/
fun b3d_objSetGlobalOrientation (obj, angDeg)=
set angDeg = if std_objIsNil angDeg then std_vectorSet 0.0 else angDeg;
if std_objIsNil obj then
(
b3d_errprint iLIB3D_ERR_OBJ_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
let angDeg -> [ax ay az] in
let [(SO3MathsDegreeToRadian ax) (SO3MathsDegreeToRadian ay) (SO3MathsDegreeToRadian az)] -> angRad in
if std_objIsNil SO3ObjectSetGlobalOrientation obj SO3MathsEulerXYZToQuat angRad then
let [SO3ObjectGetName obj ax ay az] -> p in
(
b3d_errprintS sprintf "Unable to set the orientation of the 3d object named '%s' - ang : %f %f %f" p iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_OBJ_ORIENT iLIB3D_ERR_MASK_WARN;
2
)
else
0;;
/*! \ingroup b3d_object
* \brief Get the current orientation of an 3d object
*
* Prototype : fun [SO3_OBJECT] [F F F]
*
* \param SO3_OBJECT : a 3d object (child)
* \return [F F F] : this orientation in degree if success or nil if error
*/
fun b3d_objGetOrientation (obj)=
if std_objIsNil obj then
(
b3d_errprint iLIB3D_ERR_OBJ_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let SO3MathsQuatToEulerXYZ SO3ObjectGetOrientation obj -> [ax ay az] in
[(SO3MathsRadianToDegree ax) (SO3MathsRadianToDegree ay) (SO3MathsRadianToDegree az)];;
/*! \ingroup b3d_object
* \brief Get the current global orientation of an 3d object
*
* Prototype : fun [SO3_OBJECT] [F F F]
*
* \param SO3_OBJECT : a 3d object (child)
* \return [F F F] : this orientation in degree if success or nil if error
*/
fun b3d_objGetGlobalOrientation (obj)=
if std_objIsNil obj then
(
b3d_errprint iLIB3D_ERR_OBJ_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let SO3MathsQuatToEulerXYZ SO3ObjectGetGlobalOrientation obj -> [ax ay az] in
[(SO3MathsRadianToDegree ax) (SO3MathsRadianToDegree ay) (SO3MathsRadianToDegree az)];;
/*! \ingroup b3d_object
* \brief Get an 3d object from its name in a given session object
*
* Prototype : fun [LIB3D_Session S] SO3_OBJECT
*
* \param LIB3D_Session : a 3d session object
* \param S : a name
* \return SO3_OBJECT : this object if success or nil if error or not found
*/
fun b3d_objGetFromName (strSession, name)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3SceneGetObject b3d_sessionGet strSession name;;
/*! \ingroup b3d_object
* \brief Destroy any 3d object
*
* Prototype : fun [SO3_OBJECT] I
*
* \param SO3_OBJECT : a 3d object to destroy
* \return I : 0 if success or a positive value if error :
* - 1 : 3d object is nil
* - 2 : unable to destroy this object
*/
fun b3d_objDestroy (obj)=
if std_objIsNil obj then
(
b3d_errprint iLIB3D_ERR_OBJ_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil SO3ObjectDestroy obj then
(
b3d_errprint iLIB3D_ERR_OBJ_DESTROY iLIB3D_ERR_MASK_ERROR;
2
)
else
0;;
/* */
/* */
/* */
/* 3D LIGHT OBJECT */
/* */
/* */
/* */
fun b3d_lightchecktype (type)=
std_clampT type [SO3_POINT_LIGHT SO3_DIRECTIONAL_LIGHT SO3_SPOT_LIGHT] SO3_POINT_LIGHT;;
/*! \ingroup b3d_light
* \brief Set the 3d ambiant light.
*
* Prototype : fun [LIB3D_Session I] I
*
* \param LIB3D_Session : a session object
* \param I : a RGBA color
* \return I : 0 if success, another positive value if error
* - 1 : the given 3d session object is nil
* - 2 : the light has not been set, for an internal reason
*/
fun b3d_lightAmbiantSet (strSession, color)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil SO3SceneSetAmbientLight b3d_sessionGet strSession color then
(
b3d_errprintS sprintf "The ambiant light cannot be created with color %h" [color] iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_LIGHT_SET iLIB3D_ERR_MASK_ERROR;
2
)
else
0;;
/*! \ingroup b3d_light
* \brief Get the 3d ambiant light.
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a session object
* \return I : the RGBA color if success, nil if error
*/
fun b3d_lightAmbiantGet (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3SceneGetAmbientLight strSession;;
/*! \ingroup b3d_light
* \brief Create (add) a new light.
*
* Prototype : fun [LIB3D_Session S I SO3_OBJECT] SO3_OBJECT
*
* \param LIB3D_Session : a session object
* \param S : a name
* \param I : the type of light, one of these following types :
* - SO3_POINT_LIGHT (default)
* - SO3_DIRECTIONAL_LIGHT
* - SO3_SPOT_LIGHT
* \param SO3_OBJECT : a father, a 3d object to link the light. Can be nil.
* \return SO3_OBJECT : the new light if success, nil if error
* The new light will be automatically destroyed if the type can be set or the father
* (which it is not nil) can be linked. In these cases, the return will be nil too.
*/
fun b3d_lightAdd (strSession, name, type, father)=
let nil -> light in
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else if std_objIsNil (set light = SO3LightCreate b3d_sessionGet strSession name;) then
(
b3d_errprint iLIB3D_ERR_LIGHT_CR iLIB3D_ERR_MASK_ERROR;
nil
)
else
(
set type = b3d_lightchecktype type;
if std_objIsNil SO3LightSetType light type then
(
b3d_errprintS sprintf "Unable to set the type '%d' to the new light" [type] iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_LIGHT_SET iLIB3D_ERR_MASK_ERROR;
b3d_objDestroy light;
nil
)
else
if std_objIsNil father then
light
else
if std_objIsNil SO3ObjectLink light father then
(
b3d_errprintS "Unable to link the light to the given 3d object" iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_LIGHT_SET iLIB3D_ERR_MASK_ERROR;
b3d_objDestroy light;
nil
)
else
light
);;
/*! \ingroup b3d_light
* \brief Set the type of a light.
*
* Prototype : fun [SO3_OBJECT I] I
*
* \param SO3_OBJECT : a light
* \param I : the type of light, one of these following types :
* - SO3_POINT_LIGHT (default)
* - SO3_DIRECTIONAL_LIGHT
* - SO3_SPOT_LIGHT
* \return I : 0 if success, a positive value if error :
* - 1 : the 3d light is nil
* - 2 : the type can not be set
*/
fun b3d_lightSetType (light, type)=
if std_objIsNil light then
(
b3d_errprint iLIB3D_ERR_LIGHT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set type = b3d_lightchecktype type;
if std_objIsNil SO3LightSetType light type then
(
b3d_errprint iLIB3D_ERR_LIGHT_SET iLIB3D_ERR_MASK_ERROR;
2
)
else
0
);;
/*! \ingroup b3d_light
* \brief Get the type of a light.
*
* Prototype : fun [SO3_OBJECT] I
*
* \param SO3_OBJECT : a light
* \return I : the type if success, nil if error.
* - SO3_POINT_LIGHT (default)
* - SO3_DIRECTIONAL_LIGHT
* - SO3_SPOT_LIGHT
*/
fun b3d_lightGetType (light)=
if std_objIsNil light then
(
b3d_errprint iLIB3D_ERR_LIGHT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3LightGetType light;;
/*! \ingroup b3d_light
* \brief Set the diffuse color of a light.
*
* Prototype : fun [SO3_OBJECT I] I
*
* \param SO3_OBJECT : a light
* \param I : the rgba color to set
* \return I : 0 if success, a positive value if error :
* - 1 : the 3d light is nil
* - 2 : the color can not be set
*/
fun b3d_lightSetColorDiffuse (light, color)=
if std_objIsNil light then
(
b3d_errprint iLIB3D_ERR_LIGHT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
if std_objIsNil SO3LightSetDiffuseColor light color then
(
b3d_errprint iLIB3D_ERR_LIGHT_SET iLIB3D_ERR_MASK_ERROR;
2
)
else
0;;
/*! \ingroup b3d_light
* \brief Set the specular color of a light.
*
* Prototype : fun [SO3_OBJECT I] I
*
* \param SO3_OBJECT : a light
* \param I : the rgba color to set
* \return I : 0 if success, a positive value if error :
* - 1 : the 3d light is nil
* - 2 : the color can not be set
*/
fun b3d_lightSetColorSpecular (light, color)=
if std_objIsNil light then
(
b3d_errprint iLIB3D_ERR_LIGHT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
if std_objIsNil SO3LightSetSpecularColor light color then
(
b3d_errprint iLIB3D_ERR_LIGHT_SET iLIB3D_ERR_MASK_ERROR;
2
)
else
0;;
/*! \ingroup b3d_light
* \brief Set the specular color of a light.
*
* Prototype : fun [SO3_OBJECT [I I]] I
*
* \param SO3_OBJECT : a light
* \param [I I] : the rgba diffuse color and the rgba specular color
* \return I : 0 if success, a positive value if error :
* - 1 : the 3d light is nil
* - 3 : the diffuse color can not be set
* - 7 : the specular color can not be set
* - 9 : all given colors are nil
*/
fun b3d_lightSetColors (light, tuple)=
let 0 -> res in
if std_objIsNil light then
(
b3d_errprint iLIB3D_ERR_LIGHT_NIL iLIB3D_ERR_MASK_ERROR;
set res = 1
)
else
let tuple -> [colorDif colorSpe] in
(
if std_tupleIsNil tuple then
9
else
(
if colorDif != nil then
if !b3d_lightSetColorDiffuse light colorDif then 0 else set res = 1 + res
else
0;
if colorSpe != nil then
if !b3d_lightSetColorSpecular light colorSpe then 0 else set res = 5 + res
else
0
);
res
);;
/*! \ingroup b3d_light
* \brief Get the diffuse and specular colors of a light.
*
* Prototype : fun [SO3_OBJECT] [I I]
*
* \param SO3_OBJECT : a light
* \return [I I] : the diffuse and specular colors if success, nil if error.
*/
fun b3d_lightGetColors (light)=
if std_objIsNil light then
(
b3d_errprint iLIB3D_ERR_LIGHT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
[SO3LightGetDiffuseColor light SO3LightGetSpecularColor light];;
/*! \ingroup b3d_light
* \brief Set the visibility of a light.
*
* Prototype : fun [SO3_OBJECT I] I
*
* \param SO3_OBJECT : a light
* \param I : the state : 1 to enable the visibility, 0 to disable the visibility
* \return I : 0 if success, a positive value if error :
* - 1 : the 3d light is nil
* - 2 : the visibility can not be set
*/
fun b3d_lightSetVisible (light, state)=
if std_objIsNil light then
(
b3d_errprint iLIB3D_ERR_LIGHT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set state = std_clamp state 0 1;
if std_objIsNil SO3LightSetVisible light state then
(
b3d_errprint iLIB3D_ERR_LIGHT_SET iLIB3D_ERR_MASK_ERROR;
2
)
else
0
);;
/*! \ingroup b3d_light
* \brief Get the visibility of a light.
*
* Prototype : fun [SO3_OBJECT] I
*
* \param SO3_OBJECT : a light
* \return I : 1 if enabled, 0 if disabled if success, nil if error.
*/
fun b3d_lightGetVisible (light)=
if std_objIsNil light then
(
b3d_errprint iLIB3D_ERR_LIGHT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3LightGetVisible light;;
/*! \ingroup b3d_light
* \brief Set the attenuation coefficients of a light.
*
* Prototype : fun [SO3_OBJECT [F F F F]] I
*
* \param SO3_OBJECT : a light
* \param [F F F F] : light range coefficient, constant attenuation value, linear attenuation coefficient
* and quadratic attenuation coefficient
* \return I : 0 if success, a positive value if error :
* - 1 : the 3d light is nil
* - 2 the tuple or one (or more) of its items is nil
* - 3 : the attenuation can not be set
*/
fun b3d_lightSetAttenuation (light, tuple)=
if std_objIsNil light then
(
b3d_errprint iLIB3D_ERR_LIGHT_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
if std_tupleHasNil tuple then
2
else
if std_objIsNil SO3LightSetAttenuation light tuple then
(
b3d_errprint iLIB3D_ERR_LIGHT_SET iLIB3D_ERR_MASK_ERROR;
3
)
else
0;;
/*! \ingroup b3d_light
* \brief Get the attenuation coefficients of a light.
*
* Prototype : fun [SO3_OBJECT] [F F F F]
*
* \param SO3_OBJECT : a light
* \return [F F F F] : light range coefficient, constant attenuation value, linear attenuation coefficient
* if success, nil if error.
*/
fun b3d_lightGetAttenuation (light)=
if std_objIsNil light then
(
b3d_errprint iLIB3D_ERR_LIGHT_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3LightGetAttenuation light;;
/* */
/* */
/* */
/* CAMERA OBJECT */
/* */
/* */
/* */
/*! \ingroup b3d_camera
* \brief Add a camera in a given session.
*
* Prototype : fun [LIB3D_Session S I] [SO3_OBJECT I]
*
* \param LIB3D_Session : a session object
* \param S : a name for the new camera
* \param I : define if this camera is (or becomes) the default camera or not.
* Possible values are : iLIB3S_ISDEFAULT or nil
* \return [SO3_OBJECT I] : the new camera object and the new camera id or nil if error
*/
fun b3d_cameraAdd (strSession, name, flag)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
(
set name = if std_objIsNil name then strcat "defaultCamera_" itoa _tickcount else name;
let SO3CameraCreate b3d_sessionGet strSession name -> newcam in
if std_objIsNil newcam then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
(
set strSession.lib3d_lCamera = [(set strSession.lib3d_nCamera = strSession.lib3d_nCamera;) [name newcam]]:: strSession.lib3d_lCamera;
if flag == iLIB3S_ISDEFAULT then
(
set strSession.lib3d_lPrevDefaultCamera = strSession.lib3d_defaultCamera :: strSession.lib3d_lPrevDefaultCamera;
set strSession.lib3d_defaultCamera = newcam;
)
else
nil;
[newcam strSession.lib3d_nCamera]
)
);;
/*! \ingroup b3d_camera
* \brief Get the name from a camera id.
*
* Prototype : fun [LIB3D_Session I] S
*
* \param LIB3D_Session : a session object
* \param I : a camera id
* \return I : the name or nil if error (or not found)
*/
fun b3d_cameraGetNameFromId (strSession, id)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else if std_objIsNil strSession.lib3d_lCamera then
(
b3d_errprint iLIB3D_ERR_OBJ_UKWN iLIB3D_ERR_MASK_ERROR;
nil
)
else
let switch strSession.lib3d_lCamera id -> [name _] in
name;;
/*! \ingroup b3d_camera
* \brief Get the camera object from a camera id.
*
* Prototype : fun [LIB3D_Session I] SO3_OBJECT
*
* \param LIB3D_Session : a session object
* \param I : a camera id
* \return SO3_OBJECT : the camera object or nil if error (or not found)
*/
fun b3d_cameraGetFromId (strSession, id)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else if std_objIsNil strSession.lib3d_lCamera then
(
b3d_errprint iLIB3D_ERR_OBJ_UKWN iLIB3D_ERR_MASK_ERROR;
nil
)
else
let switch strSession.lib3d_lCamera id -> [_ cam] in
cam;;
fun b3d_cameragetidfromcamera (cameras, cam)=
if std_objIsNil cameras then
nil
else
let cameras -> [[id [_ camera]] next] in
if std_objIsEqual cam camera then
id
else
b3d_cameragetidfromcamera next cam;;
/*! \ingroup b3d_camera
* \brief Get the name from a camera id.
*
* Prototype : fun [LIB3D_Session SO3_OBJECT] I
*
* \param LIB3D_Session : a session object
* \param SO3_OBJECT : a camera object
* \return I : the camera id or nil if error (or not found)
*/
fun b3d_cameraGetIdFromCamera (strSession, cam)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let b3d_cameragetidfromcamera strSession.lib3d_lCamera cam -> id in
if id == nil then
(
b3d_errprint iLIB3D_ERR_OBJ_UKWN iLIB3D_ERR_MASK_ERROR;
nil
)
else
id;;
fun b3d_cameragetfromname (cameras, name)=
if std_objIsNil cameras then
nil
else
let cameras -> [[_ [n camera]] next] in
if std_szIsEqual n name then
camera
else
b3d_cameragetfromname next name;;
/*! \ingroup b3d_camera
* \brief Get the the camera from its name.
*
* Prototype : fun [LIB3D_Session S] SO3_OBJECT
*
* \param LIB3D_Session : a session object
* \param S : a name
* \return SO3_OBJECT : the camera or nil if error (or not found)
*/
fun b3d_cameraGetFromName (strSession, name)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let b3d_cameragetfromname strSession.lib3d_lCamera name -> cam in
if cam == nil then
(
b3d_errprint iLIB3D_ERR_OBJ_UKWN iLIB3D_ERR_MASK_ERROR;
nil
)
else
cam;;
/*! \ingroup b3d_camera
* \brief Get the the camera which it created during the 3d session initialization.
*
* Prototype : fun [LIB3D_Session] SO3_OBJECT
*
* \param LIB3D_Session : a session object
* \return SO3_OBJECT : the camera or nil if error (or not found)
*/
fun b3d_cameraGetFromInit (strSession)=
b3d_cameraGetFromName strSession szCAMERAINIT;;
/*! \ingroup b3d_camera
* \brief Restore the last used camera before the current camera.
*
* The current camera is not destroyed : it is stored to be the next last
* camera, if any. This is similar as an undo/redo.
*
* Prototype : fun [LIB3D_Session SO3_OBJECT] I
*
* \param LIB3D_Session : a session object
* \param SO3_OBJECT : a camera object
* \return I : 0 if success or a positive value if error :
* - 1 : 3d session object is nil
* - 2 : no default camera set
* - 3 : 3d view object which the 3d session is, is nil
* - 4 : the last stored default camera is nil
*/
fun b3d_cameraRestoreLast (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil strSession.lib3d_lPrevDefaultCamera then
(
b3d_errprint iLIB3D_ERR_CAM_NODEFAULT iLIB3D_ERR_MASK_ERROR;
2
)
else
let strSession.lib3d_sessionView -> strView in
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
3
)
else
(
set strSession.lib3d_defaultCamera = hd strSession.lib3d_lPrevDefaultCamera;
if std_objIsNil strSession.lib3d_defaultCamera then
(
b3d_errprint iLIB3D_ERR_CAM_NODEFAULT iLIB3D_ERR_MASK_ERROR;
4
)
else
(
set strSession.lib3d_lPrevDefaultCamera = tl strSession.lib3d_lPrevDefaultCamera;
exec strView.lib3d_viewCB.lib3dview_cbCameraChange with [strView strSession strSession.lib3d_defaultCamera];
b3d_viewportSetCamera b3d_viewGetViewportDefault strView strSession.lib3d_defaultCamera;
0
)
);;
/*! \ingroup b3d_camera
* \brief Set a camera as the default camera.
*
* Prototype : fun [LIB3D_Session SO3_OBJECT] I
*
* \param LIB3D_Session : a session object
* \param SO3_OBJECT : a camera object
* \return I : 0 if success or a positive value if error :
* - 1 : 3d session object is nil
* - 2 or 5 : the camera object is nil
* - 3 : no 3D View for this session
* - 4 : the 3d viewport is nil
* - 6 : for an internal reason, the camera can not set to the given 3d viewport.
*/
fun b3d_cameraSetDefault (strSession, cam)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil cam then
(
b3d_errprint iLIB3D_MISC_ARG_NIL iLIB3D_ERR_MASK_ERROR;
2
)
else
let strSession.lib3d_sessionView -> strView in
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
3
)
else
(
set strSession.lib3d_lPrevDefaultCamera = cam :: strSession.lib3d_lPrevDefaultCamera;
exec strView.lib3d_viewCB.lib3dview_cbCameraChange with [strView strSession strSession.lib3d_defaultCamera];
let b3d_viewportSetCamera b3d_viewGetViewportDefault strView strSession.lib3d_defaultCamera -> res in
if !res then
0
else
3+res
);;
/*! \ingroup b3d_camera
* \brief Destroy a camera.
*
* If the camera is destroyed, the last default camera is set to default camera.
* If no previous camera has been set, the first camera found will be set.
*
* Prototype : fun [LIB3D_Session SO3_OBJECT] I
*
* \param LIB3D_Session : a session object
* \param SO3_OBJECT : a camera object
* \return I : 0 if success or a positive value if error :
* - 1 or 4 : 3d session object is nil
* - 2 or 5 : the camera object is nil
* - 3 : unable to destroy the camera, probably it was already destroyed
* - 6 : the 3d viewport is nil
* - 7 : for an internal reason, the camera can not set to the given 3d viewport.
* - 9 : no camera object is in this given session, so no camera set.
*/
fun b3d_cameraDestroy (strSession, cam)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if std_objIsNil cam then
(
b3d_errprint iLIB3D_OBJ_ALREADY_DESTROYED iLIB3D_ERR_MASK_ERROR;
2
)
else
(
set strSession.lib3d_lPrevDefaultCamera = std_lRemoveElt strSession.lib3d_lPrevDefaultCamera cam;
set strSession.lib3d_lCamera = b3d_misc_listCamerasRemove strSession.lib3d_lCamera cam;
if std_objIsNil SO3ObjectDestroy cam then
(
b3d_errprint iLIB3D_OBJ_ALREADY_DESTROYED iLIB3D_ERR_MASK_ERROR;
3
)
else
if !b3d_cameraRestoreLast strSession then
0
else
let hd strSession.lib3d_lCamera -> [_ [_ c]] in
if std_objIsNil c then
(
b3d_errprint iLIB3D_ERR_CAM_FIRSTFOUND iLIB3D_ERR_MASK_WARN;
9
)
else
let b3d_cameraSetDefault strSession c -> res in
if !res then 0 else 3+res
);;
/*! \ingroup b3d_camera
* \brief Set the camera parameters.
*
*
* Prototype : fun [SO3_OBJECT F F F F] I
*
* \param SO3_OBJECT : a camera object.
* \param F : the focal length. If nil, this parameter is unchanged.
* \param F : the FOVy. If nil, this parameter is unchanged.
* \param F : the near clip distance. If nil, this parameter is unchanged.
* \param F : the far clip distance. If nil, this parameter is unchanged.
* \return I : 0 if success or a positive value if error (these values can be combined) :
* - 16 : camera object is nil
* - 1 : unable to set the focal length
* - 2 : unable to set the FOVy
* - 4 : unable to set the near clip distance
* - 8 : unable to set the far clip distance
*/
fun b3d_cameraSetParams (camera, focalLength, fovy, near, far)=
if std_objIsNil camera then
(
b3d_errprint iLIB3D_ERR_CAM_NIL iLIB3D_ERR_MASK_ERROR;
16
)
else
let 0 -> res in
(
if focalLength != nil then
if SO3CameraSetFocalLenght camera focalLength then
0
else
set res = res + 1
else
0;
if fovy != nil then
if SO3CameraSetFOVy camera fovy then
0
else
set res = res + 2
else
0;
if near != nil then
if SO3CameraSetNearClipDistance camera near then
0
else
set res = res + 4
else
0;
if far != nil then
if SO3CameraSetFarClipDistance camera far then
0
else
set res = res + 8
else
0;
res
);;
/*! \ingroup b3d_camera
* \brief Return the camera parameters.
*
*
* Prototype : fun [SO3_OBJECT] [F F F F]
*
* \param SO3_OBJECT : a camera object.
* \return [F F F F] : the focal length, the FOVy, the near and the far clip distance or nil if error
*/
fun b3d_cameraGetParams (camera)=
if std_objIsNil camera then
(
b3d_errprint iLIB3D_ERR_CAM_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
[SO3CameraGetFocalLenght camera SO3CameraGetFOVy camera SO3CameraGetNearClipDistance camera SO3CameraGetFarClipDistance camera];;
/*! \ingroup b3d_camera
* \brief Set the camera parameters.
*
* Prototype : fun [I F F F F] I
*
* \param I : a camera id.
* \param F : the focal length. If nil, this parameter is unchanged.
* \param F : the FOVy. If nil, this parameter is unchanged.
* \param F : the near clip distance. If nil, this parameter is unchanged.
* \param F : the far clip distance. If nil, this parameter is unchanged.
* \return I : 0 if success or a positive value if error (these values can be combined) :
* - 32 : the 3d session is nil
* - 16 : camera object is nil (the given id should be incorrect)
* - 1 : unable to set the focal length
* - 2 : unable to set the FOVy
* - 4 : unable to set the near clip distance
* - 8 : unable to set the far clip distance
*/
fun b3d_cameraSetParamsFromId (strSession, id, focalLength, fovy, near, far)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
32
)
else
b3d_cameraSetParams b3d_cameraGetFromId strSession id focalLength fovy near far;;
/*! \ingroup b3d_camera
* \brief Set the mode of projection to use with this camera.
*
* Prototype : fun [SO3_OBJECT I] I
*
* \param SO3_OBJECT : a camera object.
* \param I : the choosen mode : SO3_PROJECTION_PERSPECTIVE or SO3_PROJECTION_ORTHOGRAPHIC.
* SO3_PROJECTION_PERSPECTIVE is the default mode. If another value is given, the camera will
* set to this default mode.
* \return I : 0 if success or a positive value if error (these values can be combined) :
* - 1 : camera object is nil
* - 2 : the operation is not performed
*/
fun b3d_cameraSetProjection (camera, mode)=
set mode = std_clampT mode [SO3_PROJECTION_PERSPECTIVE SO3_PROJECTION_ORTHOGRAPHIC] SO3_PROJECTION_PERSPECTIVE;
if std_objIsNil camera then
(
b3d_errprint iLIB3D_ERR_CAM_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
if SO3CameraSetProjectionType camera mode then
0
else
(
b3d_errprint iLIB3D_ERR_CAM_SET iLIB3D_ERR_MASK_ERROR;
2
);;
/*! \ingroup b3d_camera
* \brief Set the mode of projection to use with this camera.
*
* Prototype : fun [SO3_OBJECT I] I
*
* \param SO3_OBJECT : a camera object.
* \param I : the choosen mode : SO3_PROJECTION_PERSPECTIVE or SO3_PROJECTION_ORTHOGRAPHIC.
* SO3_PROJECTION_PERSPECTIVE is the default mode. If another value is given, the camera will
* set to this default mode.
* \return I : 0 if success or a positive value if error (these values can be combined) :
* - 1 : camera object is nil (the given id should be incorrect)
* - 2 : the operation is not performed
* - 3 : the given 3d session is nil
*/
fun b3d_cameraSetProjectionFromId (strSession, id, mode)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
3
)
else
b3d_cameraSetProjection b3d_cameraGetFromId strSession id mode;;
/*! \ingroup b3d_camera
* \brief Get the current mode of projection to use with this camera.
*
* Prototype : fun [SO3_OBJECT] I
*
* \param SO3_OBJECT : a camera object.
* \return I : SO3_PROJECTION_PERSPECTIVE or SO3_PROJECTION_ORTHOGRAPHIC if success or nil if error
*/
fun b3d_cameraGetProjection (camera)=
if std_objIsNil camera then
(
b3d_errprint iLIB3D_ERR_CAM_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3CameraGetProjectionType camera;;
/*! \ingroup b3d_camera
* \brief Sets the orthographic window settings, for use with orthographic rendering only.
*
* Prototype : fun [SO3_OBJECT F F] I
*
* \param SO3_OBJECT : a camera object.
* \param F : the width in world unit.
* \param F : the height in world unit.
* \return I : 0 if success or a positive value if error :
* - 1 : the camera opbject is nil
* - 2 : the mode of the given camera is not 'orthographic'
* - 3 : the operation has not been performed
*/
fun b3d_cameraSetOrthographicWindow (camera, width, height)=
if std_objIsNil camera then
(
b3d_errprint iLIB3D_ERR_CAM_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if SO3_PROJECTION_ORTHOGRAPHIC != b3d_cameraGetProjection camera then
(
b3d_errprint iLIB3D_ERR_CAM_NOTORTHO iLIB3D_ERR_MASK_ERROR;
2
)
else
(
set width = if width <. 1.0 then 1.0 else width;
set height = if height <. 1.0 then 1.0 else height;
if SO3CameraSetOrthoWindow camera width height then
0
else
(
b3d_errprint iLIB3D_ERR_CAM_SET iLIB3D_ERR_MASK_ERROR;
3
)
);;
/*! \ingroup b3d_camera
* \brief Sets the orthographic window settings, for use with orthographic rendering only.
*
* Prototype : fun [SO3_OBJECT F] I
*
* \param SO3_OBJECT : a camera object.
* \param F : a scale ratio.
* \return I : 0 if success or a positive value if error :
* - 1 : the camera opbject is nil
* - 2 : the mode of the given camera is not 'orthographic'
* - 3 : the operation has not been performed
* \remark b3d_cameraSetOrthographicWindow is recommended instead.
* \see b3d_cameraSetOrthographicWindow
*/
fun b3d_cameraSetOrthographicWindowFromScale (camera, scale)=
if std_objIsNil camera then
(
b3d_errprint iLIB3D_ERR_CAM_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else if SO3_PROJECTION_ORTHOGRAPHIC != b3d_cameraGetProjection camera then
(
b3d_errprint iLIB3D_ERR_CAM_NOTORTHO iLIB3D_ERR_MASK_ERROR;
2
)
else
let SO3CameraGetViewport camera -> viewport in
let SO3ViewportGetPixelPositionSize viewport -> [_ _ vw vh] in
let ((itof vw) /. (itof vh)) *. scale -> wscale in
if SO3CameraSetOrthoWindow camera wscale scale then
0
else
(
b3d_errprint iLIB3D_ERR_CAM_SET iLIB3D_ERR_MASK_ERROR;
3
);;
/*! \ingroup b3d_camera
* \brief Get the orthographic window settings, for use with orthographic rendering only.
*
* Prototype : fun [SO3_OBJECT] [F F]
*
* \param SO3_OBJECT : a camera object.
* \return [F F] : the result (width, height) or nil if error
*/
fun b3d_cameraGetOrthographicWindow (camera)=
if std_objIsNil camera then
(
b3d_errprint iLIB3D_ERR_CAM_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else if SO3_PROJECTION_ORTHOGRAPHIC != b3d_cameraGetProjection camera then
(
b3d_errprint iLIB3D_ERR_CAM_NOTORTHO iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3CameraGetOrthoWindow camera;;
/* */
/* */
/* */
/* 3D RESOURCES */
/* */
/* */
/* */
fun b3d_resourcesloadp (pRsc, session, nErr)=
if std_objIsNil pRsc then
nErr
else
let hd pRsc -> [file name type] in
let _checkpack file -> pFile in
if std_objIsNil pFile then
(
b3d_errprintS sprintf "The given 3d resource '%s' is not loaded. Check its pathname !" [file] iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_RSC_NOTFOUND iLIB3D_ERR_MASK_ERROR;
b3d_resourcesloadp tl pRsc session nErr+1
)
else
if std_objIsNil SO3SceneLoadResource session name pFile type then
(
b3d_errprintS sprintf "The given 3d resource '%s' cannot be loaded." [file] iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_RSC_NOTLOADED iLIB3D_ERR_MASK_ERROR;
b3d_resourcesloadp tl pRsc session nErr+1
)
else
b3d_resourcesloadp tl pRsc session nErr;;
/*! \ingroup b3d_rsc
* \brief Load a list of resources in a session.
*
* Prototype : fun [LIB3D_Session [[S S I] r1]] I
*
* \param LIB3D_Session : a session object
* \param [[S S I] r1]] : a list, for each item :
* - a filename,
* - a group name (il nil, this name will be "General")
* - and a flag : SO3_RESOURCE_MESH, SO3_RESOURCE_MATERIAL, SO3_RESOURCE_TEXTURE, SO3_RESOURCE_SKELETON,
* SO3_RESOURCE_GPUPROGRAM, SO3_RESOURCE_HIGHLEVELGPUPROGRAM, SO3_RESOURCE_COMPOSITOR or SO3_RESOURCE_PARTICLE_SYSTEM.
* \return I : 0 if success or another value if error (or not found)
* - (-1) : given 3d session is nil
* - (-2) : given resources are nil
* - a positive value (> 0) : the number of not loaded resources
*/
fun b3d_resourcesLoadP (strSession, pRsc)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
neg 1
)
else if std_objIsNil pRsc then
(
b3d_errprint iLIB3D_MISC_ARG_NIL iLIB3D_ERR_MASK_WARN;
neg 2
)
else
b3d_resourcesloadp pRsc b3d_sessionGet strSession 0;;
/*! \ingroup b3d_rsc
* \brief Return the group name by default. It was created by this library
* when the 3d session is initialized.
*
* Prototype : fun [LIB3D_Session] S
*
* \param LIB3D_Session : a 3d session
* \return S : this group name or nil if error
*/
fun b3d_resourcesGetGroupNameDefault (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strcat strSession.lib3d_sessionName szGROUPINIT;;
/* */
/* */
/* */
/* 3D PHYSICS */
/* */
/* */
/* */
/*! \ingroup b3d_physics
* \brief Set the platform architecture.
*
* Prototype : fun [LIB3D_Session I] I
*
* \param LIB3D_Session : a session object
* \param I : the chosen mode :
* - SO3_PA_DEFAULT
* - SO3_PA_MEDIUM
* - SO3_PA_BEST
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsSetArchi (strSession, mode)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
SO3WorldSetPlateformArchitecture b3d_sessionGet strSession mode;
0
);;
/*! \ingroup b3d_physics
* \brief Get the platform architecture.
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a session object
* \return I : this architecture or nil if error
*/
fun b3d_physicsGetArchi (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3WorldGetPlateformArchitecture b3d_sessionGet strSession;;
/*! \ingroup b3d_physics
* \brief Set the solver model.
*
* Prototype : fun [LIB3D_Session I] I
*
* \param LIB3D_Session : a session object
* \param I : the chosen mode :
* - SO3_SM_EXACT
* - SO3_SM_ADAPTATIVE
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsSetSolver (strSession, mode)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
SO3WorldSetSolverModel b3d_sessionGet strSession mode;
0
);;
/*! \ingroup b3d_physics
* \brief Get the solver model.
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a session object
* \return I : the solver if success or nil if error
*/
fun b3d_physicsGetSolver (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3WorldGetSolverModel b3d_sessionGet strSession;;
/*! \ingroup b3d_physics
* \brief Set the friction model.
*
* Prototype : fun [LIB3D_Session I] I
*
* \param LIB3D_Session : a session object
* \param I : the chosen mode :
* - SO3_SM_EXACT
* - SO3_SM_ADAPTATIVE
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsSetFriction (strSession, mode)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
SO3WorldSetFrictionModel b3d_sessionGet strSession mode;
0
);;
/*! \ingroup b3d_physics
* \brief Get the friction model.
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a session object
* \return I : this friction if success or nil if error
*/
fun b3d_physicsGetFriction (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3WorldGetFrictionModel b3d_sessionGet strSession;;
/*! \ingroup b3d_physics
* \brief Set the world size.
*
* Prototype : fun [LIB3D_Session [F F F]] I
*
* \param LIB3D_Session : a session object
* \param [F F F] : the 3d three compnents (x, y, z)
* If a component is nil, its value will be 1000 (default value)
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsSetSize (strSession, vector)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
let vector -> [fX fY fZ] in
(
if fX == nil then
set fX = 1000.0
else if fY == nil then
set fY = 1000.0
else if fZ == nil then
set fZ = 1000.0
else
0.0;
set strSession.lib3d_physics.lib3d_vWorld = [fX fY fZ];
SO3WorldSetSize b3d_sessionGet strSession [((negf fX) /. 2.0) ((negf fY) /. 2.0) ((negf fZ) /. 2.0)] [(fX /. 2.0) (fY /. 2.0) (fZ /. 2.0)];
0
);;
/*! \ingroup b3d_physics
* \brief Get the world size.
*
* Prototype : fun [LIB3D_Session] [F F F]
*
* \param LIB3D_Session : a session object
* \return [F F F] : the 3d three compnents (x, y, z) if success or nil if error
*/
fun b3d_physicsGetSize (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strSession.lib3d_physics.lib3d_vWorld;;
/*! \ingroup b3d_physics
* \brief Set the fps model.
*
* Prototype : fun [LIB3D_Session I] I
*
* \param LIB3D_Session : a session object
* \param I : the fps (60 by default, if this value is nil)
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsSetFps (strSession, value)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
SO3WorldSetFPS b3d_sessionGet strSession if (value == nil) then 60 else if value < 0 then abs value else value;
0
);;
/*! \ingroup b3d_physics
* \brief Get the fps model.
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a session object
* \return I : the FPS if success or nil if error
*/
fun b3d_physicsGetFps (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
SO3WorldGetFPS b3d_sessionGet strSession;;
/*! \ingroup b3d_physics
* \brief Set the world gravity.
*
* Prototype : fun [LIB3D_Session [F F F]] I
*
* \param LIB3D_Session : a session object
* \param [F F F] : the graivity in the three directions (x, y, z)
* If a component is nil, its value will be 0 (default value)
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsSetGravity (strSession, vector)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
let vector -> [fX fY fZ] in
(
if fX == nil then
set fX = 0.0
else if fY == nil then
set fY = 0.0
else if fZ == nil then
set fZ = 0.0
else
0.0;
set strSession.lib3d_physics.lib3d_iGravityVec = [fX fY fZ];
SO3WorldSetGravity b3d_sessionGet strSession std_vectorMultiplyF [fX fY fZ] std_vectorSet itof iLIB3D_GlobalUnit;
0
);;
/*! \ingroup b3d_physics
* \brief Set the world gravity as on Earth (x = 0, y = 9.81, z = 0).
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a session object
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsSetGravityEarth (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
set strSession.lib3d_physics.lib3d_iGravityVec = [0.0 9.81 0.0];
SO3WorldSetGravity b3d_sessionGet strSession std_vectorMultiplyF [0.0 9.81 0.0] std_vectorSet itof iLIB3D_GlobalUnit;
0
);;
/*! \ingroup b3d_physics
* \brief Get the world gravity.
*
* Prototype : fun [LIB3D_Session] [F F F]
*
* \param LIB3D_Session : a session object
* \return [F F F] : the graivity in the three directions (x, y, z) if success or nil if error
*/
fun b3d_physicsGetGravity (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strSession.lib3d_physics.lib3d_iGravityVec;;
/*! \ingroup b3d_physics
* \brief Set the physics with the default values.
* - Archi plateforme = SO3_PA_DEFAULT
* - Solver = SO3_SM_ADAPTATIVE
* - Friction = SO3_SM_ADAPTATIVE
* - Size = [1000.0 1000.0 1000.0]
* - Fps = 60
* - Gravity = [0.0 0.0 0.0]
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a session object
* \return I : 0 if success or another positive value if error, nil if the given session object is nil
*/
fun b3d_physicsSetDefault (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
(
(b3d_physicsSetArchi strSession SO3_PA_DEFAULT) +
(b3d_physicsSetSolver strSession SO3_SM_ADAPTATIVE) +
(b3d_physicsSetFriction strSession SO3_SM_ADAPTATIVE) +
(b3d_physicsSetSize strSession nil) +
(b3d_physicsSetFps strSession nil) +
(b3d_physicsSetGravity strSession nil)
);;
/*! \ingroup b3d_physics
* \brief Enable / Disable the physics world.
*
* Prototype : fun [LIB3D_Session I] I
*
* \param LIB3D_Session : a session object
* \param I : 1 to enable, 0 to disable
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsEnable (strSession, state)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
SO3WorldSetEnabled
b3d_sessionGet strSession
set strSession.lib3d_physics.lib3d_bEnable = std_clamp state 0 1;
0
);;
/*! \ingroup b3d_physics
* \brief Return if the physics world is enabled / disabled.
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a session object
* \return I : 0 if disable, 1 if enabled or nil if error
*/
fun b3d_physicsIsEnabled (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
set strSession.lib3d_physics.lib3d_bEnable = SO3WorldGetEnabled b3d_sessionGet strSession;;
/*! \ingroup b3d_physics
* \brief Reset the physics world and all bodies states.
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a session object
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsReset (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
SO3WorldReset b3d_sessionGet strSession;
0
);;
/*! \ingroup b3d_physics
* \brief Set the current PRS as initial PRS to all bodies.
*
* Prototype : fun [LIB3D_Session] I
*
* \param LIB3D_Session : a session object
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsInitBodies (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
SO3WorldSetBodiesInitialState b3d_sessionGet strSession;
0
);;
/*! \ingroup b3d_physics
* \brief Show / Hide the debug physics lines.
*
* Prototype : fun [LIB3D_Session I] I
*
* \param LIB3D_Session : a session object
* \param I : 1 to show, 0 to hide
* \return I : 0 if success or 1 if error
*/
fun b3d_physicsDebug (strSession, state)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
1
)
else
(
SO3WorldShowLines
b3d_sessionGet strSession
set strSession.lib3d_physics.lib3d_bDebugPhy = std_clamp state 0 1;
0
);;
/*! \ingroup b3d_physics
* \brief Return if the debug physics lines is shown / hidden.
*
* Prototype : fun [LIB3D_Session I] I
*
* \param LIB3D_Session : a session object
* \param I : 1 to show, 0 to hide
* \return I : 0 if hidden, 1 if shown or nil if error
*/
fun b3d_physicsIsDebug (strSession, state)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strSession.lib3d_physics.lib3d_bDebugPhy;;
/* */
/* */
/* */
/* WINDOW OBJECT */
/* */
/* */
/* */
/*! \ingroup b3d_window
* \brief Get the window from the 3d view
*
* Prototype : fun [LIB3D_View] ObjWin
*
* \param LIB3D_View : a 3d view object
* \return ObjWin : the ObjWin or nil if error
*/
fun b3d_winGetObj (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strView.lib3d_win;;
/*! \ingroup b3d_window
* \brief Get the mother window from the 3d view
*
* Prototype : fun [LIB3D_View] ObjWin
*
* \param LIB3D_View : a 3d view object
* \return ObjWin : the ObjWin or nil if error
*/
fun b3d_winGetMotherObj (strView)=
if std_objIsNil strView then
(
b3d_errprint iLIB3D_ERR_3DVIEW_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
strView.lib3d_motherwin;;
fun b3d_winCBfocus (win, strView)=
exec strView.lib3d_viewCB.lib3dview_cbFocusView with [strView];
0;;
fun b3d_winCBfocuskilled (win, strView)=
exec strView.lib3d_viewCB.lib3dview_cbKillFocusView with [strView];
0;;
fun b3d_winCBsize (win, strView, newW, newH)=
/*if (newH == 0) || (newW == 0) then
b3d_errprint iLIB3D_ERR_WINSIZE iLIB3D_ERR_MASK_WARN
else
nil;
set strView.lib3d_iOldSize = strView.lib3d_iSize;
set strView.lib3d_iSize = [newW newH];*/
exec strView.lib3d_viewCB.lib3dview_cbResizeView with [strView newW newH];;
fun b3d_winCBmove (win, strView, newX, newY)=
set strView.lib3d_iPosition = [newX newY];
exec strView.lib3d_viewCB.lib3dview_cbMoveView with [strView newX newY];;
fun b3d_winCBdestroy (win, strView)=
b3d_viewDestroy strView;;
fun b3d_winmotherCBsize (win, strView, newW, newH)=
if strView.lib3d_iSizeFixed then
1
else
// let _GETwindowPositionSize win -> [x y _ _] in
(
// _SIZEwindow strView.lib3d_win newW newH x y;
b3d_viewSetSize strView newW newH;
0
);;
fun b3d_initwindow (win, strView)=
if win == nil then
(
b3d_errprint iLIB3D_ERR_WINDOW iLIB3D_ERR_MASK_ERROR;
iLIB3D_ERR_WINDOW
)
else
(
_SHOWwindow win WINDOW_HIDDEN;
_CBwinFocus win @b3d_winCBfocus strView;
_CBwinKillFocus win @b3d_winCBfocuskilled strView;
_CBwinSize win @b3d_winCBsize strView;
_CBwinSize strView.lib3d_motherwin @b3d_winmotherCBsize strView;
_CBwinMove win @b3d_winCBmove strView;
_CBwinDestroy win @b3d_winCBdestroy strView;
0
);;
/* */
/* */
/* */
/* INITIALIZATION */
/* */
/* */
/* */
fun b3d_init ()=
let 0 -> res in
res;;
/*! \brief Initialiaze the internal error 3d library
*
* \ingroup b3d_init
*
* This function should be called in a development mode or in a debugging
* mode.
*
* Prototype: fun [S I I] I
*
* \param S : a base name for the log file, if any this file will put in the Logs directory
* \param I : the mask level to set
* \param I : a flag :
* - iLIB3D_LOGTEMPFILE : to put the datas in a temporary file;
* - iLIB3D_LOGHARDFILE : to put the datas in a hard file;
*
* \return I : 0 if success or a positive value if error :
* - 1 : unable to build the internal error structure
* - 2 : unable to set the 'temporary file" mode
* - 3 : unable to create the error manager
* - 4 : unable to open the 'hard file' error manager
**/
fun b3d_initError (logfilename, mask, hardlog)=
set Lib3d_error = std_errOpen mask;
b3d_initerrormsg Lib3d_error;
let if std_objIsNil Lib3d_error then
1
else
if iLIB3D_LOGTEMPFILE == hardlog then
if std_objIsNil std_errSetIsTemp Lib3d_error 1 nil then
2
else
if std_objIsNil std_errOpenLog Lib3d_error nil then
3
else
0
else
if std_objIsNil std_errOpenLogNow Lib3d_error logfilename then
4
else
0
-> res in
if !res then
0
else
(
b3d_errprint iLIB3D_ERR_INIT_ERR iLIB3D_ERR_MASK_ERROR;
res
);;
/*! \brief Initialiaze the 3D View
*
* \ingroup b3d_init
*
* Prototype: fun [Chn ObjWin fun [LIB3D_View I] fun [LIB3D_View] I] I
*
* \param Chn : a channel, typically could be the current channel : _channel
* \param ObjWin : the window mother
* \param fun [LIB3D_View I] I : a function to run immediately after this initialization.
* The supplemental argument is 0 if success or a positive number if error.
* \param fun [LIB3D_View] I : a function to run immediately before the 3d view destruction
*
* \return LIB3D_View : the new 3d view object or nil if error.
**/
fun b3d_initView (ch, winFather, cbInit, cbEnd)=
if (std_objIsNil ch) || (std_objIsNil winFather) then
nil
else
let 0 -> res in
let _GETwindowSizePosition winFather -> [iW iH _ _] in
let _CRwindow ch winFather 0 0 iW iH WN_CHILDINSIDE|WN_NOCAPTION|WN_NOBORDER|WN_DRAGDROP "" -> win in
let SO3BufferCreate ch win 0 0 iW iH -> buffer in
let mkLIB3D_ViewCB [cbInit cbEnd nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil] -> viewcb in
let mkLIB3D_View [
win winFather buffer ch [iW iH] [0 0] [iW iH] nil nil (set iLIB3D_VIEWS = iLIB3D_VIEWS+1;) 0
nil nil
nil
nil nil nil nil
nil
nil nil nil nil
nil
nil nil nil
viewcb
] -> strView in
(
set res = b3d_initbuffer buffer strView;
set res = res + b3d_initwindow win strView;
set strView.lib3d_iCursorDir = [0 0];
set strView.lib3d_iMoveClickStatus =
set strView.lib3d_iClickStatus = iLIB3D_CLICK_NO;
set strView.lib3d_bMouseEnabled =
set strView.lib3d_bKeyboardEnabled =
set strView.lib3d_bPaused = iLIB3D_NULL;
set strView.lib3d_iRenderTick = _tickcount;
exec strView.lib3d_viewCB.lib3dview_cbInit with [strView res];
if !res then
strView
else
nil
);;
/*! \brief Initialiaze the 3D Session. A default camera "camera_init",
* a default group "_defaultResources" and an ambiant light are
* defined too.
*
* \ingroup b3d_init
*
* Prototype: fun [LIB3D_View S fun [LIB3D_Session I] I] LIB3D_Session
*
* \param LIB3D_View : a valide View object
* \param S : the session name
* \ param fun [LIB3D_Session I] I : function called when the initialization is ended.
* The supplemental argument is the result : 0 -> success, other value -> fail.
*
* \return LIB3D_Session : the new 3d session object or nil if error.
**/
fun b3d_initSession (strView, name, cbInit)=
set name = if std_szIsEmpty name then strcat szSESSION itoa _tickcount else name;
let SO3SceneCreate strView.lib3d_channel name -> scn in
if (std_objIsNil strView) || (std_objIsNil scn) then
(
b3d_errprint iLIB3D_ERR_SESSION_CREATE iLIB3D_ERR_MASK_ERROR;
nil
)
else
let mkLIB3D_SessionCB [nil nil nil nil nil nil nil cbInit nil nil] -> cb in
let 0 -> res in
let mkLIB3D_Session [
strView scn nil nil nil neg 1 nil nil nil name
nil nil nil nil 0
nil 0
nil cb
] -> strSession in
(
set strSession.lib3d_sessionCB.lib3d_cbSceneInit = cbInit;
set strView.lib3d_lSessions = strSession :: strView.lib3d_lSessions;
// default resources group
if std_objIsNil SO3GroupCreate scn strcat name szGROUPINIT then
(
b3d_errprintS sprintf "Creating group resource : %s_defaultResources" [name] iLIB3D_ERR_MASK_ERROR;
b3d_errprint iLIB3D_ERR_RSC_GRP_CREATE iLIB3D_ERR_MASK_ERROR;
set res = 1
)
else
0;
// camera and shell camera
let b3d_cameraAdd strSession szCAMERAINIT iLIB3S_ISDEFAULT -> [camObj camNum] in
// let b3d_cameraGetCameraFromId strSession camNum -> camObj in
(
if (std_objIsNil (set strSession.lib3d_shellNavigate = SO3SceneNodeCreate scn "shell_camera";)) || (std_objIsNil camObj) then
(
b3d_errprint iLIB3D_ERR_CAM_SH_CREATE iLIB3D_ERR_MASK_ERROR;
set res = 1
)
else
0;
if !(b3d_objSetPosition strSession.lib3d_shellNavigate [0.0 0.0 0.0]) then
0
else
set res = 1;
if !(b3d_objSetRotatePitch strSession.lib3d_shellNavigate negf 0.5 SO3_LOCAL_TS) then
0
else
set res = 1;
if !(b3d_objLink camObj strSession.lib3d_shellNavigate) then
0
else
set res = 1;
if !(b3d_objSetPosition camObj [0.0 0.0 5.0 *. itof (iLIB3D_GlobalUnit)]) then
0
else
set res = 1;
);
// light
if !(b3d_lightAmbiantSet strSession 0x000000) then
0
else
set res = 1;
exec strSession.lib3d_sessionCB.lib3d_cbSceneInit with [strSession res];
if !res then
(
SO3CbScenePreRender scn @b3d_sessionCBprerender strSession;
SO3CbScenePreRenderPhysic scn @b3d_sessionCBprerenderphysic strSession;
SO3CbScenePreRender2 scn @b3d_sessionCBprerender2 strSession;
SO3CbScenePostRender scn @b3d_sessionCBpostrender strSession;
strSession
)
else
nil
);;
/*! \brief Initialiaze the 3D Physics
* \ingroup b3d_init
*
* Prototype: fun [LIB3D_Session] LIB3D_Physics
*
* \param LIB3D_Session : a valide Session object
*
* \return LIB3D_Physics : the new 3d physics object or nil if error.
**/
fun b3d_initPhysics (strSession)=
if std_objIsNil strSession then
(
b3d_errprint iLIB3D_ERR_SESSION_NIL iLIB3D_ERR_MASK_ERROR;
nil
)
else
let mkLIB3D_Physics [
nil nil
nil 0
] -> strPhysics in
(
set strSession.lib3d_physics = strPhysics;
// to do default ?
strPhysics
);;
/* */
/* */
/* */
/* OTHER FUNCTIONS */
/* */
/* */
/* */
/*! \brief Version's informations about this library
* \ingroup b3d_info
*
* Prototype: fun [] [S S S]
*
* \return [S S S] : versions : SO3Engine, Ogre3d and this library.
**/
fun b3d_infoLib ()=
let SO3GetAPIVersion -> [so3 ogre] in
[so3 ogre iLIB3D_VERSION];;
/*! \brief Get fullscreen video modes supported by the host.
* \ingroup b3d_info
*
* Prototype: fun [] [S r1]
*
* \return [S r1] : supported modes.
**/
fun b3d_infoFullscreenModes ()=
SO3GetFullscreenVideoMode;;
/*! \brief Get multi sampling modes supported by the host.
* \ingroup b3d_info
*
* Prototype: fun [] [S r1]
*
* \return [S r1] : supported modes.
**/
fun b3d_infoMultiSamplingModes (flag)=
SO3GetMultisamplingMode flag;;
/*! \brief This is a conivence function. It returns several infos
* about the system. These infos are the same than provided by
* 'SO3GetGeneralInfo' function but they are formatted.
* \ingroup b3d_info
*
* Prototype: fun [] S
*
* \return S : informations system.
* \remark This function can take few seconds before return.
**/
fun b3d_infoSys ()=
sprintf "Vendor CPU Name : %s\nCPU Name : %s\nNumber of processors : %s\nRAM (total) : %s MB\nOS version : %s\nGraphic device : %s\nGraphic driver : %s\nDirectX version : %s\n" SO3GetGeneralInfo;;