finish fill mode setting

now fill mode actually takes effect and changes the fill mode type used to generate the convex hull
This commit is contained in:
marauder2k7 2024-05-16 04:32:14 +01:00
parent 48848f9706
commit 25b0c5e2b1
4 changed files with 46 additions and 33 deletions

View file

@ -183,7 +183,7 @@ public:
void fit26_DOP(); void fit26_DOP();
// Convex Hulls // Convex Hulls
void fitConvexHulls( U32 depth, F32 minPercentage, U32 maxHulls, U32 maxHullVerts, void fitConvexHulls( U32 depth, U32 fillType, F32 minPercentage, U32 maxHulls, U32 maxHullVerts,
F32 boxMaxError, F32 sphereMaxError, F32 capsuleMaxError ); F32 boxMaxError, F32 sphereMaxError, F32 capsuleMaxError );
}; };
@ -691,11 +691,11 @@ void MeshFit::fitK_DOP( const Vector<Point3F>& planes )
//--------------------------- //---------------------------
// Best-fit set of convex hulls // Best-fit set of convex hulls
void MeshFit::fitConvexHulls( U32 depth, F32 minPercentage, U32 maxHulls, U32 maxHullVerts, void MeshFit::fitConvexHulls( U32 depth, U32 fillType, F32 minPercentage, U32 maxHulls, U32 maxHullVerts,
F32 boxMaxError, F32 sphereMaxError, F32 capsuleMaxError ) F32 boxMaxError, F32 sphereMaxError, F32 capsuleMaxError )
{ {
VHACD::IVHACD::Parameters p; VHACD::IVHACD::Parameters p;
p.m_fillMode = VHACD::FillMode::FLOOD_FILL; p.m_fillMode = (VHACD::FillMode)fillType;
p.m_maxNumVerticesPerCH = maxHullVerts; p.m_maxNumVerticesPerCH = maxHullVerts;
p.m_shrinkWrap = true; p.m_shrinkWrap = true;
p.m_maxRecursionDepth = depth; p.m_maxRecursionDepth = depth;
@ -929,8 +929,8 @@ DefineTSShapeConstructorMethod( addPrimitive, bool, ( const char* meshName, cons
return true; return true;
}} }}
DefineTSShapeConstructorMethod( addCollisionDetail, bool, ( S32 size, const char* type, const char* target, S32 depth, F32 minPercentage, S32 maxHulls, S32 maxVerts, F32 boxMaxError, F32 sphereMaxError, F32 capsuleMaxError ), ( 4, 30, 30, 32, 0, 0, 0 ), DefineTSShapeConstructorMethod( addCollisionDetail, bool, ( S32 size, const char* type, const char* target, const char* fillMode, S32 depth, F32 minPercentage, S32 maxHulls, S32 maxVerts, F32 boxMaxError, F32 sphereMaxError, F32 capsuleMaxError ), ( "flood fill", 4, 10, 30, 32, 0, 0, 0),
( size, type, target, depth, minPercentage, maxHulls, maxVerts, boxMaxError, sphereMaxError, capsuleMaxError ), false, ( size, type, target, fillMode, depth, minPercentage, maxHulls, maxVerts, boxMaxError, sphereMaxError, capsuleMaxError ), false,
"Autofit a mesh primitive or set of convex hulls to the shape geometry. Hulls " "Autofit a mesh primitive or set of convex hulls to the shape geometry. Hulls "
"may optionally be converted to boxes, spheres and/or capsules based on their " "may optionally be converted to boxes, spheres and/or capsules based on their "
"volume.\n" "volume.\n"
@ -984,7 +984,13 @@ DefineTSShapeConstructorMethod( addCollisionDetail, bool, ( S32 size, const char
fit.fit26_DOP(); fit.fit26_DOP();
else if ( !dStricmp( type, "convex hulls" ) ) else if ( !dStricmp( type, "convex hulls" ) )
{ {
fit.fitConvexHulls( depth, minPercentage, maxHulls, maxVerts,
U32 fillType = 0;
if (!dStricmp(fillMode, "surface only"))
fillType = 1;
if (!dStricmp(fillMode, "raycast fill"))
fillType = 2;
fit.fitConvexHulls( depth, fillType, minPercentage, maxHulls, maxVerts,
boxMaxError, sphereMaxError, capsuleMaxError ); boxMaxError, sphereMaxError, capsuleMaxError );
} }
else else

View file

@ -100,7 +100,7 @@ public:
{ {
eCommandType type; // Command type eCommandType type; // Command type
StringTableEntry name; // Command name StringTableEntry name; // Command name
static const U32 MAX_ARGS = 10; static const U32 MAX_ARGS = 11;
String argv[MAX_ARGS]; // Command arguments String argv[MAX_ARGS]; // Command arguments
S32 argc; // Number of arguments S32 argc; // Number of arguments
Command() : type(CmdInvalid), name(0), argc(0) { } Command() : type(CmdInvalid), name(0), argc(0) { }
@ -315,7 +315,7 @@ public:
const char* getImposterSettings(S32 index); const char* getImposterSettings(S32 index);
S32 addImposter(S32 size, S32 equatorSteps, S32 polarSteps, S32 dl, S32 dim, bool includePoles, F32 polarAngle); S32 addImposter(S32 size, S32 equatorSteps, S32 polarSteps, S32 dl, S32 dim, bool includePoles, F32 polarAngle);
bool removeImposter(); bool removeImposter();
bool addCollisionDetail(S32 size, const char* type, const char* target, S32 depth = 4, F32 minPercentage = 10.0f, S32 maxHull = 30, S32 maxVerts = 32, F32 boxMaxError = 0, F32 sphereMaxError = 0, F32 capsuleMaxError = 0); bool addCollisionDetail(S32 size, const char* type, const char* target, const char* fillMode = "flood fill", S32 depth = 4, F32 minPercentage = 10.0f, S32 maxHull = 30, S32 maxVerts = 32, F32 boxMaxError = 0, F32 sphereMaxError = 0, F32 capsuleMaxError = 0);
///@} ///@}
/// @name Sequences /// @name Sequences

View file

@ -2936,14 +2936,17 @@ function ShapeEdColWindow::onWake( %this )
%this-->colType.add( "26-DOP" ); %this-->colType.add( "26-DOP" );
%this-->colType.add( "Convex Hulls" ); %this-->colType.add( "Convex Hulls" );
%this-->fillMode.clear();
%this-->fillMode.add("Flood fill"); %this-->fillMode.add("Flood fill");
%this-->fillMode.add("Surface only"); %this-->fillMode.add("Surface only");
%this-->fillMode.add("Raycast Fill"); %this-->fillMode.add("Raycast Fill");
%this-->fillMode.setSelected( %this-->fillMode.findText( "Flood fill" ), false );
} }
function ShapeEdColWindow::update_onShapeSelectionChanged( %this ) function ShapeEdColWindow::update_onShapeSelectionChanged( %this )
{ {
%this.lastColSettings = "" TAB "Bounds"; %this.lastColSettings = "" TAB "Bounds" TAB "Flood fill";
// Initialise collision mesh target list // Initialise collision mesh target list
%this-->colTarget.clear(); %this-->colTarget.clear();
@ -2953,8 +2956,6 @@ function ShapeEdColWindow::update_onShapeSelectionChanged( %this )
%this-->colTarget.add( ShapeEditor.shape.getObjectName( %i ) ); %this-->colTarget.add( ShapeEditor.shape.getObjectName( %i ) );
%this-->colTarget.setSelected( %this-->colTarget.findText( "Bounds" ), false ); %this-->colTarget.setSelected( %this-->colTarget.findText( "Bounds" ), false );
%this-->fillMode.setSelected( %this-->fillMode.findText( "Flood fill" ), false );
} }
function ShapeEdColWindow::update_onCollisionChanged( %this ) function ShapeEdColWindow::update_onCollisionChanged( %this )
@ -2968,22 +2969,25 @@ function ShapeEdColWindow::update_onCollisionChanged( %this )
%targetId = %this-->colTarget.findText( getField( %colData, 1 ) ); %targetId = %this-->colTarget.findText( getField( %colData, 1 ) );
%this-->colTarget.setSelected( %targetId, false ); %this-->colTarget.setSelected( %targetId, false );
%fillModeID = %this-->fillMode.findText( getField( %colData, 2 ) );
%this-->fillMode.setSelected( %fillModeID, false );
if ( %this-->colType.getText() $= "Convex Hulls" ) if ( %this-->colType.getText() $= "Convex Hulls" )
{ {
%this-->hullInactive.setVisible( false ); %this-->hullInactive.setVisible( false );
%this-->hullDepth.setValue( getField( %colData, 2 ) ); %this-->hullDepth.setValue( getField( %colData, 3 ) );
%this-->hullDepthText.setText( mFloor( %this-->hullDepth.getValue() ) ); %this-->hullDepthText.setText( mFloor( %this-->hullDepth.getValue() ) );
%this-->hullMergeThreshold.setValue( getField( %colData, 3 ) ); %this-->hullMergeThreshold.setValue( getField( %colData, 4 ) );
%this-->hullMergeText.setText( mFloor( %this-->hullMergeThreshold.getValue() ) ); %this-->hullMergeText.setText( mFloor( %this-->hullMergeThreshold.getValue() ) );
%this-->hullConcaveThreshold.setValue( getField( %colData, 4 ) ); %this-->hullConcaveThreshold.setValue( getField( %colData, 5 ) );
%this-->hullConcaveText.setText( mFloor( %this-->hullConcaveThreshold.getValue() ) ); %this-->hullConcaveText.setText( mFloor( %this-->hullConcaveThreshold.getValue() ) );
%this-->hullMaxVerts.setValue( getField( %colData, 5 ) ); %this-->hullMaxVerts.setValue( getField( %colData, 6 ) );
%this-->hullMaxVertsText.setText( mFloor( %this-->hullMaxVerts.getValue() ) ); %this-->hullMaxVertsText.setText( mFloor( %this-->hullMaxVerts.getValue() ) );
%this-->hullMaxBoxError.setValue( getField( %colData, 6 ) ); %this-->hullMaxBoxError.setValue( getField( %colData, 7 ) );
%this-->hullMaxBoxErrorText.setText( mFloor( %this-->hullMaxBoxError.getValue() ) ); %this-->hullMaxBoxErrorText.setText( mFloor( %this-->hullMaxBoxError.getValue() ) );
%this-->hullMaxSphereError.setValue( getField( %colData, 7 ) ); %this-->hullMaxSphereError.setValue( getField( %colData, 8 ) );
%this-->hullMaxSphereErrorText.setText( mFloor( %this-->hullMaxSphereError.getValue() ) ); %this-->hullMaxSphereErrorText.setText( mFloor( %this-->hullMaxSphereError.getValue() ) );
%this-->hullMaxCapsuleError.setValue( getField( %colData, 8 ) ); %this-->hullMaxCapsuleError.setValue( getField( %colData, 9 ) );
%this-->hullMaxCapsuleErrorText.setText( mFloor( %this-->hullMaxCapsuleError.getValue() ) ); %this-->hullMaxCapsuleErrorText.setText( mFloor( %this-->hullMaxCapsuleError.getValue() ) );
} }
else else
@ -3013,6 +3017,7 @@ function ShapeEdColWindow::editCollisionOK( %this )
{ {
%type = %this-->colType.getText(); %type = %this-->colType.getText();
%target = %this-->colTarget.getText(); %target = %this-->colTarget.getText();
%fillMode = %this-->fillMode.getText();
%depth = %this-->hullDepth.getValue(); %depth = %this-->hullDepth.getValue();
%merge = %this-->hullMergeThreshold.getValue(); %merge = %this-->hullMergeThreshold.getValue();
%concavity = %this-->hullConcaveThreshold.getValue(); %concavity = %this-->hullConcaveThreshold.getValue();
@ -3021,7 +3026,7 @@ function ShapeEdColWindow::editCollisionOK( %this )
%maxSphere = %this-->hullMaxSphereError.getValue(); %maxSphere = %this-->hullMaxSphereError.getValue();
%maxCapsule = %this-->hullMaxCapsuleError.getValue(); %maxCapsule = %this-->hullMaxCapsuleError.getValue();
ShapeEditor.doEditCollision( %type, %target, %depth, %merge, %concavity, %maxVerts, ShapeEditor.doEditCollision( %type, %target, %fillMode, %depth, %merge, %concavity, %maxVerts,
%maxBox, %maxSphere, %maxCapsule ); %maxBox, %maxSphere, %maxCapsule );
} }

View file

@ -1046,7 +1046,7 @@ function ActionAddMeshFromFile::undo( %this )
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Add/edit collision geometry // Add/edit collision geometry
function ShapeEditor::doEditCollision( %this, %type, %target, %depth, %merge, %concavity, function ShapeEditor::doEditCollision( %this, %type, %target, %fillMode, %depth, %merge, %concavity,
%maxVerts, %boxMax, %sphereMax, %capsuleMax ) %maxVerts, %boxMax, %sphereMax, %capsuleMax )
{ {
%colData = ShapeEdColWindow.lastColSettings; %colData = ShapeEdColWindow.lastColSettings;
@ -1055,16 +1055,18 @@ function ShapeEditor::doEditCollision( %this, %type, %target, %depth, %merge, %c
%action.oldType = getField( %colData, 0 ); %action.oldType = getField( %colData, 0 );
%action.oldTarget = getField( %colData, 1 ); %action.oldTarget = getField( %colData, 1 );
%action.oldDepth = getField( %colData, 2 ); %action.oldFillMode = getField(%colData, 2);
%action.oldMerge = getField( %colData, 3 ); %action.oldDepth = getField( %colData, 3 );
%action.oldConcavity = getField( %colData, 4 ); %action.oldMerge = getField( %colData, 4 );
%action.oldMaxVerts = getField( %colData, 5 ); %action.oldConcavity = getField( %colData, 5 );
%action.oldBoxMax = getField( %colData, 6 ); %action.oldMaxVerts = getField( %colData, 6 );
%action.oldSphereMax = getField( %colData, 7 ); %action.oldBoxMax = getField( %colData, 7 );
%action.oldCapsuleMax = getField( %colData, 8 ); %action.oldSphereMax = getField( %colData, 8 );
%action.oldCapsuleMax = getField( %colData, 9 );
%action.newType = %type; %action.newType = %type;
%action.newTarget = %target; %action.newTarget = %target;
%action.newFillMode = %fillMode;
%action.newDepth = %depth; %action.newDepth = %depth;
%action.newMerge = %merge; %action.newMerge = %merge;
%action.newConcavity = %concavity; %action.newConcavity = %concavity;
@ -1076,7 +1078,7 @@ function ShapeEditor::doEditCollision( %this, %type, %target, %depth, %merge, %c
%this.doAction( %action ); %this.doAction( %action );
} }
function ActionEditCollision::updateCollision( %this, %type, %target, %depth, %merge, %concavity, function ActionEditCollision::updateCollision( %this, %type, %target, %fillMode, %depth, %merge, %concavity,
%maxVerts, %boxMax, %sphereMax, %capsuleMax ) %maxVerts, %boxMax, %sphereMax, %capsuleMax )
{ {
%colDetailSize = -1; %colDetailSize = -1;
@ -1089,7 +1091,7 @@ function ActionEditCollision::updateCollision( %this, %type, %target, %depth, %m
if ( %index != -1 ) if ( %index != -1 )
%colNode = ShapeEditor.shape.getNodeName( %index ); %colNode = ShapeEditor.shape.getNodeName( %index );
if(%target $= "Bounds" || %oldTarget $= "Bounds" || %target $= %oldTarget) if(%target $= %oldTarget)
{ {
// First remove the old detail and collision nodes // First remove the old detail and collision nodes
%meshList = ShapeEditor.getDetailMeshList( %colDetailSize ); %meshList = ShapeEditor.getDetailMeshList( %colDetailSize );
@ -1114,7 +1116,7 @@ function ActionEditCollision::updateCollision( %this, %type, %target, %depth, %m
if ( %type $= "" ) if ( %type $= "" )
return; return;
if ( !ShapeEditor.shape.addCollisionDetail( %colDetailSize, %type, %target, if ( !ShapeEditor.shape.addCollisionDetail( %colDetailSize, %type, %target, %fillMode,
%depth, %merge, %concavity, %maxVerts, %depth, %merge, %concavity, %maxVerts,
%boxMax, %sphereMax, %capsuleMax ) ) %boxMax, %sphereMax, %capsuleMax ) )
return false; return false;
@ -1126,7 +1128,7 @@ function ActionEditCollision::updateCollision( %this, %type, %target, %depth, %m
for ( %i = 0; %i < %count; %i++ ) for ( %i = 0; %i < %count; %i++ )
ShapeEdPropWindow.update_onMeshAdded( getField( %meshList, %i ) ); ShapeEdPropWindow.update_onMeshAdded( getField( %meshList, %i ) );
ShapeEdColWindow.lastColSettings = %type TAB %target TAB %depth TAB %merge TAB ShapeEdColWindow.lastColSettings = %type TAB %target TAB %fillMode TAB %depth TAB %merge TAB
%concavity TAB %maxVerts TAB %boxMax TAB %sphereMax TAB %capsuleMax; %concavity TAB %maxVerts TAB %boxMax TAB %sphereMax TAB %capsuleMax;
ShapeEdColWindow.update_onCollisionChanged(); ShapeEdColWindow.update_onCollisionChanged();
@ -1136,7 +1138,7 @@ function ActionEditCollision::updateCollision( %this, %type, %target, %depth, %m
function ActionEditCollision::doit( %this ) function ActionEditCollision::doit( %this )
{ {
ShapeEdWaitGui.show( "Generating collision geometry..." ); ShapeEdWaitGui.show( "Generating collision geometry..." );
%success = %this.updateCollision( %this.newType, %this.newTarget, %this.newDepth, %this.newMerge, %success = %this.updateCollision( %this.newType, %this.newTarget, %this.newFillMode, %this.newDepth, %this.newMerge,
%this.newConcavity, %this.newMaxVerts, %this.newBoxMax, %this.newConcavity, %this.newMaxVerts, %this.newBoxMax,
%this.newSphereMax, %this.newCapsuleMax ); %this.newSphereMax, %this.newCapsuleMax );
ShapeEdWaitGui.hide(); ShapeEdWaitGui.hide();
@ -1149,7 +1151,7 @@ function ActionEditCollision::undo( %this )
Parent::undo( %this ); Parent::undo( %this );
ShapeEdWaitGui.show( "Generating collision geometry..." ); ShapeEdWaitGui.show( "Generating collision geometry..." );
%this.updateCollision( %this.oldType, %this.oldTarget, %this.oldDepth, %this.oldMerge, %this.updateCollision( %this.oldType, %this.oldTarget, %this.oldFillMode, %this.oldDepth, %this.oldMerge,
%this.oldConcavity, %this.oldMaxVerts, %this.oldBoxMax, %this.oldConcavity, %this.oldMaxVerts, %this.oldBoxMax,
%this.oldSphereMax, %this.oldCapsuleMax ); %this.oldSphereMax, %this.oldCapsuleMax );
ShapeEdWaitGui.hide(); ShapeEdWaitGui.hide();