1 | // |
2 | // Redistribution and use in source and binary forms, with or without |
3 | // modification, are permitted provided that the following conditions |
4 | // are met: |
5 | // * Redistributions of source code must retain the above copyright |
6 | // notice, this list of conditions and the following disclaimer. |
7 | // * Redistributions in binary form must reproduce the above copyright |
8 | // notice, this list of conditions and the following disclaimer in the |
9 | // documentation and/or other materials provided with the distribution. |
10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
11 | // contributors may be used to endorse or promote products derived |
12 | // from this software without specific prior written permission. |
13 | // |
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | // |
26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
29 | |
30 | #ifndef PX_PHYSICS_NP_ARTICULATION_LINK |
31 | #define PX_PHYSICS_NP_ARTICULATION_LINK |
32 | |
33 | #include "NpRigidBodyTemplate.h" |
34 | #include "PxArticulationLink.h" |
35 | |
36 | #if PX_ENABLE_DEBUG_VISUALIZATION |
37 | #include "CmRenderOutput.h" |
38 | #endif |
39 | |
40 | namespace physx |
41 | { |
42 | class NpArticulation; |
43 | class NpArticulationLink; |
44 | class NpArticulationJoint; |
45 | class PxConstraintVisualizer; |
46 | |
47 | typedef NpRigidBodyTemplate<PxArticulationLink> NpArticulationLinkT; |
48 | |
49 | class NpArticulationLinkArray : public Ps::InlineArray<NpArticulationLink*, 4> //!!!AL TODO: check if default of 4 elements makes sense |
50 | { |
51 | //= ATTENTION! ===================================================================================== |
52 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
53 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
54 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
55 | // accordingly. |
56 | //================================================================================================== |
57 | public: |
58 | // PX_SERIALIZATION |
59 | NpArticulationLinkArray(const PxEMPTY) : Ps::InlineArray<NpArticulationLink*, 4> (PxEmpty) {} |
60 | static void getBinaryMetaData(PxOutputStream& stream); |
61 | //~PX_SERIALIZATION |
62 | NpArticulationLinkArray() : Ps::InlineArray<NpArticulationLink*, 4>(PX_DEBUG_EXP("articulationLinkArray" )) {} |
63 | }; |
64 | |
65 | class NpArticulationLink : public NpArticulationLinkT |
66 | { |
67 | //= ATTENTION! ===================================================================================== |
68 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
69 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
70 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
71 | // accordingly. |
72 | //================================================================================================== |
73 | public: |
74 | // PX_SERIALIZATION |
75 | NpArticulationLink(PxBaseFlags baseFlags) : NpArticulationLinkT(baseFlags), mChildLinks(PxEmpty) {} |
76 | void preExportDataReset() { NpArticulationLinkT::preExportDataReset(); } |
77 | virtual void (PxSerializationContext& context); |
78 | void (PxDeserializationContext& context); |
79 | void resolveReferences(PxDeserializationContext& context); |
80 | virtual void requiresObjects(PxProcessPxBaseCallback& c); |
81 | virtual bool isSubordinate() const { return true; } |
82 | static NpArticulationLink* createObject(PxU8*& address, PxDeserializationContext& context); |
83 | static void getBinaryMetaData(PxOutputStream& stream); |
84 | //~PX_SERIALIZATION |
85 | virtual ~NpArticulationLink(); |
86 | |
87 | //--------------------------------------------------------------------------------- |
88 | // PxArticulationLink implementation |
89 | //--------------------------------------------------------------------------------- |
90 | virtual void release(); |
91 | |
92 | |
93 | virtual PxActorType::Enum getType() const { return PxActorType::eARTICULATION_LINK; } |
94 | |
95 | // Pose |
96 | virtual void setGlobalPose(const PxTransform& pose); |
97 | virtual void setGlobalPose(const PxTransform& pose, bool autowake); |
98 | virtual PxTransform getGlobalPose() const; |
99 | |
100 | //damping |
101 | virtual void setLinearDamping(PxReal linDamp); |
102 | virtual PxReal getLinearDamping() const; |
103 | |
104 | virtual void setAngularDamping(PxReal angDamp); |
105 | virtual PxReal getAngularDamping() const; |
106 | |
107 | // Velocity |
108 | virtual void setLinearVelocity(const PxVec3&, bool autowake = true); |
109 | virtual void setAngularVelocity(const PxVec3&, bool autowake = true); |
110 | virtual void setMaxAngularVelocity(PxReal); |
111 | virtual PxReal getMaxAngularVelocity() const; |
112 | virtual void setMaxLinearVelocity(PxReal); |
113 | virtual PxReal getMaxLinearVelocity() const; |
114 | |
115 | virtual PxArticulationBase& getArticulation() const; |
116 | virtual PxArticulationJointBase* getInboundJoint() const; |
117 | virtual PxU32 getInboundJointDof() const; |
118 | |
119 | virtual PxU32 getNbChildren() const; |
120 | virtual PxU32 getChildren(PxArticulationLink** userBuffer, PxU32 bufferSize, PxU32 startIndex) const; |
121 | virtual PxU32 getLinkIndex() const; |
122 | virtual void setCMassLocalPose(const PxTransform& pose); |
123 | |
124 | virtual void addForce(const PxVec3& force, PxForceMode::Enum mode = PxForceMode::eFORCE, bool autowake = true); |
125 | virtual void addTorque(const PxVec3& torque, PxForceMode::Enum mode = PxForceMode::eFORCE, bool autowake = true); |
126 | virtual void setForceAndTorque(const PxVec3& force, const PxVec3& torque, PxForceMode::Enum mode = PxForceMode::eFORCE); |
127 | virtual void clearForce(PxForceMode::Enum mode = PxForceMode::eFORCE); |
128 | virtual void clearTorque(PxForceMode::Enum mode = PxForceMode::eFORCE); |
129 | |
130 | //--------------------------------------------------------------------------------- |
131 | // Miscellaneous |
132 | //--------------------------------------------------------------------------------- |
133 | NpArticulationLink(const PxTransform& bodyPose, PxArticulationBase& root, NpArticulationLink* parent); |
134 | |
135 | void releaseInternal(); |
136 | |
137 | PX_INLINE PxArticulationBase& getRoot() { return *mRoot; } |
138 | PX_INLINE NpArticulationLink* getParent() { return mParent; } |
139 | |
140 | PX_INLINE void setInboundJoint(PxArticulationJointBase& joint) { mInboundJoint = &joint; } |
141 | |
142 | void setGlobalPoseInternal(const PxTransform& pose, bool autowake); |
143 | void setLLIndex(const PxU32 index) { mLLIndex = index; } |
144 | void setInboundJointDof(const PxU32 index) { mInboundJointDof = index; } |
145 | |
146 | static PX_FORCE_INLINE size_t getScbBodyOffset() { return PX_OFFSET_OF_RT(NpArticulationLink, mBody); } |
147 | private: |
148 | PX_INLINE void addToChildList(NpArticulationLink& link) { mChildLinks.pushBack(a: &link); } |
149 | PX_INLINE void removeFromChildList(NpArticulationLink& link) { PX_ASSERT(mChildLinks.find(&link) != mChildLinks.end()); mChildLinks.findAndReplaceWithLast(a: &link); } |
150 | |
151 | public: |
152 | PX_INLINE NpArticulationLink* const* getChildren() { return mChildLinks.empty() ? NULL : &mChildLinks.front(); } |
153 | void setKinematicLink(const bool value); |
154 | |
155 | #if PX_ENABLE_DEBUG_VISUALIZATION |
156 | public: |
157 | void visualize(Cm::RenderOutput& out, NpScene* scene); |
158 | void visualizeJoint(PxConstraintVisualizer& jointViz); |
159 | #endif |
160 | |
161 | private: |
162 | PxArticulationBase* mRoot; //!!!AL TODO: Revisit: Could probably be avoided if registration and deregistration in root is handled differently |
163 | PxArticulationJointBase* mInboundJoint; |
164 | NpArticulationLink* mParent; //!!!AL TODO: Revisit: Some memory waste but makes things faster |
165 | NpArticulationLinkArray mChildLinks; |
166 | PxU32 mLLIndex; |
167 | PxU32 mInboundJointDof; |
168 | }; |
169 | |
170 | } |
171 | |
172 | #endif |
173 | |