Browse Source

Gizmo icon picking works

Marko Pintera 11 years ago
parent
commit
43b595cda9

+ 2 - 2
BansheeCore/Include/BsTransientMesh.h

@@ -77,8 +77,8 @@ namespace BansheeEngine
 		 *
 		 *
 		 * @see		MeshHeap::alloc
 		 * @see		MeshHeap::alloc
 		 */
 		 */
-		TransientMesh(const MeshHeapPtr& parentHeap, UINT32 id, UINT32 numIndices, 
-			UINT32 numVertices, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
+		TransientMesh(const MeshHeapPtr& parentHeap, UINT32 id, UINT32 numVertices,
+			UINT32 numIndices, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
 
 
 		/**
 		/**
 		 * @brief	Marks the mesh as destroyed so we know that we don't need to destroy it ourselves.
 		 * @brief	Marks the mesh as destroyed so we know that we don't need to destroy it ourselves.

+ 0 - 7
BansheeEditor/Source/BsBuiltinEditorResources.cpp

@@ -1423,11 +1423,6 @@ namespace BansheeEngine
 
 
 		HBlendState blendState = BlendState::create(blendDesc);
 		HBlendState blendState = BlendState::create(blendDesc);
 
 
-		RASTERIZER_STATE_DESC rasterizerDesc;
-		rasterizerDesc.cullMode = CULL_NONE;
-
-		HRasterizerState rasterizerState = RasterizerState::create(rasterizerDesc);
-
 		DEPTH_STENCIL_STATE_DESC depthStencilState0Desc;
 		DEPTH_STENCIL_STATE_DESC depthStencilState0Desc;
 		depthStencilState0Desc.depthWriteEnable = false;
 		depthStencilState0Desc.depthWriteEnable = false;
 		depthStencilState0Desc.depthComparisonFunc = CMPF_LESS_EQUAL;
 		depthStencilState0Desc.depthComparisonFunc = CMPF_LESS_EQUAL;
@@ -1447,7 +1442,6 @@ namespace BansheeEngine
 
 
 		newPass0->setBlendState(blendState);
 		newPass0->setBlendState(blendState);
 		newPass0->setDepthStencilState(depthStencilState0);
 		newPass0->setDepthStencilState(depthStencilState0);
-		newPass0->setRasterizerState(rasterizerState);
 
 
 		PassPtr newPass1 = newTechnique->addPass();
 		PassPtr newPass1 = newTechnique->addPass();
 		newPass1->setVertexProgram(vsProgram1);
 		newPass1->setVertexProgram(vsProgram1);
@@ -1455,7 +1449,6 @@ namespace BansheeEngine
 
 
 		newPass1->setBlendState(blendState);
 		newPass1->setBlendState(blendState);
 		newPass1->setDepthStencilState(depthStencilState1);
 		newPass1->setDepthStencilState(depthStencilState1);
-		newPass1->setRasterizerState(rasterizerState);
 	}
 	}
 
 
 	void BuiltinEditorResources::initGizmoPickingShader()
 	void BuiltinEditorResources::initGizmoPickingShader()

+ 12 - 9
BansheeEditor/Source/BsGizmoManager.cpp

@@ -529,19 +529,22 @@ namespace BansheeEngine
 			calculateIconColors(curIconData.color, *camera.get(), (UINT32)(halfHeight * 2.0f), curIconData.fixedScale, normalColor, fadedColor);
 			calculateIconColors(curIconData.color, *camera.get(), (UINT32)(halfHeight * 2.0f), curIconData.fixedScale, normalColor, fadedColor);
 
 
 			if (forPicking)
 			if (forPicking)
+			{
 				normalColor = curIconData.color;
 				normalColor = curIconData.color;
+				fadedColor = curIconData.color;
+			}
 
 
 			Vector3 positions[4];
 			Vector3 positions[4];
 			positions[0] = position + Vector3(-halfWidth, -halfHeight, 0.0f);
 			positions[0] = position + Vector3(-halfWidth, -halfHeight, 0.0f);
 			positions[1] = position + Vector3(halfWidth, -halfHeight, 0.0f);
 			positions[1] = position + Vector3(halfWidth, -halfHeight, 0.0f);
-			positions[2] = position + Vector3(-halfWidth, halfHeight, 0.0f);
-			positions[3] = position + Vector3(halfWidth, halfHeight, 0.0f);
+			positions[2] = position + Vector3(halfWidth, halfHeight, 0.0f);
+			positions[3] = position + Vector3(-halfWidth, halfHeight, 0.0f);
 
 
 			Vector2 uvs[4];
 			Vector2 uvs[4];
 			uvs[0] = curIconData.texture->transformUV(Vector2(0.0f, 0.0f));
 			uvs[0] = curIconData.texture->transformUV(Vector2(0.0f, 0.0f));
 			uvs[1] = curIconData.texture->transformUV(Vector2(1.0f, 0.0f));
 			uvs[1] = curIconData.texture->transformUV(Vector2(1.0f, 0.0f));
-			uvs[2] = curIconData.texture->transformUV(Vector2(0.0f, 1.0f));
-			uvs[3] = curIconData.texture->transformUV(Vector2(1.0f, 1.0f));
+			uvs[2] = curIconData.texture->transformUV(Vector2(1.0f, 1.0f));
+			uvs[3] = curIconData.texture->transformUV(Vector2(0.0f, 1.0f));
 
 
 			for (UINT32 j = 0; j < 4; j++)
 			for (UINT32 j = 0; j < 4; j++)
 			{
 			{
@@ -554,8 +557,8 @@ namespace BansheeEngine
 			UINT32 vertOffset = i * 4;
 			UINT32 vertOffset = i * 4;
 
 
 			indices[0] = vertOffset + 0;
 			indices[0] = vertOffset + 0;
-			indices[1] = vertOffset + 1;
-			indices[2] = vertOffset + 2;
+			indices[1] = vertOffset + 3;
+			indices[2] = vertOffset + 1;
 			indices[3] = vertOffset + 1;
 			indices[3] = vertOffset + 1;
 			indices[4] = vertOffset + 3;
 			indices[4] = vertOffset + 3;
 			indices[5] = vertOffset + 2;
 			indices[5] = vertOffset + 2;
@@ -792,13 +795,13 @@ namespace BansheeEngine
 			{
 			{
 				Renderer::setPass(*mIconMaterial.proxy, passIdx);
 				Renderer::setPass(*mIconMaterial.proxy, passIdx);
 
 
-				UINT32 curIndexOffset = 0;
+				UINT32 curIndexOffset = mesh->_getIndexOffset();
 				for (auto curRenderData : *renderData)
 				for (auto curRenderData : *renderData)
 				{
 				{
 					mIconMaterial.mTexture[passIdx].set(curRenderData.texture);
 					mIconMaterial.mTexture[passIdx].set(curRenderData.texture);
 					rs.bindGpuParams(GPT_FRAGMENT_PROGRAM, mIconMaterial.mFragParams[passIdx]);
 					rs.bindGpuParams(GPT_FRAGMENT_PROGRAM, mIconMaterial.mFragParams[passIdx]);
 
 
-					rs.drawIndexed(curIndexOffset, curRenderData.count * 6, 0, curRenderData.count * 4);
+					rs.drawIndexed(curIndexOffset, curRenderData.count * 6, mesh->_getVertexOffset(), curRenderData.count * 4);
 					curIndexOffset += curRenderData.count * 6;
 					curIndexOffset += curRenderData.count * 6;
 				}
 				}
 			}
 			}
@@ -815,7 +818,7 @@ namespace BansheeEngine
 				mAlphaPickingMaterial.mTexture.set(curRenderData.texture);
 				mAlphaPickingMaterial.mTexture.set(curRenderData.texture);
 				rs.bindGpuParams(GPT_FRAGMENT_PROGRAM, mAlphaPickingMaterial.mFragParams);
 				rs.bindGpuParams(GPT_FRAGMENT_PROGRAM, mAlphaPickingMaterial.mFragParams);
 
 
-				rs.drawIndexed(curIndexOffset, curRenderData.count * 6, 0, curRenderData.count * 4);
+				rs.drawIndexed(curIndexOffset, curRenderData.count * 6, mesh->_getVertexOffset(), curRenderData.count * 4);
 				curIndexOffset += curRenderData.count * 6;
 				curIndexOffset += curRenderData.count * 6;
 
 
 			}
 			}

+ 1 - 1
BansheeEditor/Source/BsHandleSliderDisc.cpp

@@ -42,7 +42,7 @@ namespace BansheeEngine
 		Ray localRay = ray;
 		Ray localRay = ray;
 		localRay.transform(getTransformInv());
 		localRay.transform(getTransformInv());
 
 
-		auto intersect = mCollider.intersects(ray);
+		auto intersect = mCollider.intersects(localRay);
 
 
 		if (intersect.first)
 		if (intersect.first)
 		{
 		{

+ 2 - 2
BansheeEditor/Source/BsHandleSliderLine.cpp

@@ -39,8 +39,8 @@ namespace BansheeEngine
 		Ray localRay = ray;
 		Ray localRay = ray;
 		localRay.transform(getTransformInv());
 		localRay.transform(getTransformInv());
 
 
-		auto capsuleIntersect = mCapsuleCollider.intersects(ray);
-		auto sphereIntersect = mSphereCollider.intersects(ray);
+		auto capsuleIntersect = mCapsuleCollider.intersects(localRay);
+		auto sphereIntersect = mSphereCollider.intersects(localRay);
 
 
 		t = std::numeric_limits<float>::max();
 		t = std::numeric_limits<float>::max();
 		bool gotIntersect = false;
 		bool gotIntersect = false;

+ 1 - 1
BansheeEditor/Source/BsHandleSliderPlane.cpp

@@ -33,7 +33,7 @@ namespace BansheeEngine
 		Ray localRay = ray;
 		Ray localRay = ray;
 		localRay.transform(getTransformInv());
 		localRay.transform(getTransformInv());
 
 
-		auto intersect = mCollider.intersects(ray);
+		auto intersect = mCollider.intersects(localRay);
 
 
 		if (intersect.first)
 		if (intersect.first)
 		{
 		{

+ 8 - 3
BansheeEngine/Source/BsCamera.cpp

@@ -11,6 +11,7 @@
 #include "BsException.h"
 #include "BsException.h"
 #include "BsRenderSystem.h"
 #include "BsRenderSystem.h"
 #include "BsSceneObject.h"
 #include "BsSceneObject.h"
+#include "BsDebug.h"
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
@@ -521,8 +522,8 @@ namespace BansheeEngine
 	Vector2 Camera::screenToClipPoint(const Vector2I& screenPoint) const
 	Vector2 Camera::screenToClipPoint(const Vector2I& screenPoint) const
 	{
 	{
 		Vector2 clipPoint;
 		Vector2 clipPoint;
-		clipPoint.x = (float)(((screenPoint.x - mViewport->getX()) / mViewport->getWidth()) * 2.0f - 1.0f);
-		clipPoint.y = (float)(((screenPoint.y - mViewport->getY()) / mViewport->getHeight()) * 2.0f - 1.0f);
+		clipPoint.x = (float)(((screenPoint.x - mViewport->getX()) / (float)mViewport->getWidth()) * 2.0f - 1.0f);
+		clipPoint.y = (float)(((screenPoint.y - mViewport->getY()) / (float)mViewport->getHeight()) * 2.0f - 1.0f);
 
 
 		return clipPoint;
 		return clipPoint;
 	}
 	}
@@ -568,11 +569,15 @@ namespace BansheeEngine
 	Ray Camera::screenPointToRay(const Vector2I& screenPoint) const
 	Ray Camera::screenPointToRay(const Vector2I& screenPoint) const
 	{
 	{
 		Vector2 clipPoint = screenToClipPoint(screenPoint);
 		Vector2 clipPoint = screenToClipPoint(screenPoint);
+		LOGWRN(toString(clipPoint));
 
 
 		Vector3 near = unprojectPoint(Vector3(clipPoint.x, clipPoint.y, mNearDist));
 		Vector3 near = unprojectPoint(Vector3(clipPoint.x, clipPoint.y, mNearDist));
 		Vector3 far = unprojectPoint(Vector3(clipPoint.x, clipPoint.y, mNearDist + 1.0f));
 		Vector3 far = unprojectPoint(Vector3(clipPoint.x, clipPoint.y, mNearDist + 1.0f));
 
 
-		return Ray(near, Vector3::normalize(far - near));
+		Ray ray(near, Vector3::normalize(far - near));
+		ray.transformAffine(mViewMatrix.inverseAffine());
+
+		return ray;
 	}
 	}
 
 
 	Vector3 Camera::projectPoint(const Vector3& point) const
 	Vector3 Camera::projectPoint(const Vector3& point) const

+ 1 - 0
MBansheeEditor/DbgGizmo.cs

@@ -28,6 +28,7 @@ namespace BansheeEditor
                 target.sceneObject.position + 8.5f * Vector3.xAxis);
                 target.sceneObject.position + 8.5f * Vector3.xAxis);
             Gizmos.DrawFrustum(target.sceneObject.position + 10 * Vector3.xAxis, 1920.0f / 1080.0f, 90, 1.0f, 1000.0f);
             Gizmos.DrawFrustum(target.sceneObject.position + 10 * Vector3.xAxis, 1920.0f / 1080.0f, 90, 1.0f, 1000.0f);
 
 
+            Gizmos.color = Color.red;
             Gizmos.DrawIcon(target.sceneObject.position + new Vector3(0, 10, 0), iconTexture, false);
             Gizmos.DrawIcon(target.sceneObject.position + new Vector3(0, 10, 0), iconTexture, false);
         }
         }
     }
     }

+ 2 - 1
SceneView.txt

@@ -6,9 +6,10 @@
 
 
 REFACTOR material getParams* and related classes. Those params should update all gpu program params that share that variable, not just the first found
 REFACTOR material getParams* and related classes. Those params should update all gpu program params that share that variable, not just the first found
 Add a way to render GUI image without alpha
 Add a way to render GUI image without alpha
-Cannot pick gizmo icon
 Line slider collider intersection doesn't work properly
 Line slider collider intersection doesn't work properly
 Handles need to render in front of everything
 Handles need to render in front of everything
+Clicking on empty space needs to deselect everything
+D3D11HardwareBuffer::writeData provides incorrect parameters to UpdateSubresource() (length & offset)
 
 
 Test gizmos
 Test gizmos
  - HOOK UP GIZMO SELECTION and test it
  - HOOK UP GIZMO SELECTION and test it