Przeglądaj źródła

Minor fixes to skeletal animation code and more work on GUITimeline

BearishSun 9 lat temu
rodzic
commit
fc4942d1a6

BIN
Data/Engine/GUISkin.asset


BIN
Data/Engine/Includes/SkinnedVertexInput.bslinc.asset


BIN
Data/Engine/ResourceManifest.asset


BIN
Data/Engine/Timestamp.asset


BIN
Data/Engine/arial.ttf.asset


+ 8 - 8
Data/Raw/Engine/Includes/SkinnedVertexInput.bslinc

@@ -1,7 +1,7 @@
 Parameters =
 Parameters =
 {
 {
-	StructBuffer boneMatrices : auto("BoneMatrices");;
-}
+	StructBuffer boneMatrices : auto("BoneMatrices");
+};
 
 
 Technique =
 Technique =
 {
 {
@@ -115,7 +115,7 @@ Technique =
 					float4 position = float4(input.position, 1.0f);
 					float4 position = float4(input.position, 1.0f);
 				#endif
 				#endif
 			
 			
-				position = mul(intermediate.blendMatrix, position);
+				position = float4(mul(intermediate.blendMatrix, position), 1.0f);
 				return mul(gMatWorld, position);
 				return mul(gMatWorld, position);
 			}
 			}
 			
 			
@@ -123,8 +123,8 @@ Technique =
 			{
 			{
 				result.uv0 = input.uv0;
 				result.uv0 = input.uv0;
 				
 				
-				result.tangentToWorldZ = float3(intermediate.tangentToWorld._m02_m12_m22); // Normal basis vector
-				result.tangentToWorldX = float4(intermediate.tangentToWorld._m00_m10_m20, tangentSign); // Tangent basis vector
+				result.tangentToWorldZ = intermediate.worldNormal;
+				result.tangentToWorldX = intermediate.worldTangent;
 			}
 			}
 		};
 		};
 	};
 	};
@@ -245,7 +245,7 @@ Technique =
 					vec4 position = vec4(bs_position, 1.0f);
 					vec4 position = vec4(bs_position, 1.0f);
 				#endif
 				#endif
 			
 			
-				position = intermediate.blendMatrix * position;
+				position = vec4(intermediate.blendMatrix * position, 1.0f);
 				result = gMatWorld * position;
 				result = gMatWorld * position;
 			}
 			}
 			
 			
@@ -253,8 +253,8 @@ Technique =
 			{
 			{
 				uv0 = bs_texcoord0;
 				uv0 = bs_texcoord0;
 				
 				
-				tangentToWorldZ = intermediate.tangentToWorld[2]; // Normal basis vector
-				tangentToWorldX = vec4(intermediate.tangentToWorld[0].xyz, intermediate.tangentSign); // Tangent basis vector
+				tangentToWorldZ = intermediate.worldNormal;
+				tangentToWorldX = intermediate.worldTangent;
 			}
 			}
 		};
 		};
 	};
 	};

+ 7 - 1
Source/BansheeCore/Source/BsAnimation.cpp

@@ -254,7 +254,13 @@ namespace BansheeEngine
 				UINT32 localStateIdx = 0;
 				UINT32 localStateIdx = 0;
 				for(auto& clipInfo : clipInfos)
 				for(auto& clipInfo : clipInfos)
 				{
 				{
-					if (clipInfo.state.layer != layer.index)
+					UINT32 clipLayer = clipInfo.state.layer;
+					if (clipLayer == (UINT32)-1)
+						clipLayer = 0;
+					else
+						clipLayer += 1;
+
+					if (clipLayer != layer.index)
 						continue;
 						continue;
 
 
 					AnimationState& state = states[curStateIdx];
 					AnimationState& state = states[curStateIdx];

+ 3 - 0
Source/BansheeD3D11RenderAPI/Include/BsD3D11GpuProgram.h

@@ -41,6 +41,9 @@ namespace BansheeEngine
 		 */
 		 */
 		void populateParametersAndConstants(ID3DBlob* microcode);
 		void populateParametersAndConstants(ID3DBlob* microcode);
 
 
+		/** Parses compiler error message and returns the line number at which the error occurred. */
+		UINT32 parseErrorMessage(const char* message);
+
 	protected:
 	protected:
 		static UINT32 GlobalProgramId;
 		static UINT32 GlobalProgramId;
 
 

+ 31 - 3
Source/BansheeD3D11RenderAPI/Source/BsD3D11GpuProgram.cpp

@@ -10,6 +10,7 @@
 #include "BsHardwareBufferManager.h"
 #include "BsHardwareBufferManager.h"
 #include "BsD3D11HLSLParamParser.h"
 #include "BsD3D11HLSLParamParser.h"
 #include "BsRenderStats.h"
 #include "BsRenderStats.h"
+#include <regex>
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -65,10 +66,27 @@ namespace BansheeEngine
 		GpuProgramCore::initialize();
 		GpuProgramCore::initialize();
 	}
 	}
 
 
