aboutsummaryrefslogtreecommitdiff
path: root/APEX_1.4/module/clothing/include/CookingAbstract.h
blob: cd8fb1be6f5a71cb27272d8dd735d07f5976ae6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright (c) 2008-2017, NVIDIA CORPORATION.  All rights reserved.
 *
 * NVIDIA CORPORATION and its licensors retain all intellectual property
 * and proprietary rights in and to this software, related documentation
 * and any modifications thereto.  Any use, reproduction, disclosure or
 * distribution of this software and related documentation without an express
 * license agreement from NVIDIA CORPORATION is strictly prohibited.
 */


#ifndef COOKING_ABSTRACT_H
#define COOKING_ABSTRACT_H

#include "PsUserAllocated.h"
#include "PxVec3.h"
#include "PsArray.h"
#include "ApexUsingNamespace.h"

namespace NvParameterized
{
class Interface;
}

namespace nvidia
{
namespace clothing
{

namespace ClothingAssetParametersNS
{
struct BoneEntry_Type;
struct ActorEntry_Type;
}

typedef ClothingAssetParametersNS::BoneEntry_Type BoneEntry;
typedef ClothingAssetParametersNS::ActorEntry_Type BoneActorEntry;

using namespace physx::shdfnd;

class CookingAbstract : public nvidia::UserAllocated
{
public:
	CookingAbstract() : mBoneActors(NULL), mNumBoneActors(0), mBoneEntries(NULL), mNumBoneEntries(0), mBoneVertices(NULL), mMaxConvexVertices(256),
		mFreeTempMemoryWhenDone(NULL), mScale(1.0f), mVirtualParticleDensity(0.0f), mSelfcollisionRadius(0.0f)
	{
	}

	virtual ~CookingAbstract()
	{
		if (mFreeTempMemoryWhenDone != NULL)
		{
			PX_FREE(mFreeTempMemoryWhenDone);
			mFreeTempMemoryWhenDone = NULL;
		}
	}

	struct PhysicalMesh
	{
		PhysicalMesh() : meshID(0), isTetrahedral(false), vertices(NULL), numVertices(0), numSimulatedVertices(0), numMaxDistance0Vertices(0), 
						indices(NULL), numIndices(0), numSimulatedIndices(0), largestTriangleArea(0.0f), smallestTriangleArea(0.0f) {}

		uint32_t	meshID;
		bool		isTetrahedral;

		PxVec3*		vertices;
		uint32_t	numVertices;
		uint32_t	numSimulatedVertices;
		uint32_t	numMaxDistance0Vertices;

		uint32_t*	indices;
		uint32_t	numIndices;
		uint32_t	numSimulatedIndices;

		void computeTriangleAreas();
		float largestTriangleArea;
		float smallestTriangleArea;
	};

	void addPhysicalMesh(const PhysicalMesh& physicalMesh);
	void setConvexBones(const BoneActorEntry* boneActors, uint32_t numBoneActors, const BoneEntry* boneEntries, uint32_t numBoneEntries, const PxVec3* boneVertices, uint32_t maxConvexVertices);

	void freeTempMemoryWhenDone(void* memory)
	{
		mFreeTempMemoryWhenDone = memory;
	}
	void setScale(float scale)
	{
		mScale = scale;
	}
	void setVirtualParticleDensity(float density)
	{
		PX_ASSERT(density >= 0.0f);
		PX_ASSERT(density <= 1.0f);
		mVirtualParticleDensity = density;
	}
	void setSelfcollisionRadius(float radius)
	{
		PX_ASSERT(radius >= 0.0f);
		mSelfcollisionRadius = radius;
	}
	void setGravityDirection(const PxVec3& gravityDir)
	{
		mGravityDirection = gravityDir;
		mGravityDirection.normalize();
	}

	virtual NvParameterized::Interface* execute() = 0;

	bool isValid() const;

protected:
	Array<PhysicalMesh>		mPhysicalMeshes;

	const BoneActorEntry*	mBoneActors;
	uint32_t				mNumBoneActors;
	const BoneEntry*		mBoneEntries;
	uint32_t				mNumBoneEntries;
	const PxVec3*			mBoneVertices;
	uint32_t				mMaxConvexVertices;

	void*					mFreeTempMemoryWhenDone;
	float					mScale;

	float					mVirtualParticleDensity;
	float					mSelfcollisionRadius;

	PxVec3					mGravityDirection;
};

}
} // namespace nvidia

#endif // COOKING_ABSTRACT_H