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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*
* Copyright (c) 2008-2015, 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.
*/
#include "EditionToolController.h"
#include "BlastController.h"
#include "Renderer.h"
#include "PhysXController.h"
#include "SampleProfiler.h"
#include "PxRigidDynamic.h"
#include "PxScene.h"
#include "NvBlastExtPxManager.h"
#include "SceneController.h"
#include "NvBlastExtPxActor.h"
#include "GlobalSettings.h"
using namespace Nv::Blast;
using namespace physx;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Setup
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
EditionToolController::EditionToolController()
{
}
EditionToolController::~EditionToolController()
{
}
void EditionToolController::onSampleStart()
{
}
void EditionToolController::onInitialize()
{
}
void EditionToolController::onSampleStop()
{
}
void EditionToolController::Animate(double dt)
{
PROFILER_SCOPED_FUNCTION();
}
LRESULT EditionToolController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PROFILER_SCOPED_FUNCTION();
if (uMsg == WM_LBUTTONDOWN || uMsg == WM_MOUSEMOVE || uMsg == WM_LBUTTONUP)
{
float mouseX = (short)LOWORD(lParam) / getRenderer().getScreenWidth();
float mouseY = (short)HIWORD(lParam) / getRenderer().getScreenHeight();
bool press = uMsg == WM_LBUTTONDOWN;
if (uMsg == WM_LBUTTONUP)
{
PxVec3 eyePos, pickDir;
getPhysXController().getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir);
pickDir = pickDir.getNormalized();
PxRaycastHit hit; hit.shape = NULL;
PxRaycastBuffer hit1;
getPhysXController().getPhysXScene().raycast(eyePos, pickDir, PX_MAX_F32, hit1, PxHitFlag::ePOSITION | PxHitFlag::eNORMAL);
hit = hit1.block;
PxRigidActor* actor = NULL;
if (hit.shape)
{
actor = hit.actor;
}
fracture(actor);
}
}
return 1;
}
void EditionToolController::drawUI()
{
}
void EditionToolController::fracture(PxActor* actor)
{
if (NULL == actor)
{
return;
}
BlastController& blastController = getBlastController();
std::vector<BlastFamilyPtr>& families = blastController.getFamilies();
if (families.size() == 0)
{
return;
}
ExtPxActor* extActor = NULL;
PxRigidDynamic* rigidDynamic = actor->is<PxRigidDynamic>();
if (NULL != rigidDynamic)
{
extActor = blastController.getExtPxManager().getActorFromPhysXActor(*rigidDynamic);
}
if (NULL == extActor)
{
return;
}
uint32_t chunkCount = extActor->getChunkCount();
if (chunkCount <= 0)
{
return;
}
BlastFamilyPtr pBlastFamily = NULL;
std::vector<BlastFamilyPtr>::iterator it = families.begin();
for (; it != families.end(); it++)
{
BlastFamilyPtr f = *it;
if (f->find(extActor))
{
pBlastFamily = f;
break;
}
}
if (NULL == pBlastFamily)
{
return;
}
const uint32_t* chunkIndices = extActor->getChunkIndices();
const BlastAsset& blastAsset = pBlastFamily->getBlastAsset();
const BlastAsset* pBlastAsset = &blastAsset;
SceneController& sceneController = getManager()->getSceneController();
AssetList::ModelAsset desc;
sceneController.GetAssetDesc(pBlastAsset, desc);
std::string assetname = desc.id;
GlobalSettings& globalSettings = GlobalSettings::Inst();
getManager()->fractureAsset(globalSettings.m_projectFileDir, assetname, pBlastAsset, chunkIndices[0]);
getManager()->addModelAsset(globalSettings.m_projectFileDir, assetname, desc.isSkinned, desc.transform, false);
}
|