-	ID3DBlob* D3D11GpuProgramCore::compileMicrocode(const String& profile)
+	UINT32 D3D11GpuProgramCore::parseErrorMessage(const char* message)
 	{
 	{
-		// TODO - Preprocessor defines aren't supported
+		if (message == nullptr)
+			return 0;
+
+		String pattern = R"(\(([0-9]*),.*\))";
+		std::regex regex(pattern);
+
+		std::cmatch results;
+		if (std::regex_search(message, results, regex))
+		{
+			std::string result = results[1].str();
+
+			return strtol(result.c_str(), nullptr, 10) - 1;
+		}
 
 
+		return 0;
+	}
+
+	ID3DBlob* D3D11GpuProgramCore::compileMicrocode(const String& profile)
+	{
 		UINT compileFlags = 0;
 		UINT compileFlags = 0;
 #if defined(BS_DEBUG_MODE)
 #if defined(BS_DEBUG_MODE)
 		compileFlags |= D3DCOMPILE_DEBUG;
 		compileFlags |= D3DCOMPILE_DEBUG;
@@ -102,9 +120,19 @@ namespace BansheeEngine
 
 
 		if (FAILED(hr))
 		if (FAILED(hr))
 		{
 		{
+			const char* errorMessage = static_cast<const char*>(errors->GetBufferPointer());
+			UINT32 errorLineIdx = parseErrorMessage(errorMessage);
+
+			Vector<String> sourceLines = StringUtil::split(source, "\n");
+			String sourceLine;
+			if (errorLineIdx < sourceLines.size())
+				sourceLine = sourceLines[errorLineIdx];
+
 			mIsCompiled = false;
 			mIsCompiled = false;
 			mCompileError = "Cannot compile D3D11 high-level shader. Errors:\n" +
 			mCompileError = "Cannot compile D3D11 high-level shader. Errors:\n" +
-				String(static_cast<const char*>(errors->GetBufferPointer()));
+				String(errorMessage) + "\n" +
+				"\n" +
+				"Line " + toString(errorLineIdx) + ": " + sourceLine;
 
 
 			SAFE_RELEASE(microCode);
 			SAFE_RELEASE(microCode);
 			SAFE_RELEASE(errors);
 			SAFE_RELEASE(errors);

+ 1 - 1
Source/MBansheeEditor/Inspectors/AnimationInspector.cs

@@ -14,7 +14,7 @@ namespace BansheeEditor
     [CustomInspector(typeof(Animation))]
     [CustomInspector(typeof(Animation))]
     internal class AnimationInspector : Inspector
     internal class AnimationInspector : Inspector
     {
     {
-        private GUIResourceField animationClipField = new GUIResourceField(typeof(AudioClip), new LocEdString("Clip"));
+        private GUIResourceField animationClipField = new GUIResourceField(typeof(AnimationClip), new LocEdString("Clip"));
         private GUIEnumField wrapModeField = new GUIEnumField(typeof(AnimWrapMode), new LocEdString("Wrap mode"));
         private GUIEnumField wrapModeField = new GUIEnumField(typeof(AnimWrapMode), new LocEdString("Wrap mode"));
         private GUIFloatField speedField = new GUIFloatField(new LocEdString("Speed"));
         private GUIFloatField speedField = new GUIFloatField(new LocEdString("Speed"));
         private InspectableState modifyState;
         private InspectableState modifyState;

+ 5 - 59
Source/MBansheeEditor/Windows/Animation/GUITimeline.cs

@@ -69,11 +69,16 @@ namespace BansheeEditor
                 60.0f, 120.0f, 300.0f, 600.0f, 1800.0f, 3600.0f // Minutes
                 60.0f, 120.0f, 300.0f, 600.0f, 1800.0f, 3600.0f // Minutes
             };
             };
 
 
+            float timePerFrame = 1.0f/fps;
             int bestIntervalIdx = 0;
             int bestIntervalIdx = 0;
             float bestDistance = float.MaxValue;
             float bestDistance = float.MaxValue;
 
 
             for(int i = 0; i < validIntervals.Length; i++)
             for(int i = 0; i < validIntervals.Length; i++)
             {
             {
+                // Cannot choose an interval that would display ticks for below the frame-rate
+                if (validIntervals[i] < timePerFrame)
+                    continue;
+
                 float tickCount = length/validIntervals[i];
                 float tickCount = length/validIntervals[i];
                 float distance = Math.Abs(tickCount - OPTIMAL_TICK_COUNT);
                 float distance = Math.Abs(tickCount - OPTIMAL_TICK_COUNT);
                 if (distance < bestDistance)
                 if (distance < bestDistance)
@@ -161,9 +166,6 @@ namespace BansheeEditor
         {
         {
             canvas.Clear();
             canvas.Clear();
 
 
-            // TODO - Enforce a minimum limit between ticks, so when width is too small they don't come too close together
-            // TODO - Don't draw ticks below the frame rate
-
             // TODO - Text from invisible ticks should be displayed (otherwise it will just pop in was the tick is shown)
             // TODO - Text from invisible ticks should be displayed (otherwise it will just pop in was the tick is shown)
 
 
             // TODO - Draw small ticks (don't forget to handle offset properly)
             // TODO - Draw small ticks (don't forget to handle offset properly)
@@ -208,62 +210,6 @@ namespace BansheeEditor
                 t += tickInterval;
                 t += tickInterval;
                 t = Math.Min(t, rangeLength);
                 t = Math.Min(t, rangeLength);
             }
             }
-
-            //float offsetLarge = MathEx.CeilToInt(rangeStart / largeTickInterval) * largeTickInterval - rangeStart;
-            //float offsetSmall = MathEx.CeilToInt(rangeStart / smallTickInterval) * smallTickInterval - rangeStart;
-
-            //int largeTickHeight = (int)(height * LARGE_TICK_HEIGHT_PCT);
-            //int smallTickHeight = (int)(height * SMALL_TICK_HEIGHT_PCT);
-
-            //bool drawSmallTicks = true; // TODO
-
-            //float t = offsetSmall;
-            //for (int i = 0; i < numVisibleTicks; i++)
-            //{
-            //    float distanceToLargeTick = MathEx.CeilToInt(t / largeTickInterval) * largeTickInterval - t;
-            //    if (MathEx.ApproxEquals(distanceToLargeTick, 0.0f))
-            //    {
-            //        int xPos = (int)((t/rangeLength)* drawableWidth) + PADDING;
-
-            //        Vector2I start = new Vector2I(xPos, height - largeTickHeight);
-            //        Vector2I end = new Vector2I(xPos, height);
-
-            //        canvas.DrawLine(start, end, Color.LightGray);
-
-            //        TimeSpan intervalSpan = TimeSpan.FromSeconds(largeTickInterval);
-            //        TimeSpan timeSpan = TimeSpan.FromSeconds(rangeStart + t);
-
-            //        string timeString;
-            //        if(intervalSpan.Minutes > 0)
-            //            timeString = timeSpan.ToString(@"m\:ss");
-            //        else
-            //            timeString = timeSpan.ToString(@"ss\:fff");
-
-            //        Vector2I textBounds = GUIUtility.CalculateTextBounds(timeString, EditorBuiltin.DefaultFont, 
-            //            EditorStyles.DefaultFontSize);
-
-            //        Vector2I textPosition = new Vector2I();
-            //        textPosition.x = xPos - textBounds.x/2;
-            //        textPosition.y = TEXT_PADDING;
-
-            //        canvas.DrawText(timeString, textPosition, EditorBuiltin.DefaultFont, Color.LightGray, 
-            //            EditorStyles.DefaultFontSize);
-            //    }
-            //    else
-            //    {
-            //        if (drawSmallTicks)
-            //        {
-            //            int xPos = (int)((t / rangeLength) * drawableWidth) + PADDING;
-
-            //            Vector2I start = new Vector2I(xPos, height - smallTickHeight);
-            //            Vector2I end = new Vector2I(xPos, height);
-
-            //            canvas.DrawLine(start, end, Color.LightGray);
-            //        }
-            //    }
-
-            //    t += smallTickInterval;
-            //}
         }
         }
     }
     }