mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 16:14:38 +00:00
Engine directory for ticket #1
This commit is contained in:
parent
352279af7a
commit
7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions
73
Engine/source/scene/mixin/sceneAmbientSoundObject.h
Normal file
73
Engine/source/scene/mixin/sceneAmbientSoundObject.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _SCENEAMBIENTSOUNDOBJECT_H_
|
||||
#define _SCENEAMBIENTSOUNDOBJECT_H_
|
||||
|
||||
|
||||
class SFXAmbience;
|
||||
|
||||
|
||||
/// Template mixin to add ability to hold a custom SFXAmbience to
|
||||
/// a SceneObject.
|
||||
template< typename Base >
|
||||
class SceneAmbientSoundObject : public Base
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Base Parent;
|
||||
|
||||
protected:
|
||||
|
||||
enum
|
||||
{
|
||||
SoundMask = Parent::NextFreeMask << 0, ///< Ambient sound properties have changed.
|
||||
NextFreeMask = Parent::NextFreeMask << 1,
|
||||
};
|
||||
|
||||
/// Ambient sound properties for this space.
|
||||
SFXAmbience* mSoundAmbience;
|
||||
|
||||
public:
|
||||
|
||||
SceneAmbientSoundObject();
|
||||
|
||||
/// Set the ambient sound properties for the space.
|
||||
void setSoundAmbience( SFXAmbience* ambience );
|
||||
|
||||
// SimObject.
|
||||
static void initPersistFields();
|
||||
|
||||
// NetObject.
|
||||
virtual U32 packUpdate( NetConnection* connection, U32 mask, BitStream* stream );
|
||||
virtual void unpackUpdate( NetConnection* connection, BitStream* stream );
|
||||
|
||||
// SceneObject.
|
||||
virtual SFXAmbience* getSoundAmbience() const { return mSoundAmbience; }
|
||||
|
||||
private:
|
||||
|
||||
// Console field getters/setters.
|
||||
static bool _setSoundAmbience( void* object, const char* index, const char* data );
|
||||
};
|
||||
|
||||
#endif // !_SCENEAMBIENTSOUNDOBJECT_H_
|
||||
114
Engine/source/scene/mixin/sceneAmbientSoundObject.impl.h
Normal file
114
Engine/source/scene/mixin/sceneAmbientSoundObject.impl.h
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "scene/mixin/sceneAmbientSoundObject.h"
|
||||
|
||||
#include "T3D/sfx/sfx3DWorld.h"
|
||||
#include "sfx/sfxTypes.h"
|
||||
#include "sfx/sfxAmbience.h"
|
||||
#include "core/stream/bitStream.h"
|
||||
#include "console/engineAPI.h"
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base >
|
||||
SceneAmbientSoundObject< Base >::SceneAmbientSoundObject()
|
||||
: mSoundAmbience( NULL )
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base >
|
||||
void SceneAmbientSoundObject< Base >::initPersistFields()
|
||||
{
|
||||
Parent::addGroup( "Sound" );
|
||||
Parent::addProtectedField( "soundAmbience", TypeSFXAmbienceName, Offset( mSoundAmbience, SceneAmbientSoundObject ),
|
||||
&_setSoundAmbience, &defaultProtectedGetFn,
|
||||
"Ambient sound environment for the space." );
|
||||
Parent::endGroup( "Sound" );
|
||||
|
||||
Parent::initPersistFields();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base >
|
||||
U32 SceneAmbientSoundObject< Base >::packUpdate( NetConnection* connection, U32 mask, BitStream* stream )
|
||||
{
|
||||
U32 retMask = Parent::packUpdate( connection, mask, stream );
|
||||
|
||||
if( stream->writeFlag( mask & SoundMask ) )
|
||||
sfxWrite( stream, mSoundAmbience );
|
||||
|
||||
return retMask;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base >
|
||||
void SceneAmbientSoundObject< Base >::unpackUpdate( NetConnection* connection, BitStream* stream )
|
||||
{
|
||||
Parent::unpackUpdate( connection, stream );
|
||||
|
||||
if( stream->readFlag() ) // SoundMask
|
||||
{
|
||||
SFXAmbience* ambience;
|
||||
|
||||
String errorStr;
|
||||
if( !sfxReadAndResolve( stream, &ambience, errorStr ) )
|
||||
Con::errorf( "SceneAmbientSoundObject::unpackUpdate - bad packet: %s", errorStr.c_str() );
|
||||
else
|
||||
setSoundAmbience( ambience );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base >
|
||||
void SceneAmbientSoundObject< Base >::setSoundAmbience( SFXAmbience* ambience )
|
||||
{
|
||||
if( mSoundAmbience == ambience )
|
||||
return;
|
||||
|
||||
mSoundAmbience = ambience;
|
||||
|
||||
if( this->isServerObject() )
|
||||
this->setMaskBits( SoundMask );
|
||||
else if( this->isProperlyAdded() && gSFX3DWorld )
|
||||
gSFX3DWorld->notifyChanged( this );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base >
|
||||
bool SceneAmbientSoundObject< Base >::_setSoundAmbience( void* object, const char* index, const char* data )
|
||||
{
|
||||
SceneAmbientSoundObject* p = reinterpret_cast< SceneAmbientSoundObject* >( object );
|
||||
SFXAmbience* ambience = EngineUnmarshallData< SFXAmbience* >()( data );
|
||||
p->setSoundAmbience( ambience );
|
||||
return false;
|
||||
}
|
||||
116
Engine/source/scene/mixin/scenePolyhedralObject.h
Normal file
116
Engine/source/scene/mixin/scenePolyhedralObject.h
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _SCENEPOLYHEDRALOBJECT_H_
|
||||
#define _SCENEPOLYHEDRALOBJECT_H_
|
||||
|
||||
#ifndef _MPOLYHEDRON_H_
|
||||
#include "math/mPolyhedron.h"
|
||||
#endif
|
||||
|
||||
|
||||
/// Shared interface for polyhedral objects.
|
||||
struct IScenePolyhedralObject
|
||||
{
|
||||
/// Convert the polyhedral object to a raw polyhedron.
|
||||
virtual AnyPolyhedron ToAnyPolyhedron() const = 0;
|
||||
};
|
||||
|
||||
|
||||
/// Helper template for mixing a polyhedral volume definition into
|
||||
/// the superclass hierarchy of a SceneSpace-derived class.
|
||||
template< typename Base, typename P = Polyhedron >
|
||||
class ScenePolyhedralObject : public Base, public IScenePolyhedralObject
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Base Parent;
|
||||
typedef P PolyhedronType;
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_PLANES = 256,
|
||||
MAX_POINTS = 256,
|
||||
MAX_EDGES = 256
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
enum
|
||||
{
|
||||
PolyMask = Parent::NextFreeMask << 0,
|
||||
NextFreeMask = Parent::NextFreeMask << 1
|
||||
};
|
||||
|
||||
/// Whether the polyhedron corresponds to the object box. If so,
|
||||
/// several things can be fast-tracked. For example, serializing the
|
||||
/// polyhedron is pointless as it can be easily reconstructed from the
|
||||
/// object box on load time. Also, certain operations like containment
|
||||
/// tests have significantly faster formulations for AABBs (given that the
|
||||
/// input data is transformed into object space) than for general
|
||||
/// polyhedrons.
|
||||
bool mIsBox;
|
||||
|
||||
/// The polyhedron that defines the volume of the object.
|
||||
/// @note Defined in object space by default.
|
||||
PolyhedronType mPolyhedron;
|
||||
|
||||
///
|
||||
virtual void _renderObject( ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat );
|
||||
|
||||
public:
|
||||
|
||||
ScenePolyhedralObject()
|
||||
: mIsBox( true ) {}
|
||||
|
||||
ScenePolyhedralObject( const PolyhedronType& polyhedron )
|
||||
: mIsBox( false ),
|
||||
mPolyhedron( polyhedron ) {}
|
||||
|
||||
/// Return the polyhedron that describes the space.
|
||||
const PolyhedronType& getPolyhedron() const { return mPolyhedron; }
|
||||
|
||||
// SimObject.
|
||||
virtual bool onAdd();
|
||||
virtual void writeFields( Stream& stream, U32 tabStop );
|
||||
virtual bool writeField( StringTableEntry name, const char* value );
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
// NetObject.
|
||||
virtual U32 packUpdate( NetConnection* connection, U32 mask, BitStream* stream );
|
||||
virtual void unpackUpdate( NetConnection* connection, BitStream* stream );
|
||||
|
||||
// SceneObject.
|
||||
virtual bool containsPoint( const Point3F& point );
|
||||
|
||||
// IScenePolyhedralObject.
|
||||
virtual AnyPolyhedron ToAnyPolyhedron() const { return getPolyhedron(); }
|
||||
|
||||
private:
|
||||
|
||||
static bool _setPlane( void* object, const char* index, const char* data );
|
||||
static bool _setPoint( void* object, const char* index, const char* data );
|
||||
static bool _setEdge( void* object, const char* index, const char* data );
|
||||
};
|
||||
|
||||
#endif // !_SCENEPOLYHEDRALOBJECT_H_
|
||||
395
Engine/source/scene/mixin/scenePolyhedralObject.impl.h
Normal file
395
Engine/source/scene/mixin/scenePolyhedralObject.impl.h
Normal file
|
|
@ -0,0 +1,395 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "scene/mixin/scenePolyhedralObject.h"
|
||||
|
||||
#include "console/consoleTypes.h"
|
||||
#include "gfx/gfxDrawUtil.h"
|
||||
#include "gfx/gfxTransformSaver.h"
|
||||
#include "core/stream/bitStream.h"
|
||||
#include "math/mathIO.h"
|
||||
|
||||
#if 0 // Enable when enabling debug rendering below.
|
||||
#include "scene/sceneRenderState.h"
|
||||
#include "gfx/sim/debugDraw.h"
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
void ScenePolyhedralObject< Base, P >::initPersistFields()
|
||||
{
|
||||
Parent::addGroup( "Internal" );
|
||||
|
||||
Parent::addProtectedField( "plane", TypeRealString, NULL,
|
||||
&_setPlane, &defaultProtectedGetFn,
|
||||
"For internal use only.",
|
||||
AbstractClassRep::FIELD_HideInInspectors );
|
||||
Parent::addProtectedField( "point", TypeRealString, NULL,
|
||||
&_setPoint, &defaultProtectedGetFn,
|
||||
"For internal use only.",
|
||||
AbstractClassRep::FIELD_HideInInspectors );
|
||||
Parent::addProtectedField( "edge", TypeRealString, NULL,
|
||||
&_setEdge, &defaultProtectedGetFn,
|
||||
"For internal use only.",
|
||||
AbstractClassRep::FIELD_HideInInspectors );
|
||||
|
||||
Parent::endGroup( "Internal" );
|
||||
|
||||
Parent::initPersistFields();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
bool ScenePolyhedralObject< Base, P >::onAdd()
|
||||
{
|
||||
// If no polyhedron has been initialized for the zone, default
|
||||
// to object box. Do this before calling the parent's onAdd()
|
||||
// so that we set the object box correctly.
|
||||
|
||||
if( mPolyhedron.getNumPlanes() == 0 )
|
||||
{
|
||||
mPolyhedron.buildBox( MatrixF::Identity, this->getObjBox() );
|
||||
mIsBox = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mIsBox = false;
|
||||
|
||||
// Compute object-space bounds from polyhedron.
|
||||
this->mObjBox = mPolyhedron.getBounds();
|
||||
}
|
||||
|
||||
if( !Parent::onAdd() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
bool ScenePolyhedralObject< Base, P >::containsPoint( const Point3F& point )
|
||||
{
|
||||
// If our shape is the OBB, use the default implementation
|
||||
// inherited from SceneObject.
|
||||
|
||||
if( this->mIsBox )
|
||||
return Parent::containsPoint( point );
|
||||
|
||||
// Take the point into our local object space.
|
||||
|
||||
Point3F p = point;
|
||||
this->getWorldTransform().mulP( p );
|
||||
p.convolveInverse( this->getScale() );
|
||||
|
||||
// See if the polyhedron contains the point.
|
||||
|
||||
return mPolyhedron.isContained( p );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
void ScenePolyhedralObject< Base, P >::_renderObject( ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat )
|
||||
{
|
||||
if( overrideMat )
|
||||
return;
|
||||
|
||||
if( this->mIsBox )
|
||||
Parent::_renderObject( ri, state, overrideMat );
|
||||
else if( !this->mEditorRenderMaterial )
|
||||
{
|
||||
GFXTransformSaver saver;
|
||||
|
||||
MatrixF mat = this->getRenderTransform();
|
||||
mat.scale( this->getScale() );
|
||||
|
||||
GFX->multWorld( mat );
|
||||
|
||||
GFXStateBlockDesc desc;
|
||||
desc.setZReadWrite( true, false );
|
||||
desc.setBlend( true );
|
||||
desc.setCullMode( GFXCullNone );
|
||||
|
||||
GFX->getDrawUtil()->drawPolyhedron( desc, mPolyhedron, this->_getDefaultEditorSolidColor() );
|
||||
|
||||
// Render black wireframe.
|
||||
|
||||
desc.setFillModeWireframe();
|
||||
GFX->getDrawUtil()->drawPolyhedron( desc, mPolyhedron, this->_getDefaultEditorWireframeColor() );
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO: render polyhedron with material
|
||||
}
|
||||
|
||||
// Debug rendering.
|
||||
|
||||
#if 0
|
||||
if( state->isDiffusePass() )
|
||||
DebugDrawer::get()->drawPolyhedronDebugInfo( mPolyhedron, this->getTransform(), this->getScale() );
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
U32 ScenePolyhedralObject< Base, P >::packUpdate( NetConnection* connection, U32 mask, BitStream* stream )
|
||||
{
|
||||
U32 retMask = Parent::packUpdate( connection, mask, stream );
|
||||
|
||||
if( stream->writeFlag( !mIsBox && ( mask & PolyMask ) ) )
|
||||
{
|
||||
// Write planes.
|
||||
|
||||
const U32 numPlanes = mPolyhedron.getNumPlanes();
|
||||
const typename PolyhedronType::PlaneType* planes = mPolyhedron.getPlanes();
|
||||
|
||||
stream->writeInt( numPlanes, 8 );
|
||||
for( U32 i = 0; i < numPlanes; ++ i )
|
||||
mathWrite( *stream, planes[ i ] );
|
||||
|
||||
// Write points.
|
||||
|
||||
const U32 numPoints = mPolyhedron.getNumPoints();
|
||||
const typename PolyhedronType::PointType* points = mPolyhedron.getPoints();
|
||||
|
||||
stream->writeInt( numPoints, 8 );
|
||||
for( U32 i = 0; i < numPoints; ++ i )
|
||||
mathWrite( *stream, points[ i ] );
|
||||
|
||||
// Write edges.
|
||||
|
||||
const U32 numEdges = mPolyhedron.getNumEdges();
|
||||
const typename PolyhedronType::EdgeType* edges = mPolyhedron.getEdges();
|
||||
|
||||
stream->writeInt( numEdges, 8 );
|
||||
for( U32 i = 0; i < numEdges; ++ i )
|
||||
{
|
||||
const typename PolyhedronType::EdgeType& edge = edges[ i ];
|
||||
|
||||
stream->writeInt( edge.face[ 0 ], 8 );
|
||||
stream->writeInt( edge.face[ 1 ], 8 );
|
||||
stream->writeInt( edge.vertex[ 0 ], 8 );
|
||||
stream->writeInt( edge.vertex[ 1 ], 8 );
|
||||
}
|
||||
}
|
||||
|
||||
return retMask;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
void ScenePolyhedralObject< Base, P >::unpackUpdate( NetConnection* connection, BitStream* stream )
|
||||
{
|
||||
Parent::unpackUpdate( connection, stream );
|
||||
|
||||
if( stream->readFlag() ) // PolyMask
|
||||
{
|
||||
// Read planes.
|
||||
|
||||
const U32 numPlanes = stream->readInt( 8 );
|
||||
mPolyhedron.planeList.setSize( numPlanes );
|
||||
|
||||
for( U32 i = 0; i < numPlanes; ++ i )
|
||||
mathRead( *stream, &mPolyhedron.planeList[ i ] );
|
||||
|
||||
// Read points.
|
||||
|
||||
const U32 numPoints = stream->readInt( 8 );
|
||||
mPolyhedron.pointList.setSize( numPoints );
|
||||
|
||||
for( U32 i = 0; i < numPoints; ++ i )
|
||||
mathRead( *stream, &mPolyhedron.pointList[ i ] );
|
||||
|
||||
// Read edges.
|
||||
|
||||
const U32 numEdges = stream->readInt( 8 );
|
||||
mPolyhedron.edgeList.setSize( numEdges );
|
||||
|
||||
for( U32 i = 0; i < numEdges; ++ i )
|
||||
{
|
||||
typename PolyhedronType::EdgeType& edge = mPolyhedron.edgeList[ i ];
|
||||
|
||||
edge.face[ 0 ] = stream->readInt( 8 );
|
||||
edge.face[ 1 ] = stream->readInt( 8 );
|
||||
edge.vertex[ 0 ] = stream->readInt( 8 );
|
||||
edge.vertex[ 1 ] = stream->readInt( 8 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
bool ScenePolyhedralObject< Base, P >::writeField( StringTableEntry name, const char* value )
|
||||
{
|
||||
StringTableEntry sPlane = StringTable->insert( "plane" );
|
||||
StringTableEntry sPoint = StringTable->insert( "point" );
|
||||
StringTableEntry sEdge = StringTable->insert( "edge" );
|
||||
|
||||
if( name == sPlane || name == sPoint || name == sEdge )
|
||||
return false;
|
||||
|
||||
return Parent::writeField( name, value );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
void ScenePolyhedralObject< Base, P >::writeFields( Stream& stream, U32 tabStop )
|
||||
{
|
||||
Parent::writeFields( stream, tabStop );
|
||||
|
||||
// If the polyhedron is the same as our object box,
|
||||
// don't bother writing out the planes and points.
|
||||
|
||||
if( mIsBox )
|
||||
return;
|
||||
|
||||
stream.write( 2, "\r\n" );
|
||||
|
||||
// Write all planes.
|
||||
|
||||
const U32 numPlanes = mPolyhedron.getNumPlanes();
|
||||
for( U32 i = 0; i < numPlanes; ++ i )
|
||||
{
|
||||
const PlaneF& plane = mPolyhedron.getPlanes()[ i ];
|
||||
|
||||
stream.writeTabs( tabStop );
|
||||
|
||||
char buffer[ 1024 ];
|
||||
dSprintf( buffer, sizeof( buffer ), "plane = \"%g %g %g %g\";",
|
||||
plane.x, plane.y, plane.z, plane.d
|
||||
);
|
||||
|
||||
stream.writeLine( reinterpret_cast< const U8* >( buffer ) );
|
||||
}
|
||||
|
||||
// Write all points.
|
||||
|
||||
const U32 numPoints = mPolyhedron.getNumPoints();
|
||||
for( U32 i = 0; i < numPoints; ++ i )
|
||||
{
|
||||
const Point3F& point = mPolyhedron.getPoints()[ i ];
|
||||
|
||||
stream.writeTabs( tabStop );
|
||||
|
||||
char buffer[ 1024 ];
|
||||
dSprintf( buffer, sizeof( buffer ), "point = \"%g %g %g\";",
|
||||
point.x, point.y, point.z
|
||||
);
|
||||
|
||||
stream.writeLine( reinterpret_cast< const U8* >( buffer ) );
|
||||
}
|
||||
|
||||
// Write all edges.
|
||||
|
||||
const U32 numEdges = mPolyhedron.getNumEdges();
|
||||
for( U32 i = 0; i < numEdges; ++ i )
|
||||
{
|
||||
const PolyhedronData::Edge& edge = mPolyhedron.getEdges()[ i ];
|
||||
|
||||
stream.writeTabs( tabStop );
|
||||
|
||||
char buffer[ 1024 ];
|
||||
dSprintf( buffer, sizeof( buffer ), "edge = \"%i %i %i %i\";",
|
||||
edge.face[ 0 ], edge.face[ 1 ],
|
||||
edge.vertex[ 0 ], edge.vertex[ 1 ]
|
||||
);
|
||||
|
||||
stream.writeLine( reinterpret_cast< const U8* >( buffer ) );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
bool ScenePolyhedralObject< Base, P >::_setPlane( void* object, const char* index, const char* data )
|
||||
{
|
||||
ScenePolyhedralObject* obj = reinterpret_cast< ScenePolyhedralObject* >( object );
|
||||
|
||||
PlaneF plane;
|
||||
|
||||
dSscanf( data, "%g %g %g %g",
|
||||
&plane.x,
|
||||
&plane.y,
|
||||
&plane.z,
|
||||
&plane.d
|
||||
);
|
||||
|
||||
obj->mPolyhedron.planeList.push_back( plane );
|
||||
obj->setMaskBits( PolyMask );
|
||||
obj->mIsBox = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
bool ScenePolyhedralObject< Base, P >::_setPoint( void* object, const char* index, const char* data )
|
||||
{
|
||||
ScenePolyhedralObject* obj = reinterpret_cast< ScenePolyhedralObject* >( object );
|
||||
|
||||
Point3F point;
|
||||
|
||||
dSscanf( data, "%g %g %g %g",
|
||||
&point[ 0 ],
|
||||
&point[ 1 ],
|
||||
&point[ 2 ]
|
||||
);
|
||||
|
||||
obj->mPolyhedron.pointList.push_back( point );
|
||||
obj->setMaskBits( PolyMask );
|
||||
obj->mIsBox = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template< typename Base, typename P >
|
||||
bool ScenePolyhedralObject< Base, P >::_setEdge( void* object, const char* index, const char* data )
|
||||
{
|
||||
ScenePolyhedralObject* obj = reinterpret_cast< ScenePolyhedralObject* >( object );
|
||||
|
||||
PolyhedronData::Edge edge;
|
||||
|
||||
dSscanf( data, "%i %i %i %i",
|
||||
&edge.face[ 0 ],
|
||||
&edge.face[ 1 ],
|
||||
&edge.vertex[ 0 ],
|
||||
&edge.vertex[ 1 ]
|
||||
);
|
||||
|
||||
obj->mPolyhedron.edgeList.push_back( edge );
|
||||
obj->setMaskBits( PolyMask );
|
||||
obj->mIsBox = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue