2015-07-26 21:39:49 +00:00
|
|
|
#include "CScriptNode.h"
|
2015-11-27 18:49:20 +00:00
|
|
|
#include "script/CScriptExtra.h"
|
|
|
|
|
2015-07-26 21:39:49 +00:00
|
|
|
#include <Common/AnimUtil.h>
|
|
|
|
#include <Common/Math.h>
|
|
|
|
#include <Core/CDrawUtil.h>
|
|
|
|
#include <Core/CGraphics.h>
|
|
|
|
#include <Core/CRenderer.h>
|
|
|
|
#include <Core/CResCache.h>
|
|
|
|
#include <Core/CSceneManager.h>
|
2015-10-26 05:36:53 +00:00
|
|
|
#include <Resource/script/CMasterTemplate.h>
|
2015-07-26 21:39:49 +00:00
|
|
|
|
|
|
|
CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObject *pObject)
|
|
|
|
: CSceneNode(pScene, pParent)
|
|
|
|
{
|
|
|
|
mpVolumePreviewNode = nullptr;
|
|
|
|
|
|
|
|
// Evaluate instance
|
|
|
|
mpInstance = pObject;
|
|
|
|
mpActiveModel = nullptr;
|
2015-11-24 15:43:26 +00:00
|
|
|
mpBillboard = nullptr;
|
2015-09-26 22:55:14 +00:00
|
|
|
mpCollisionNode = new CCollisionNode(pScene, this);
|
|
|
|
mpCollisionNode->SetInheritance(true, true, false);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
|
|
|
if (mpInstance)
|
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
CScriptTemplate *pTemp = mpInstance->Template();
|
|
|
|
|
2015-09-26 22:55:14 +00:00
|
|
|
// Determine transform
|
2015-09-18 05:53:53 +00:00
|
|
|
mPosition = mpInstance->Position();
|
|
|
|
mRotation = CQuaternion::FromEuler(mpInstance->Rotation());
|
2015-12-07 04:23:52 +00:00
|
|
|
mScale = mpInstance->Scale();
|
|
|
|
mScaleMultiplier = mpInstance->Template()->PreviewScale();
|
2015-07-26 21:39:49 +00:00
|
|
|
MarkTransformChanged();
|
|
|
|
|
2015-12-07 04:23:52 +00:00
|
|
|
SetName("[" + pTemp->TemplateName(mpInstance->NumProperties()) + "] " + mpInstance->InstanceName());
|
|
|
|
|
2015-09-26 22:55:14 +00:00
|
|
|
// Determine display assets
|
|
|
|
mpActiveModel = mpInstance->GetDisplayModel();
|
|
|
|
mModelToken = CToken(mpActiveModel);
|
|
|
|
|
2015-11-24 15:43:26 +00:00
|
|
|
mpBillboard = mpInstance->GetBillboard();
|
|
|
|
mBillboardToken = CToken(mpBillboard);
|
|
|
|
|
2015-09-26 22:55:14 +00:00
|
|
|
mpCollisionNode->SetCollision(mpInstance->GetCollision());
|
|
|
|
|
|
|
|
// Create preview volume node
|
2015-09-18 05:53:53 +00:00
|
|
|
mHasValidPosition = pTemp->HasPosition();
|
|
|
|
mHasVolumePreview = (pTemp->ScaleType() == CScriptTemplate::eScaleVolume);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
|
|
|
if (mHasVolumePreview)
|
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
EVolumeShape shape = mpInstance->VolumeShape();
|
2015-07-26 21:39:49 +00:00
|
|
|
CModel *pVolumeModel = nullptr;
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
if ((shape == eAxisAlignedBoxShape) || (shape == eBoxShape))
|
2015-07-26 21:39:49 +00:00
|
|
|
pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeBox.cmdl");
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
else if (shape == eEllipsoidShape)
|
2015-07-26 21:39:49 +00:00
|
|
|
pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeSphere.cmdl");
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
else if (shape == eCylinderShape)
|
|
|
|
pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeCylinder.cmdl");
|
|
|
|
|
|
|
|
else if (shape == eCylinderLargeShape)
|
|
|
|
pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeCylinderLarge.cmdl");
|
|
|
|
|
2015-07-26 21:39:49 +00:00
|
|
|
if (pVolumeModel)
|
|
|
|
{
|
|
|
|
mpVolumePreviewNode = new CModelNode(pScene, this, pVolumeModel);
|
2015-12-07 04:23:52 +00:00
|
|
|
mpVolumePreviewNode->SetInheritance(true, (shape != eAxisAlignedBoxShape), true);
|
2015-07-26 21:39:49 +00:00
|
|
|
mpVolumePreviewNode->ForceAlphaEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
2015-10-26 05:36:53 +00:00
|
|
|
|
|
|
|
// Fetch LightParameters
|
|
|
|
mpLightParameters = new CLightParameters(mpInstance->LightParameters(), mpInstance->MasterTemplate()->GetGame());
|
|
|
|
SetLightLayerIndex(mpLightParameters->LightLayerIndex());
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Shouldn't ever happen
|
|
|
|
SetName("ScriptNode - NO INSTANCE");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mpActiveModel)
|
|
|
|
mLocalAABox = mpActiveModel->AABox();
|
|
|
|
else
|
|
|
|
mLocalAABox = CAABox::skOne;
|
2015-11-27 18:49:20 +00:00
|
|
|
|
|
|
|
mpExtra = CScriptExtra::CreateExtra(this);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ENodeType CScriptNode::NodeType()
|
|
|
|
{
|
|
|
|
return eScriptNode;
|
|
|
|
}
|
|
|
|
|
2015-11-25 21:37:34 +00:00
|
|
|
void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
if (!mpInstance) return;
|
2015-09-27 22:02:53 +00:00
|
|
|
|
2015-11-27 18:49:20 +00:00
|
|
|
// Add script extra to renderer first
|
|
|
|
if (mpExtra) mpExtra->AddToRenderer(pRenderer, ViewInfo);
|
|
|
|
|
2015-11-26 09:05:26 +00:00
|
|
|
// If we're in game mode, then override other visibility settings.
|
|
|
|
if (ViewInfo.GameMode)
|
|
|
|
{
|
|
|
|
if (!mpInstance->IsActive() || !mpInstance->HasInGameModel())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-27 18:49:20 +00:00
|
|
|
// Check whether the script extra wants us to render before we render.
|
|
|
|
bool ShouldDraw = (!mpExtra || mpExtra->ShouldDrawNormalAssets());
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-27 18:49:20 +00:00
|
|
|
if (ShouldDraw)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-11-27 18:49:20 +00:00
|
|
|
// Otherwise, we proceed as normal
|
|
|
|
ERenderOptions options = pRenderer->RenderOptions();
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-27 18:49:20 +00:00
|
|
|
if ((options & eDrawObjectCollision) && (!ViewInfo.GameMode))
|
|
|
|
mpCollisionNode->AddToRenderer(pRenderer, ViewInfo);
|
2015-09-26 22:55:14 +00:00
|
|
|
|
2015-11-27 18:49:20 +00:00
|
|
|
if (options & eDrawObjects || ViewInfo.GameMode)
|
|
|
|
{
|
|
|
|
if (ViewInfo.ViewFrustum.BoxInFrustum(AABox()))
|
|
|
|
{
|
|
|
|
if (!mpActiveModel)
|
2015-11-27 23:28:35 +00:00
|
|
|
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh);
|
2015-09-27 22:02:53 +00:00
|
|
|
|
|
|
|
else
|
2015-09-26 22:55:14 +00:00
|
|
|
{
|
2015-11-27 18:49:20 +00:00
|
|
|
if (!mpActiveModel->HasTransparency(0))
|
2015-11-27 23:28:35 +00:00
|
|
|
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh);
|
2015-11-27 18:49:20 +00:00
|
|
|
else
|
2015-11-27 23:28:35 +00:00
|
|
|
AddSurfacesToRenderer(pRenderer, mpActiveModel, 0, ViewInfo);
|
2015-09-26 22:55:14 +00:00
|
|
|
}
|
2015-11-27 18:49:20 +00:00
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 09:05:26 +00:00
|
|
|
if (IsSelected() && !ViewInfo.GameMode)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-27 22:02:53 +00:00
|
|
|
// Script nodes always draw their selections regardless of frustum planes
|
|
|
|
// in order to ensure that script connection lines don't get improperly culled.
|
2015-11-27 18:49:20 +00:00
|
|
|
if (ShouldDraw)
|
2015-11-27 23:28:35 +00:00
|
|
|
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-27 18:49:20 +00:00
|
|
|
if (mHasVolumePreview && (!mpExtra || mpExtra->ShouldDrawVolume()))
|
2015-11-25 21:37:34 +00:00
|
|
|
mpVolumePreviewNode->AddToRenderer(pRenderer, ViewInfo);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-27 23:28:35 +00:00
|
|
|
void CScriptNode::Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
if (!mpInstance) return;
|
|
|
|
|
2015-11-24 15:43:26 +00:00
|
|
|
// Draw model
|
2015-12-07 04:23:52 +00:00
|
|
|
if (UsesModel())
|
2015-11-24 15:43:26 +00:00
|
|
|
{
|
2015-11-27 23:28:35 +00:00
|
|
|
CGraphics::SetupAmbientColor();
|
|
|
|
CGraphics::UpdateVertexBlock();
|
2015-11-24 15:43:26 +00:00
|
|
|
LoadModelMatrix();
|
2015-11-26 10:46:09 +00:00
|
|
|
LoadLights(ViewInfo);
|
2015-11-27 18:49:20 +00:00
|
|
|
|
2015-11-27 23:28:35 +00:00
|
|
|
// Draw model if possible!
|
|
|
|
if (mpActiveModel)
|
|
|
|
{
|
|
|
|
if (mpExtra) CGraphics::sPixelBlock.TevColor = mpExtra->TevColor().ToVector4f();
|
|
|
|
else CGraphics::sPixelBlock.TevColor = CColor::skWhite.ToVector4f();
|
|
|
|
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f();
|
|
|
|
CGraphics::UpdatePixelBlock();
|
|
|
|
|
|
|
|
if (ComponentIndex < 0)
|
|
|
|
mpActiveModel->Draw(Options, 0);
|
|
|
|
else
|
|
|
|
mpActiveModel->DrawSurface(Options, ComponentIndex, 0);
|
|
|
|
}
|
2015-11-27 18:49:20 +00:00
|
|
|
|
2015-11-27 23:28:35 +00:00
|
|
|
// If no model or billboard, default to drawing a purple box
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ZERO, GL_ZERO);
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
CDrawUtil::DrawShadedCube(CColor::skTransparentPurple * TintColor(ViewInfo));
|
|
|
|
}
|
2015-11-24 15:43:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw billboard
|
|
|
|
else if (mpBillboard)
|
|
|
|
{
|
2015-11-26 10:42:42 +00:00
|
|
|
CDrawUtil::DrawBillboard(mpBillboard, mPosition, BillboardScale(), TintColor(ViewInfo));
|
2015-11-24 15:43:26 +00:00
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptNode::DrawSelection()
|
|
|
|
{
|
2015-07-27 04:22:08 +00:00
|
|
|
glBlendFunc(GL_ONE, GL_ZERO);
|
2015-11-24 15:43:26 +00:00
|
|
|
|
2015-11-26 10:42:42 +00:00
|
|
|
// Draw wireframe for models; billboards only get tinted
|
2015-12-07 04:23:52 +00:00
|
|
|
if (UsesModel())
|
2015-11-24 15:43:26 +00:00
|
|
|
{
|
|
|
|
LoadModelMatrix();
|
2015-11-26 10:42:42 +00:00
|
|
|
CModel *pModel = (mpActiveModel ? mpActiveModel : CDrawUtil::GetCubeModel());
|
|
|
|
pModel->DrawWireframe(eNoRenderOptions, WireframeColor());
|
2015-11-24 15:43:26 +00:00
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
|
|
|
|
if (mpInstance)
|
|
|
|
{
|
2015-09-01 23:21:10 +00:00
|
|
|
CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity;
|
|
|
|
CGraphics::UpdateMVPBlock();
|
|
|
|
|
2015-07-26 21:39:49 +00:00
|
|
|
for (u32 iIn = 0; iIn < mpInstance->NumInLinks(); iIn++)
|
|
|
|
{
|
2015-11-27 18:49:20 +00:00
|
|
|
// Don't draw in links if the other object is selected.
|
2015-07-26 21:39:49 +00:00
|
|
|
const SLink& con = mpInstance->InLink(iIn);
|
|
|
|
CScriptNode *pLinkNode = mpScene->ScriptNodeByID(con.ObjectID);
|
2015-11-27 18:49:20 +00:00
|
|
|
if (pLinkNode && !pLinkNode->IsSelected()) CDrawUtil::DrawLine(CenterPoint(), pLinkNode->CenterPoint(), CColor::skTransparentRed);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (u32 iOut = 0; iOut < mpInstance->NumOutLinks(); iOut++)
|
|
|
|
{
|
|
|
|
const SLink& con = mpInstance->OutLink(iOut);
|
|
|
|
CScriptNode *pLinkNode = mpScene->ScriptNodeByID(con.ObjectID);
|
|
|
|
if (pLinkNode) CDrawUtil::DrawLine(CenterPoint(), pLinkNode->CenterPoint(), CColor::skTransparentGreen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-28 18:37:22 +00:00
|
|
|
void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
if (!mpInstance)
|
|
|
|
return;
|
|
|
|
|
2015-11-27 18:49:20 +00:00
|
|
|
// Let script extra do ray check first
|
|
|
|
if (mpExtra)
|
|
|
|
{
|
2015-11-28 18:37:22 +00:00
|
|
|
mpExtra->RayAABoxIntersectTest(Tester, ViewInfo);
|
2015-11-27 18:49:20 +00:00
|
|
|
|
|
|
|
// If the extra doesn't want us rendering, then don't do the ray test either
|
2015-11-28 18:37:22 +00:00
|
|
|
if (!mpExtra->ShouldDrawNormalAssets())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're in game mode, then check whether we're visible before proceeding with the ray test.
|
|
|
|
if (ViewInfo.GameMode)
|
|
|
|
{
|
|
|
|
if (!mpInstance->IsActive() || !mpInstance->HasInGameModel())
|
|
|
|
return;
|
2015-11-27 18:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, proceed with the ray test as normal...
|
2015-07-26 21:39:49 +00:00
|
|
|
const CRay& Ray = Tester.Ray();
|
|
|
|
|
2015-12-07 04:23:52 +00:00
|
|
|
if (UsesModel())
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-11-25 21:37:34 +00:00
|
|
|
std::pair<bool,float> BoxResult = AABox().IntersectsRay(Ray);
|
|
|
|
|
|
|
|
if (BoxResult.first)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-11-27 23:28:35 +00:00
|
|
|
if (mpActiveModel) Tester.AddNodeModel(this, mpActiveModel);
|
2015-11-25 21:37:34 +00:00
|
|
|
else Tester.AddNode(this, 0, BoxResult.second);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
2015-11-25 21:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Because the billboard rotates a lot, expand the AABox on the X/Y axes to cover any possible orientation
|
|
|
|
CVector2f BillScale = BillboardScale();
|
|
|
|
float ScaleXY = (BillScale.x > BillScale.y ? BillScale.x : BillScale.y);
|
|
|
|
|
|
|
|
CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.y),
|
|
|
|
mPosition + CVector3f( ScaleXY, ScaleXY, BillScale.y));
|
|
|
|
|
|
|
|
std::pair<bool,float> BoxResult = BillBox.IntersectsRay(Ray);
|
|
|
|
if (BoxResult.first) Tester.AddNode(this, 0, BoxResult.second);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-25 21:37:34 +00:00
|
|
|
SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID, const SViewInfo& ViewInfo)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-11-25 21:37:34 +00:00
|
|
|
ERenderOptions options = ViewInfo.pRenderer->RenderOptions();
|
2015-09-26 22:55:14 +00:00
|
|
|
|
2015-07-26 21:39:49 +00:00
|
|
|
SRayIntersection out;
|
|
|
|
out.pNode = this;
|
2015-11-28 18:37:22 +00:00
|
|
|
out.ComponentIndex = AssetID;
|
2015-11-26 09:05:26 +00:00
|
|
|
|
|
|
|
if (options & eDrawObjects || ViewInfo.GameMode)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-11-25 21:37:34 +00:00
|
|
|
// Model test
|
2015-12-07 04:23:52 +00:00
|
|
|
if (UsesModel())
|
2015-09-26 22:55:14 +00:00
|
|
|
{
|
2015-11-25 21:37:34 +00:00
|
|
|
CModel *pModel = (mpActiveModel ? mpActiveModel : CDrawUtil::GetCubeModel());
|
|
|
|
|
|
|
|
CRay TransformedRay = Ray.Transformed(Transform().Inverse());
|
|
|
|
std::pair<bool,float> Result = pModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((options & eEnableBackfaceCull) == 0));
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-25 21:37:34 +00:00
|
|
|
if (Result.first)
|
|
|
|
{
|
|
|
|
out.Hit = true;
|
|
|
|
|
|
|
|
CVector3f HitPoint = TransformedRay.PointOnRay(Result.second);
|
|
|
|
CVector3f WorldHitPoint = Transform() * HitPoint;
|
|
|
|
out.Distance = Math::Distance(Ray.Origin(), WorldHitPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
out.Hit = false;
|
2015-09-26 22:55:14 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 21:37:34 +00:00
|
|
|
// Billboard test
|
|
|
|
// todo: come up with a better way to share this code between CScriptNode and CLightNode
|
2015-09-26 22:55:14 +00:00
|
|
|
else
|
2015-11-25 21:37:34 +00:00
|
|
|
{
|
|
|
|
// Step 1: check whether the ray intersects with the plane the billboard is on
|
|
|
|
CPlane BillboardPlane(-ViewInfo.pCamera->Direction(), mPosition);
|
|
|
|
std::pair<bool,float> PlaneTest = Math::RayPlaneIntersecton(Ray, BillboardPlane);
|
|
|
|
|
|
|
|
if (PlaneTest.first)
|
|
|
|
{
|
|
|
|
// Step 2: transform the hit point into the plane's local space
|
|
|
|
CVector3f PlaneHitPoint = Ray.PointOnRay(PlaneTest.second);
|
|
|
|
CVector3f RelHitPoint = PlaneHitPoint - mPosition;
|
|
|
|
|
|
|
|
CVector3f PlaneForward = -ViewInfo.pCamera->Direction();
|
|
|
|
CVector3f PlaneRight = -ViewInfo.pCamera->RightVector();
|
|
|
|
CVector3f PlaneUp = ViewInfo.pCamera->UpVector();
|
|
|
|
CQuaternion PlaneRot = CQuaternion::FromAxes(PlaneRight, PlaneForward, PlaneUp);
|
|
|
|
|
|
|
|
CVector3f RotatedHitPoint = PlaneRot.Inverse() * RelHitPoint;
|
|
|
|
CVector2f LocalHitPoint = RotatedHitPoint.xz() / BillboardScale();
|
|
|
|
|
|
|
|
// Step 3: check whether the transformed hit point is in the -1 to 1 range
|
|
|
|
if ((LocalHitPoint.x >= -1.f) && (LocalHitPoint.x <= 1.f) && (LocalHitPoint.y >= -1.f) && (LocalHitPoint.y <= 1.f))
|
|
|
|
{
|
|
|
|
// Step 4: look up the hit texel and check whether it's transparent or opaque
|
|
|
|
CVector2f TexCoord = (LocalHitPoint + CVector2f(1.f)) * 0.5f;
|
|
|
|
TexCoord.x = -TexCoord.x + 1.f;
|
|
|
|
float TexelAlpha = mpBillboard->ReadTexelAlpha(TexCoord);
|
|
|
|
|
|
|
|
if (TexelAlpha < 0.25f)
|
|
|
|
out.Hit = false;
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// It's opaque... we have a hit!
|
|
|
|
out.Hit = true;
|
|
|
|
out.Distance = PlaneTest.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
out.Hit = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
out.Hit = false;
|
|
|
|
}
|
2015-09-26 22:55:14 +00:00
|
|
|
}
|
|
|
|
else out.Hit = false;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptNode::IsVisible() const
|
|
|
|
{
|
2015-11-26 10:42:42 +00:00
|
|
|
// Reimplementation of CSceneNode::IsVisible() to allow for layer and template visiblity to be taken into account
|
2015-07-26 21:39:49 +00:00
|
|
|
return (mVisible && mpInstance->Layer()->IsVisible() && mpInstance->Template()->IsVisible());
|
|
|
|
}
|
|
|
|
|
2015-11-27 18:49:20 +00:00
|
|
|
CColor CScriptNode::TintColor(const SViewInfo &ViewInfo) const
|
|
|
|
{
|
|
|
|
CColor BaseColor = CSceneNode::TintColor(ViewInfo);
|
|
|
|
if (mpExtra) mpExtra->ModifyTintColor(BaseColor);
|
|
|
|
return BaseColor;
|
|
|
|
}
|
|
|
|
|
2015-07-26 21:39:49 +00:00
|
|
|
void CScriptNode::GeneratePosition()
|
|
|
|
{
|
|
|
|
if (!mHasValidPosition)
|
|
|
|
{
|
|
|
|
// Default to center of the active area; this is to preven recursion issues
|
|
|
|
CTransform4f& AreaTransform = mpScene->GetActiveArea()->GetTransform();
|
|
|
|
mPosition = CVector3f(AreaTransform[0][3], AreaTransform[1][3], AreaTransform[2][3]);
|
|
|
|
mHasValidPosition = true;
|
|
|
|
MarkTransformChanged();
|
|
|
|
|
|
|
|
// Ideal way to generate the position is to find a spot close to where it's being used.
|
|
|
|
// To do this I check the location of the objects that this one is linked to.
|
|
|
|
u32 NumLinks = mpInstance->NumInLinks() + mpInstance->NumOutLinks();
|
|
|
|
|
|
|
|
// In the case of one link, apply an offset so the new position isn't the same place as the object it's linked to
|
|
|
|
if (NumLinks == 1)
|
|
|
|
{
|
|
|
|
const SLink& link = (mpInstance->NumInLinks() > 0 ? mpInstance->InLink(0) : mpInstance->OutLink(0));
|
|
|
|
CScriptNode *pNode = mpScene->ScriptNodeByID(link.ObjectID);
|
|
|
|
pNode->GeneratePosition();
|
2015-08-20 01:01:58 +00:00
|
|
|
mPosition = pNode->AbsolutePosition();
|
2015-08-17 18:10:42 +00:00
|
|
|
mPosition.z += (pNode->AABox().Size().z / 2.f);
|
|
|
|
mPosition.z += (AABox().Size().z / 2.f);
|
2015-07-26 21:39:49 +00:00
|
|
|
mPosition.z += 2.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For two or more links, average out the position of the connected objects.
|
|
|
|
else if (NumLinks >= 2)
|
|
|
|
{
|
|
|
|
CVector3f NewPos = CVector3f::skZero;
|
|
|
|
|
|
|
|
for (u32 iIn = 0; iIn < mpInstance->NumInLinks(); iIn++)
|
|
|
|
{
|
|
|
|
CScriptNode *pNode = mpScene->ScriptNodeByID(mpInstance->InLink(iIn).ObjectID);
|
|
|
|
|
|
|
|
if (pNode)
|
|
|
|
{
|
|
|
|
pNode->GeneratePosition();
|
|
|
|
NewPos += pNode->AABox().Center();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (u32 iOut = 0; iOut < mpInstance->NumOutLinks(); iOut++)
|
|
|
|
{
|
|
|
|
CScriptNode *pNode = mpScene->ScriptNodeByID(mpInstance->OutLink(iOut).ObjectID);
|
|
|
|
|
|
|
|
if (pNode)
|
|
|
|
{
|
|
|
|
pNode->GeneratePosition();
|
|
|
|
NewPos += pNode->AABox().Center();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 10:22:37 +00:00
|
|
|
mPosition = NewPos / (float) NumLinks;
|
2015-07-26 21:39:49 +00:00
|
|
|
mPosition.x += 2.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
MarkTransformChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 04:23:52 +00:00
|
|
|
CColor CScriptNode::WireframeColor() const
|
|
|
|
{
|
|
|
|
return CColor((u8) 12, 135, 194, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
CScriptObject* CScriptNode::Object() const
|
|
|
|
{
|
|
|
|
return mpInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
CModel* CScriptNode::ActiveModel() const
|
|
|
|
{
|
|
|
|
return mpActiveModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptNode::UsesModel() const
|
|
|
|
{
|
|
|
|
return ((mpActiveModel != nullptr) || (mpBillboard == nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptNode::HasPreviewVolume() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
return mHasVolumePreview;
|
|
|
|
}
|
|
|
|
|
2015-12-07 04:23:52 +00:00
|
|
|
CAABox CScriptNode::PreviewVolumeAABox() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
if (!mHasVolumePreview)
|
|
|
|
return CAABox::skZero;
|
|
|
|
else
|
|
|
|
return mpVolumePreviewNode->AABox();
|
|
|
|
}
|
2015-11-25 21:37:34 +00:00
|
|
|
|
2015-12-07 04:23:52 +00:00
|
|
|
CVector2f CScriptNode::BillboardScale() const
|
2015-11-25 21:37:34 +00:00
|
|
|
{
|
2015-11-29 11:28:10 +00:00
|
|
|
CVector2f out = (mpInstance->Template()->ScaleType() == CScriptTemplate::eScaleEnabled ? AbsoluteScale().xz() : CVector2f(1.f));
|
2015-11-25 21:37:34 +00:00
|
|
|
return out * 0.5f;
|
|
|
|
}
|
2015-12-07 04:23:52 +00:00
|
|
|
|
|
|
|
// ************ PROTECTED ************
|
|
|
|
void CScriptNode::CalculateTransform(CTransform4f& rOut) const
|
|
|
|
{
|
|
|
|
CScriptTemplate *pTemp = mpInstance->Template();
|
|
|
|
|
|
|
|
if (pTemp->ScaleType() != CScriptTemplate::eScaleDisabled)
|
|
|
|
{
|
|
|
|
CVector3f Scale = (HasPreviewVolume() ? CVector3f::skOne : AbsoluteScale());
|
|
|
|
rOut.Scale(Scale * mScaleMultiplier);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UsesModel() && pTemp->RotationType() == CScriptTemplate::eRotationEnabled)
|
|
|
|
rOut.Rotate(AbsoluteRotation());
|
|
|
|
|
|
|
|
rOut.Translate(AbsolutePosition());
|
|
|
|
}
|