Adds FIELD_SpecialtyArrayField field type and handling for it in PersistenceManager, as well as a use-case of it for the surface field in ConvexShape

This commit is contained in:
JeffR 2024-12-07 13:20:30 -06:00
parent e56df92002
commit 61d9e82ce5
9 changed files with 449 additions and 183 deletions

View file

@ -296,6 +296,9 @@ StringTableEntry Scene::getLevelAsset()
bool Scene::saveScene(StringTableEntry fileName)
{
if (!isServerObject())
return false;
//So, we ultimately want to not only save out the level, but also collate all the assets utilized
//by the static objects in the scene so we can have those before we parse the level file itself
//Useful for preloading or stat tracking
@ -310,9 +313,7 @@ bool Scene::saveScene(StringTableEntry fileName)
{
if((*itr)->isMethod("onSaving"))
{
ConsoleValue vars[3];
vars[2].setString(fileName);
Con::execute((*itr), 3, vars);
Con::executef((*itr), "onSaving", fileName);
}
}

View file

@ -411,6 +411,9 @@ void SubScene::unload()
bool SubScene::save()
{
if (!isServerObject())
return false;
//if there's nothing TO save, don't bother
if (size() == 0 || !isLoaded())
return false;
@ -432,14 +435,20 @@ bool SubScene::save()
for (SimGroupIterator itr(this); *itr; ++itr)
{
if ((*itr)->isMethod("onSaving"))
{
ConsoleValue vars[3];
vars[2].setString(mLevelAssetId);
Con::execute((*itr), 3, vars);
}
SimObject* childObj = (*itr);
prMger.setDirty((*itr), levelPath);
if (!prMger.isDirty(childObj))
{
if ((*itr)->isMethod("onSaving"))
{
Con::executef((*itr), "onSaving", mLevelAssetId);
}
if (childObj->getGroup() == this)
{
prMger.setDirty((*itr), levelPath);
}
}
}
prMger.saveDirty();

View file

@ -317,10 +317,10 @@ void ConvexShape::initPersistFields()
addGroup( "Internal" );
addProtectedField( "surface", TypeRealString, 0, &protectedSetSurface, &defaultProtectedGetFn,
"Do not modify, for internal use.", AbstractClassRep::FIELD_HideInInspectors );
"Do not modify, for internal use.", AbstractClassRep::FIELD_HideInInspectors | AbstractClassRep::FIELD_SpecialtyArrayField);
addProtectedField( "surfaceTexture", TypeRealString, 0, &protectedSetSurfaceTexture, &defaultProtectedGetFn,
"Do not modify, for internal use.", AbstractClassRep::FIELD_HideInInspectors );
"Do not modify, for internal use.", AbstractClassRep::FIELD_HideInInspectors | AbstractClassRep::FIELD_SpecialtyArrayField);
endGroup( "Internal" );
@ -498,6 +498,55 @@ bool ConvexShape::writeField( StringTableEntry fieldname, const char *value )
return Parent::writeField( fieldname, value );
}
U32 ConvexShape::getSpecialFieldSize(StringTableEntry fieldName)
{
if (fieldName == StringTable->insert("surface") || fieldName == StringTable->insert("surfaceTexture"))
{
return mSurfaces.size();
}
return 0;
}
const char* ConvexShape::getSpecialFieldOut(StringTableEntry fieldName, const U32& index)
{
if (index >= smMaxSurfaces)
return NULL;
if (fieldName == StringTable->insert("surface"))
{
if(index >= mSurfaces.size())
return NULL;
const MatrixF& mat = mSurfaces[index];
QuatF quat(mat);
Point3F pos(mat.getPosition());
char buffer[1024];
dMemset(buffer, 0, 1024);
dSprintf(buffer, 1024, "%g %g %g %g %g %g %g %i %g %g %g %g %g %i %i",
quat.x, quat.y, quat.z, quat.w, pos.x, pos.y, pos.z, mSurfaceUVs[index].matID,
mSurfaceUVs[index].offset.x, mSurfaceUVs[index].offset.y, mSurfaceUVs[index].scale.x,
mSurfaceUVs[index].scale.y, mSurfaceUVs[index].zRot, mSurfaceUVs[index].horzFlip, mSurfaceUVs[index].vertFlip);
return StringTable->insert(buffer);
}
else if (fieldName == StringTable->insert("surfaceTexture"))
{
if (index >= mSurfaceTextures.size())
return NULL;
char buffer[1024];
dMemset(buffer, 0, 1024);
dSprintf(buffer, 1024, "%s", mSurfaceTextures[index].getMaterial());
return StringTable->insert(buffer);
}
}
void ConvexShape::onScaleChanged()
{
if ( isProperlyAdded() )

View file

@ -83,7 +83,7 @@ class ConvexShape : public SceneObject
typedef SceneObject Parent;
friend class GuiConvexEditorCtrl;
friend class GuiConvexEditorUndoAction;
friend class ConvexShapeCollisionConvex;
friend class ConvexShapeCollisionConvex;
public:
@ -113,10 +113,10 @@ public:
U32 p1;
U32 p2;
U32 operator []( U32 index ) const
U32 operator [](U32 index) const
{
AssertFatal( index >= 0 && index <= 2, "index out of range" );
return *( (&p0) + index );
AssertFatal(index >= 0 && index <= 2, "index out of range");
return *((&p0) + index);
}
};
@ -126,23 +126,23 @@ public:
Vector< U32 > points;
Vector< U32 > winding;
Vector< Point2F > texcoords;
Vector< Triangle > triangles;
Vector< Triangle > triangles;
Point3F tangent;
Point3F normal;
Point3F centroid;
F32 area;
S32 id;
};
};
struct surfaceMaterial
{
// The name of the Material we will use for rendering
DECLARE_MATERIALASSET(surfaceMaterial, Material);
DECLARE_ASSET_SETGET(surfaceMaterial, Material);
// The actual Material instance
BaseMatInstance* materialInst;
BaseMatInstance* materialInst;
surfaceMaterial()
{
@ -174,26 +174,26 @@ public:
U32 mPrimCount;
};
struct Geometry
{
void generate(const Vector< PlaneF > &planes, const Vector< Point3F > &tangents, const Vector< surfaceMaterial > surfaceTextures, const Vector< Point2F > texOffset, const Vector< Point2F > texScale, const Vector< bool > horzFlip, const Vector< bool > vertFlip);
struct Geometry
{
void generate(const Vector< PlaneF >& planes, const Vector< Point3F >& tangents, const Vector< surfaceMaterial > surfaceTextures, const Vector< Point2F > texOffset, const Vector< Point2F > texScale, const Vector< bool > horzFlip, const Vector< bool > vertFlip);
Vector< Point3F > points;
Vector< Face > faces;
};
Vector< Point3F > points;
Vector< Face > faces;
};
static bool smRenderEdges;
static bool smRenderEdges;
// To prevent bitpack overflows.
// This is only indirectly enforced by trucation when serializing.
static const S32 smMaxSurfaces = 100;
public:
ConvexShape();
virtual ~ConvexShape();
DECLARE_CONOBJECT( ConvexShape );
DECLARE_CONOBJECT(ConvexShape);
DECLARE_CATEGORY("Object \t Simple");
// ConsoleObject
@ -203,73 +203,76 @@ public:
void inspectPostApply() override;
bool onAdd() override;
void onRemove() override;
void writeFields(Stream &stream, U32 tabStop) override;
bool writeField( StringTableEntry fieldname, const char *value ) override;
void writeFields(Stream& stream, U32 tabStop) override;
bool writeField(StringTableEntry fieldname, const char* value) override;
U32 getSpecialFieldSize(StringTableEntry fieldName) override;
const char* getSpecialFieldOut(StringTableEntry fieldName, const U32& index) override;
// NetObject
U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream ) override;
void unpackUpdate( NetConnection *conn, BitStream *stream ) override;
U32 packUpdate(NetConnection* conn, U32 mask, BitStream* stream) override;
void unpackUpdate(NetConnection* conn, BitStream* stream) override;
// SceneObject
void onScaleChanged() override;
void setTransform( const MatrixF &mat ) override;
void prepRenderImage( SceneRenderState *state ) override;
void buildConvex( const Box3F &box, Convex *convex ) override;
bool buildPolyList( PolyListContext context, AbstractPolyList *polyList, const Box3F &box, const SphereF &sphere ) override;
bool buildExportPolyList(ColladaUtils::ExportData* exportData, const Box3F &box, const SphereF &) override;
bool castRay( const Point3F &start, const Point3F &end, RayInfo *info ) override;
bool collideBox( const Point3F &start, const Point3F &end, RayInfo *info ) override;
void setTransform(const MatrixF& mat) override;
void prepRenderImage(SceneRenderState* state) override;
void buildConvex(const Box3F& box, Convex* convex) override;
bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F& box, const SphereF& sphere) override;
bool buildExportPolyList(ColladaUtils::ExportData* exportData, const Box3F& box, const SphereF&) override;
bool castRay(const Point3F& start, const Point3F& end, RayInfo* info) override;
bool collideBox(const Point3F& start, const Point3F& end, RayInfo* info) override;
void updateBounds( bool recenter );
void updateBounds(bool recenter);
void recenter();
/// Geometry access.
/// @{
MatrixF getSurfaceWorldMat( S32 faceid, bool scaled = false ) const;
void cullEmptyPlanes( Vector< U32 > *removedPlanes );
void exportToCollada();
void resizePlanes( const Point3F &size );
void getSurfaceLineList( S32 surfId, Vector< Point3F > &lineList );
Geometry& getGeometry() { return mGeometry; }
Vector<MatrixF>& getSurfaces() { return mSurfaces; }
void getSurfaceTriangles( S32 surfId, Vector< Point3F > *outPoints, Vector< Point2F > *outCoords, bool worldSpace );
MatrixF getSurfaceWorldMat(S32 faceid, bool scaled = false) const;
void cullEmptyPlanes(Vector< U32 >* removedPlanes);
void exportToCollada();
void resizePlanes(const Point3F& size);
void getSurfaceLineList(S32 surfId, Vector< Point3F >& lineList);
Geometry& getGeometry() { return mGeometry; }
Vector<MatrixF>& getSurfaces() { return mSurfaces; }
void getSurfaceTriangles(S32 surfId, Vector< Point3F >* outPoints, Vector< Point2F >* outCoords, bool worldSpace);
/// @}
/// Geometry Visualization.
/// @{
void renderFaceEdges( S32 faceid, const ColorI &color = ColorI::WHITE, F32 lineWidth = 1.0f );
void renderFaceEdges(S32 faceid, const ColorI& color = ColorI::WHITE, F32 lineWidth = 1.0f);
/// @}
String getMaterialName() { return mMaterialName; }
String getMaterialName() { return mMaterialName; }
protected:
void _updateMaterial();
void _updateGeometry( bool updateCollision = false );
void _updateGeometry(bool updateCollision = false);
void _updateCollision();
void _export( OptimizedPolyList *plist, const Box3F &box, const SphereF &sphere );
void _export(OptimizedPolyList* plist, const Box3F& box, const SphereF& sphere);
void _renderDebug( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *mat );
void _renderDebug(ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* mat);
static S32 QSORT_CALLBACK _comparePlaneDist( const void *a, const void *b );
static S32 QSORT_CALLBACK _comparePlaneDist(const void* a, const void* b);
static bool protectedSetSurface( void *object, const char *index, const char *data );
static bool protectedSetSurface(void* object, const char* index, const char* data);
static bool protectedSetSurfaceTexture(void* object, const char* index, const char* data);
static bool protectedSetSurfaceUV(void* object, const char* index, const char* data);
static bool protectedSetSurfaceTexture( void *object, const char *index, const char *data );
static bool protectedSetSurfaceUV(void *object, const char *index, const char *data);
protected:
DECLARE_MATERIALASSET(ConvexShape, Material);
DECLARE_ASSET_SETGET(ConvexShape, Material);
// The actual Material instance
BaseMatInstance* mMaterialInst;
BaseMatInstance* mMaterialInst;
// The GFX vertex and primitive buffers
/*GFXVertexBufferHandle< VertexType > mVertexBuffer;
@ -278,7 +281,7 @@ protected:
U32 mVertCount;
U32 mPrimCount;*/
Geometry mGeometry;
Geometry mGeometry;
Vector< PlaneF > mPlanes;
@ -291,14 +294,14 @@ protected:
Vector< surfaceUV > mSurfaceUVs;
Vector< surfaceBuffers > mSurfaceBuffers;
Convex *mConvexList;
Convex* mConvexList;
PhysicsBody *mPhysicsRep;
PhysicsBody* mPhysicsRep;
/// Geometry visualization
/// @{
F32 mNormalLength;
F32 mNormalLength;
/// @}