| 136 | } |
| 137 | |
| 138 | void NpShape::resolveReferences(PxDeserializationContext& context) |
| 139 | { |
| 140 | // getMaterials() only works after material indices have been patched. |
| 141 | // in order to get to the new material indices, we need access to the new materials. |
| 142 | // this only leaves us with the option of acquiring the material through the context given an old material index (we do have the mapping) |
| 143 | { |
| 144 | PxU32 nbIndices = mShape.getScShape().getNbMaterialIndices(); |
| 145 | const PxU16* indices = mShape.getScShape().getMaterialIndices(); |
| 146 | |
| 147 | for (PxU32 i=0; i < nbIndices; i++) |
| 148 | { |
| 149 | PxBase* base = context.resolveReference(PX_SERIAL_REF_KIND_MATERIAL_IDX, size_t(indices[i])); |
| 150 | PX_ASSERT(base && base->is<PxMaterial>()); |
| 151 | |
| 152 | NpMaterial& material = *static_cast<NpMaterial*>(base); |
| 153 | getScbShape().getScShape().resolveMaterialReference(i, PxU16(material.getHandle())); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | context.translatePxBase(mActor); |
| 158 | |
| 159 | getScbShape().getScShape().resolveReferences(context); |
| 160 | |
| 161 | |
| 162 | incMeshRefCount(); |
| 163 | |
| 164 | // Increment materials' refcounts in a second pass. Works better in case of failure above. |
| 165 | PxU32 nbMaterials = mShape.getNbMaterials(); |
| 166 | for (PxU32 i=0; i < nbMaterials; i++) |
| 167 | { |
| 168 | NpMaterial* mat = static_cast<NpMaterial*>(mShape.getMaterial(i)); |
| 169 | mat->incRefCount(); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | NpShape* NpShape::createObject(PxU8*& address, PxDeserializationContext& context) |
| 174 | { |
no test coverage detected