Questions in topic: "tangent"
http://answers.unity.com/questions/topics/single/74.html
The latest questions for the topic "tangent"Tangent for 5th order Bezier curve
http://answers.unity.com/questions/1903873/tangent-for-5th-order-bezier-curve.html
I'm using Bezier curves for gameobject placement. Mostly it's enough to use cubic curve but in some cases I need more precision.
I'm not strong in math, so I found 5th order equation in wiki and the curve looks fine. Now I just need set angles. Can anyone help me with tangent equation for 5th order Bezier curve?
[1]:
//Cubic
public Vector3 GetPosition(float t)
{
return (1 - t) * (1 - t) * (1 - t) * _p0
+ 3 * (1 - t) * (1 - t) * t * _p1
+ 3 * (1 - t) * t * t * _p2
+ t * t * t * _p3;
}
public Vector3 GetTangent(float t)
{
float u = 1 - t;
float uu = u * u;
float tu = t * u;
float tt = t * t;
Vector3 P = _p0 * 3 * uu * (-1.0f);
P += _p1 * 3 * (uu - 2 * tu);
P += _p2 * 3 * (2 * tu - tt);
P += _p3 * 3 * tt;
return P.normalized;
}
//n5
public Vector3 GetPosition(float t)
{
float u = 1 - t;
float uu = u * u;
float uuu = uu * u;
float tt = t * t;
float ttt = t * tt;
Vector3 P = _p0 * uu * uuu;
P += _p1 * 5 * uu * uu * t;
P += _p2 * 10 * uuu * tt;
P += _p3 * 10 * ttt * uu;
P += _p4 * 5 * tt * tt * u;
P += _p5 * ttt * tt;
return P;
}curvebeziertangentWed, 25 May 2022 18:36:04 GMTspirit_2Tangent affected by model's UV, shader uses custom texcoord
http://answers.unity.com/questions/1798067/tangent-affected-by-uv-anyway-to-have-it-not.html
Good evening.
<br><br>
I'm still a big newbie when it comes to shaders, and I've been hitting my head against a wall lately. I've been trying to convert a Parallax Occlusion Mapping shader from using model UV coordinates to using worldspace coordinates.
<br><br>
Problem is, the shader uses the tangent in calculating.. stuff. So when the UV of the textures don't match the UV the tangent was from, well, stuff breaks completely. What should I put in place of the tangent to make it work with the position and not the UV? I am aware that the tangent points to the direction where U increases, and the bi-tangent points to the direction where V increases, but that's about where my knowledge of the subject ends.
<br><br>
This is how I'm doing the position based UV:
float2 uv = IN.vertex.xz;
uv += float2(IN.normal.x, IN.normal.z) * IN.vertex.y;
uv *= 0.25;shadershader programmingtangenttangentsSat, 19 Dec 2020 03:50:34 GMTAlphaGarg8447Why am I not getting an angle in degrees from aTan?
http://answers.unity.com/questions/1698300/why-am-i-not-getting-an-angle-in-degrees-from-atan.html
float slope = ( mousePosition.z - mouseStart.z ) / ( mousePosition.x - mouseStart.x );
float degrees = math.atan( slope );mathangleslopetangentSun, 09 Feb 2020 04:08:24 GMTmartygrof3708How do i make my terrain able to use tangent geometry
http://answers.unity.com/questions/1662670/how-do-i-make-my-terrain-able-to-use-tangent-geome.html
I'm using unity 2019.2.3f1 i'm trying to apply ground texture to my terrain so i can start making the land and add tree and rocks, every time i put my material tho any of them , I get that message "Can't Use Materials With Shaders Which Need Tangent Geometry on Terrain, Use Shaders In Nature/Terrain instead" even making a new material from scratch same thing. I know i'm missing something since i'm new to this but i can't continue until this problem is fixed i've search around and i have found no answers, i've seen people ask the same question with no resolution. if anyone knows to to fix this problem it would be extremely helpful.shaderterrainhowgeometrytangentTue, 03 Sep 2019 02:19:42 GMTdbzloverjamFinding a tangent vector from a given point and circle
http://answers.unity.com/questions/1617078/finding-a-tangent-vector-from-a-given-point-and-ci.html
Hi all
Im working on some AI navigation, and I would like the vehicle to aim up for the tangent *b* (reference picture at the bottom). I got most of the stuff figured out at the moment (thanks to [this][1] great answer), but I'm still struggling with the maths in C#.
I have the point B, the direction of vector w, the length shouldn't matter.
I also have point A, and the radius of the circle. What I'm missing is the point E, which is the intersecting point between the tangent of the circle, and the circle itself, and the direction of vector *b*.
Approximations are also alright, if they grant a performance boost - I'm not looking for accuracy, just a decent behaving ai :)
All help is appreciated!
![this][2]
[1]: https://gamedev.stackexchange.com/questions/162030/how-can-i-maneuver-an-ai-pirate-ship-for-a-sea-battle
[2]: /storage/temp/135494-tangent.pngmathvectortangentdirectionstangentsFri, 29 Mar 2019 00:34:45 GMTSkovtroldentangent space viewDir in a SurfaceShader
http://answers.unity.com/questions/1523286/tangent-space-viewdir-in-a-surfaceshader.html
There is probably not much more I can say about that. I'm trying to get the tangent space view direction in a surface shader (in the surf() function) but I can't seem to figure out how, so after searching for a solution for quite some time I'm coming back here to ask you guys.
------
The last thing I got (after a few other iterations that didn't work) is this:
struct Input {
// [...]
float3 worldTangentDir : TEXCOORD0;
};
void vert (inout appdata_full v, out Input o) {
// [...]
TANGENT_SPACE_ROTATION; // create rotation matrix
o.worldTangentDir = mul( rotation, ObjSpaceViewDir( v.vertex ) );
}
void surf (Input IN, inout SurfaceOutputStandard o) {
// [...]
o.Albedo = abs(IN.worldTangentDir);
}
What I expect would be to see different colors on my mesh representing the tangent view direction *(kind of like when you map the normals to the output Albedo so each pixel gets colored accordingly)*. But what I get is just black. Any ideas on this one?
---
Thanks in advance!shadersurface shaderhlsltangentviewdirThu, 28 Jun 2018 19:41:39 GMTDrayI Don't Need Tangent Space Normals
http://answers.unity.com/questions/1517769/i-dont-need-tangent-space-normals.html
Unity Standard Surface Shader uses "Tangent Space Normals" but I'm creating a custom bump solution that doesn't need tangents and I want to remove the configuration from the Standard Shader if possible.
My bump solution uses custom bump maps and works perfectly when applied in an Unlit Shader using "Normal Space Normals".
Is there a way to simply get the Surface Shader to use "Normal Space Normals" without losing the other features like Tessellation?normalsnormalmapsurface shadertangentWed, 13 Jun 2018 15:30:55 GMTWowmaniacHow to make One More Line game?
http://answers.unity.com/questions/1475615/how-to-make-one-more-line.html
How to hook the player to the Anchor point and release the ball according to the direction it is rotating?rotationvelocitydirectionjointstangentFri, 02 Mar 2018 11:24:13 GMTabishekjreubenNormal map issue in Calculating Tangent Space
http://answers.unity.com/questions/1370326/normal-map-issue-in-calculating-tangent-space.html
Hello evryone,
I am having a problem regarding the calculation of the tangents. Am using 3Dsmax and Substance painter 2 for the workflow. Inside SP2 the model look fine with all the maps , but in Unity i get these strange artifacts on the Normal map after calculating the tangents . I found out tha my normal map has a small degree of color inclination. Normal color(127,127,255 ) with inclinations of (126, 127,255) in some areas, producing these effects on my model.
What could i do to fix it?
Thank you![alt text][1]
[1]: /storage/temp/96616-issues.jpgtexturenormalsbakingshadingtangentMon, 26 Jun 2017 11:18:10 GMTPolls47Detect a collision point, but allow pass through collider.
http://answers.unity.com/questions/1313739/detect-a-collision-point-but-allow-pass-through-co.html
I have a Unity project in which there is a 2D game world that consists of static circle colliders. The player is dynamic. I need collision point to check whether player's trajectory(path from which he came from) tangent to circle collider or not, so I can't use Trigger. But I also need to allow player pass through collider.
How can I solve the problem?2dcollisioncollidertriggertangentFri, 17 Feb 2017 09:14:07 GMTiamdenayHow can I detect a collision point, but allow player to pass through collider.
http://answers.unity.com/questions/1314110/how-can-i-detect-a-collision-point-but-allow-playe.html
I have a Unity project in which there is a 2D game world that consists of static circle colliders. The player is dynamic. ***I need collision point*** to check whether player's trajectory(path from which he came from) ***tangent*** to circle collider or not, so I can't use Trigger. But I also need to allow player ***pass through collider***. I cannot use Trigger, because I need collision point. How can I solve the problem? Thanks!2dcollisioncollidertriggertangentThu, 16 Feb 2017 13:44:36 GMTiamdenayTangent Space Normal Map to World Space Normal Vector in C# Script
http://answers.unity.com/questions/1308536/tangent-space-normal-map-to-world-space-normal-vec.html
I am writing a path tracer in C# using Physics.Raycast, and I want to implement normal maps. When an object is hit by a raycast, I can correctly sample its normal map at the proper uv, then I convert the rgb pixel into an xyz vector. Once I have this normal vector, which is measured in the object's tangent space, I need to transform it into world space. I know this involves finding the tangent and binormal vectors to the surface, but I am unsure how to do so. Is there any consistent way of determining these vectors so that the results will match a normal-mapped shader?raycastingvectornormalmaptangentSat, 04 Feb 2017 09:50:16 GMTtaylorulesFinding distance of player to a path in 3D
http://answers.unity.com/questions/1201367/finding-distance-of-player-to-a-path-in-3d.html
I have a path in 3D (sort of a travel in space situation - Go from planet A to planet B). At the beginning of the game I show the path to be followed by the player using a thin line. The player is supposed to stay as close to the line as possible. If they move more than a certain distance x from the path, the player should automatically start moving towards the center.
For example - if the path is circular, and the player moves away from the circle, I want to calculate how far the player is from the path, then find the normal direction of the player to the circle, and push the player along that vector.
How do I find the distance of the player from the path? Keep in mind I need the shortest distance. I can't really find the distance of the player to each point on the path and then use the shortest one; as it will be very expensive. Is there a way to do this? Also, how do I find the direction vector?
Thank youdistancenormalspathfollowingtangentSun, 12 Jun 2016 07:02:24 GMTshreypareek1991How to get tangential velocity of revolving object?
http://answers.unity.com/questions/1167692/how-to-get-tangential-velocity-of-revolving-object.html
So I have this empty game object which is rotating. Now this has a sphere object as its child. So when the parent point object rotates, the child sphere appears to be revolving around it. I want to know the velocity of that sphere, specifically, its tangential velocity.
When I debug, I find all the components of the sphere rigid body velocity/angular velocity to be (0,0,0). Can anyone please tell me how can I attain this..rotationvelocitysphereangularvelocitytangentFri, 08 Apr 2016 16:46:04 GMTjajan_psContinuing rotation of circle from new point on screen by touch
http://answers.unity.com/questions/1155410/continuing-rotation-of-circle-from-new-point-on-sc.html
Hello,I have circle in my game that i use to rotate while draging my finger on the screen.When i take finger off the screen,and then drag from another place,the circle should continue rotating from previous rotation instead of instantly changing rotation.It kinda works but my problem is that sometimes - I can't tell when that happens exactly,the circle jumps to new rotation instead of continuation.Can someone tell me where i have error in my script?
Here's the exact part of the script :
if (Input.touchCount > 0)
{
Vector3 pos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(pos.x, pos.y);
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
startAngle = Mathf.Atan2(touchPos.y,touchPos.x) * Mathf.Rad2Deg;
if (startAngle <= 0)
{
startAngle += 360;
}
}
angle = Mathf.Atan2(touchPos.y, touchPos.x) * Mathf.Rad2Deg;
if(angle < 0)
angle += 360;
distanceAngle = startAngle - endAngle;
angle -= distanceAngle;
if (angle < 0)
angle += 360;
else if (angle > 360)
angle -= 360;
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
endAngle = angle;
}
circle.rotation = Quaternion.Euler(0f, 0f,angle);rotationtouchanglecircletangentTue, 15 Mar 2016 16:04:40 GMTBartol0ll0Asset Bundle and Mesh Missing Tangents
http://answers.unity.com/questions/1103799/asset-bundle-and-mesh-missing-tangents.html
I just tracked down a problem in a game we are making, that turned out to be caused by a mesh loaded from an asset bundle not having any tangents.
The symptom was that, on some devices (Nexus 6 and iPad Mini 1st gen, as examples), a mesh was not rendering properly - the lighting was wrong, and the mesh just looked bad. Upon some investigation, we discovered that the problem would go away if we did not load the mesh from an asset bundle, and had the mesh built directly into the build. This, however, was not a valid solution, as the build was already close to the 100MB IPA limit. Upon further investigation, I discovered that the mesh did not have any tangents loaded, but only when built into the asset bundle. The lack of tangents was visible in editor (which did not have the rendering problem), as well as on the problematic devices. I confirmed this both by checking the Mesh.tangents array size, as well as hacking the shader to output the tangents as the color, whereby they were completely black when loaded from an asset bundle, but seemed reasonable when loaded straight from the main package. The fbx in both cases is identical, as well as the import settings, where Tangents is set to Calculate.
I was able to work around the problem by adding code to calculate tangents on the meshes loaded from asset bundles, however this is less than ideal as it requires the meshes to be set to "Read/Write Enabled", as well as just requiring extra load time.
The question then is: Is this a known problem in Unity 4.6? Is there something wrong with the way we are building or loading the asset bundles. Is there a better way to work around the problem?
For building the asset bundle, we are using BuildPipeline.BuildAssetBundle with a potentially different asset as the main asset (this bundle has a few meshes in it, two of which have the problem), and the mesh's FBX is in the assets list. We are using the options: CollectDependencies | DeterministicAssetBundle. I have also tried adding CompleteAssets to that list, however it had no effect. The download of the asset bundle is occurring with WWW.LoadFromCacheOrDownload, and the load then uses AssetBundle.LoadAll().
We have are using Unity 4.6.8f1 and 4.6.7f1 for Android, and 4.6.8p3 (the version distributed on the forums) for iOS.assetbundleunity 4.6unity 4tangenttangentsFri, 27 Nov 2015 11:04:29 GMTChris KaynorExtending tangent length
http://answers.unity.com/questions/1075638/extending-tangent-length.html
Is there a way to extend a curve's tangent line? Currently unity has it fixed at this weird length that you can't seem to change.
![weird tangent length][1]
[1]: /storage/temp/55448-screen-shot-2015-10-02-at-195745.pnganimatorcurvestangentSat, 03 Oct 2015 01:58:36 GMTi_am_qixNormal mapping mirrored UVs?
http://answers.unity.com/questions/1007165/normal-mapping-mirrored-uvs.html
I have an object that has been mirrored in Blender with the mirror modifier. UV's have been correctly mirrored as normal, but *applying a normal map to the object in Unity causes only one half of the object to be bump mapped*. So after doing some research on the topic I noticed it had something to do incorrect tangents. However, after disabling Unity's tangent importer, I was left with an *unshaded objects*. (No tangents had been imported)
I thought the problem was that .blend files didn't contain tangents, so I exported an FBX with "tangent space" checked. And sure enough, there was bump mapping on both halves of the object. But something is still not right, there is an *obvious seam and the bump mapping on one half looks opposite to the other half*:
![alt text][1]
On the left is the original .blend (with only half bump mapped) and the right is the .fbx with imported tangents (noticeable seam with inverted bump maps). What is going on here?
Side note: previously when I ran into this problem I would just *apply the mirror and recalculate UV's*. This worked when I had **tiled textures** (as I could just scale up UV mapping to compensate for the extra UV coordinates) but now I'm using a **non-tileable** texture, which means I *can't just dump the current UVs*! The mapping is now dependent on the texture being correct in mirrored mode. Thanks in advance!
[1]: http://i58.tinypic.com/35ar8k7.pngshaderimportnormalmapbumpmaptangentTue, 14 Jul 2015 22:08:31 GMTSomeGuy22Scripting Curves, How To Maintain The Shape ?
http://answers.unity.com/questions/949859/scripting-curves-how-to-maintain-the-shape.html
Hello guys, I have a little problem. I am trying to learn how to script AnimationCurves, in order to change my Color Correction Curves Image Effect in runtime. I've figured out the most of it, but still I have a minor glitch to solve. First, here is the default value and the desired value of my red channel :
![alt text][1]
So I wrote this script:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.ImageEffects;
public class IS_ActionImageEffects : MonoBehaviour {
public Transform t_EffectsHolder;
public float f_LerpSpeedRed;
public float f_LerpSpeedRedBack;
public bool b_WaitFirst;
public float f_WaitFirst;
public float f_WaitToLerpBack;
private ColorCorrectionCurves _CorrectionCurves;
private Vector2 v2_OriginalRedKey;
void Awake()
{
_CorrectionCurves = t_EffectsHolder.GetComponent<ColorCorrectionCurves>();
}
void OnEnable()
{
StartCoroutine(LerpRedChannel());
}
IEnumerator LerpRedChannel()
{
if (b_WaitFirst)
yield return new WaitForSeconds(f_WaitFirst);
float i = 0.0f;
float rate = 1.0f / f_LerpSpeedRed;
float f_CurrentTime = _CorrectionCurves.redChannel.keys[1].time;
float f_CurrentValue = _CorrectionCurves.redChannel.keys[1].value;
v2_OriginalRedKey.x = f_CurrentTime;
v2_OriginalRedKey.y = f_CurrentValue;
float f_KeyTime;
float f_KeyValue;
while (i < 1.0f)
{
i += Time.deltaTime * rate;
f_KeyTime = Mathf.Lerp(f_CurrentTime, 0.6f, i);
f_KeyValue = Mathf.Lerp(f_CurrentValue, 0.3f, i);
_CorrectionCurves.redChannel.MoveKey(1, new Keyframe(f_KeyTime, f_KeyValue));
_CorrectionCurves.redChannel.SmoothTangents(1, 1);
_CorrectionCurves.UpdateParameters();
yield return null;
}
yield return new WaitForSeconds(f_WaitToLerpBack);
i = 0.0f;
float rate2 = 1.0f / f_LerpSpeedRedBack;
float f_CurrentTime2 = _CorrectionCurves.redChannel.keys[1].time;
float f_CurrentValue2 = _CorrectionCurves.redChannel.keys[1].value;
while (i < 1.0f)
{
i += Time.deltaTime * rate2;
f_KeyTime = Mathf.Lerp(f_CurrentTime2, v2_OriginalRedKey.x, i);
f_KeyValue = Mathf.Lerp(f_CurrentValue2, v2_OriginalRedKey.y, i);
_CorrectionCurves.redChannel.MoveKey(1, new Keyframe(f_KeyTime, f_KeyValue));
_CorrectionCurves.redChannel.SmoothTangents(1, 1);
_CorrectionCurves.UpdateParameters();
yield return null;
}
}
}
Which lerps 2 values in order to make the change smooth, waits, and lerps those values back. But the problem is, curves get, lets say, broken. I can't maintain the shape, here is the visual of the curve after the first while loop and after the second one :
![alt text][2]
It seems like something to do with my tries to maintain the things by using SmoothTangent, but I've tried:
SmoothTangent(1,0);
SmoothTangent(1,0.5f);
SmoothTangent(1,1);
I've got slightly different results but none of them helped me solve the issue. So, what am I missing? Thanks in advance :)
[1]: /storage/temp/44763-attach1.png
[2]: /storage/temp/44764-attach2.pngsmoothkeysframestangentSat, 18 Apr 2015 19:00:59 GMTInan-EvinCalculating an angle to rotate some tangent around an axis
http://answers.unity.com/questions/934403/calculating-an-angle-to-rotate-some-tangent-around.html
I don't even know how to Google my question to find an answer so I drew a picture, below. I have a weapon who's Field of Fire I'm trying to rotate so a target comes into view.
I've previously been calculating Theta (below) from my weapon's exit aperture and rotating my parent GameObject by that angle, Theta.
![alt text][1]
After drawing it out, I now understand that's not enough since my exit aperture is on the outside radius of (what is effectively) a circle and I always end up with some "error" Theta' (prime).
**I would love a math wiz to help me calculate the angle my circle needs to rotate in order for a target to come into my field of view.** My domain is 2D - everything is on the same y-plane. The center of the circle, target (x,y), radius, exit aperture (x,y) and min/max directions are all known.
[1]: /storage/temp/43476-tangent-around-axis.jpgtangentSat, 28 Mar 2015 01:54:38 GMTsaporterHow can I set my Animation Curve's Tangents to Flat in script?
http://answers.unity.com/questions/870283/how-can-i-set-my-animation-curves-tangents-to-flat.html
I have an animation that I've generated through script with three keyframes. The first is just the resting position, the second moves it down along the y-axis some ways, then the third frame moves it back to the resting position.
In my code, when I create the middle keyframe I am using AnimationCurve.AddKey() which by default will smooth the animation tangents for you. This makes the tangents look like so.
![alt text][1]
The problem with this is that the animation of my y-axis curves underneath my destination which doesn't seem like a lot here but when the animation changes in scale it can dip well underneath half my requested position. What I would like for the tangents to look like is this.
![alt text][2]
I know I can just go into the Animation Window and right click the key frame and sort this all out, but that isn't the question here so pretty please don't recommend that! Thanks for taking the time to read this and I hope you can help me!
Edit : Here is an image where this is REALLY getting out of hand and Unity just takes the flag and runs with it lol.
![alt text][3]
[1]: /storage/temp/38320-notsoflat.png
[2]: /storage/temp/38321-flattangents.png
[3]: http://i.imgur.com/2H8xOVo.pnganimationanimationcurvetangentflatTue, 06 Jan 2015 18:11:40 GMTHronetGenerate cylindrical mesh around 3D Catmull-rom spline
http://answers.unity.com/questions/867023/generate-cylindrical-mesh-around-3d-catmull-rom-sp.html
The spline is curve is defined by 4 points: p0,p1,p2,p3 and drawn between p1 and p2 with a for loop, looping through the number of segments I want. The point on the curve at time t can is being found with this function:
public Vector3 GetSpline(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) {
Vector3 ret = new Vector3();
float t2 = t * t;
float t3 = t * t * t;
ret.x = 0.5f * ((2.0f * p1.x) +
(-p0.x + p2.x) * t +
(2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x) * t2 +
(-p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x) * t3);
ret.y = 0.5f * ((2.0f * p1.y) +
(-p0.y + p2.y) * t +
(2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y) * t2 +
(-p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y) * t3);
ret.z = 0.5f * ((2.0f * p1.z) +
(-p0.z + p2.z) * t +
(2.0f * p0.z - 5.0f * p1.z + 4 * p2.z - p3.z) * t2 +
(-p0.z + 3.0f * p1.z - 3.0f * p2.z + p3.z) * t3);
return ret;
}
I think I can figure out all the mesh generation stuff but I just can't figure out how to get a "normal" vector from the "direction vector" (segmentEnd-segmentStart). I feel like this is stupidly simple.. but my 3d maths isn't that great.
Any idea?
Thanks!vectornormalsplinetangentFri, 02 Jan 2015 07:24:52 GMTDMevilleConverting vortex effect from legacy to Shuriken
http://answers.unity.com/questions/864157/converting-vortex-effect-from-legacy-to-shuriken.html
I'm trying to convert a legacy particle effect to Shuriken. The effect currently swirls particles inwards from a MeshEmitter using tangent velocity, negative normal velocity and tweaking emitter/animator settings with scripting to give it style.
I did some research and the answers I found implied that it couldn't be done easily, or perhaps at all. My experiments were not encouraging. However many of the results I found were years old and implied that the problems were just a beta issue. I haven't found any evidence of significant changes to Shuriken since (I'm currently on 4.5.5).
Is there currently a way to specify tangent velocity and negative normal velocities, or perhaps some other way to achieve the same effect? If not, should I just stick with legacy?
Thanks,
JTparticlesshurikentangentMon, 29 Dec 2014 01:18:47 GMTjefferytitanTrying to set Mesh.tangents = Vector4[] gives error of "An object reference is required to access non-static member `Create_Mesh.mesh'"
http://answers.unity.com/questions/858689/trying-to-set-meshtangents-vector4-gives-error-of.html
hello everyone, so im following [this][1] tutorial on creating a deformable mesh, and aproximately 36 mitutes in the guy creates a function to calculate the tangents, everything seems to work fine for him but i get this error that says "An object reference is required to access non-static member `Create_Mesh.mesh'" clueless of what did I do wrong i thought you guys might have an idea on what it could be. this is the part where the problem seems to be:
private static void RecalculateTangents (Mesh objMesh)
{
int [] triangles = objMesh.triangles;
Vector3 [] vertices = objMesh.vertices;
Vector2 [] uv = objMesh.uv;
Vector3 [] normals = objMesh.normals;
int triangleCount = triangles.Length;
int vertexCount = vertices.Length;
Vector3 [] tan1 = new Vector3[vertexCount];
Vector3 [] tan2 = new Vector3[vertexCount];
Vector4 [] tangents = new Vector4[vertexCount];
for (long a = 0 ; a < triangleCount ; a++)
{
long i1 = triangles[a + 0];
long i2 = triangles[a + 1];
long i3 = triangles[a + 2];
Vector3 v1 = vertices[i1];
Vector3 v2 = vertices[i2];
Vector3 v3 = vertices[i3];
Vector2 w1 = uv[i1];
Vector2 w2 = uv[i2];
Vector2 w3 = uv[i3];
float x1 = v2.x - v1.x;
float x2 = v3.x - v1.x;
float y1 = v2.y - v1.y;
float y2 = v3.y - v1.y;
float z1 = v2.z - v1.z;
float z2 = v3.z - v1.z;
float s1 = w2.x - w1.x;
float s2 = w3.x - w1.x;
float t1 = w2.y - w1.y;
float t2 = w3.y - w1.y;
float div = s1 * t2 - s2 * t1;
float r = div == 0.0f ? 0.0f : 1.0f / div;
Vector3 sdir = new Vector3 ((t2 * x1 - t1 * x2) * r, (t2 * y1 + t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
Vector3 tdir = new Vector3 ((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
tan1[i1] += sdir;
tan1[i2] += sdir;
tan1[i3] += sdir;
tan2[i1] += tdir;
tan2[i2] += tdir;
tan2[i3] += tdir;
}
for (long a = 0; a < vertexCount; a ++)
{
Vector3 n = normals[a];
Vector3 t = tan1[a];
Vector3.OrthoNormalize(ref n, ref t);
tangents[a].x = t.x;
tangents[a].y = t.y;
tangents[a].z = t.z;
tangents[a].w = (Vector3.Dot(Vector3.Cross(n, t), tan2[a]) < 0.0f) ? -1.0f : 1.0f;
}
mesh.tangents = tangents;
}
[1]: https://www.youtube.com/watch?v=hL0TXUY6Vl0&index=66&list=WL
I apreciate your time and thanks a lot in advanced.tangentFri, 19 Dec 2014 23:34:02 GMTthenachotech1113Procedural mesh generation - problem with normals.
http://answers.unity.com/questions/830117/procedural-mesh-generation-problem-with-normals-1.html
I'm trying to make mesh figure generated procedurally but some triangles clearly have broken normals. What is weird, everything is okay during play in editor:
![alt text][1]
But after build game and run it from exe file,has become a strange light on some triangles.
![alt text][2]
On pictures we have exactly same place, but we can see, that some triangles on lava mesh ignore light.
My mesh needs to have normal maps. It of course require tangents so to achieve that, I'm using script avaible at http://www.terathon.com/code/tangent.html and converted to javascript by nootz (http://forum.unity3d.com/threads/how-to-calculate-mesh-tangents.38984/):
/*
Derived from
Lengyel, Eric. “Computing Tangent Space Basis Vectors for an Arbitrary Mesh”. Terathon Software 3D Graphics Library, 2001.
http://www.terathon.com/code/tangent.html
*/
static function TangentSolver(theMesh : Mesh)
{
vertexCount = theMesh.vertexCount;
vertices = theMesh.vertices;
normals = theMesh.normals;
texcoords = theMesh.uv;
triangles = theMesh.triangles;
triangleCount = triangles.length/3;
tangents = new Vector4[vertexCount];
tan1 = new Vector3[vertexCount];
tan2 = new Vector3[vertexCount];
tri = 0;
for ( i = 0; i < (triangleCount); i++)
{
i1 = triangles[tri];
i2 = triangles[tri+1];
i3 = triangles[tri+2];
v1 = vertices[i1];
v2 = vertices[i2];
v3 = vertices[i3];
w1 = texcoords[i1];
w2 = texcoords[i2];
w3 = texcoords[i3];
x1 = v2.x - v1.x;
x2 = v3.x - v1.x;
y1 = v2.y - v1.y;
y2 = v3.y - v1.y;
z1 = v2.z - v1.z;
z2 = v3.z - v1.z;
s1 = w2.x - w1.x;
s2 = w3.x - w1.x;
t1 = w2.y - w1.y;
t2 = w3.y - w1.y;
r = 1.0 / (s1 * t2 - s2 * t1);
sdir = new Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
tdir = new Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
tan1[i1] += sdir;
tan1[i2] += sdir;
tan1[i3] += sdir;
tan2[i1] += tdir;
tan2[i2] += tdir;
tan2[i3] += tdir;
tri += 3;
}
for (i = 0; i < (vertexCount); i++)
{
n = normals[i];
t = tan1[i];
// Gram-Schmidt orthogonalize
Vector3.OrthoNormalize( n, t );
tangents[i].x = t.x;
tangents[i].y = t.y;
tangents[i].z = t.z;
// Calculate handedness
tangents[i].w = ( Vector3.Dot(Vector3.Cross(n, t), tan2[i]) < 0.0 ) ? -1.0 : 1.0;
}
theMesh.tangents = tangents;
return theMesh;
}
Turning off that script fix the problem with broken normals. So there is my question: where lies the problem in attached script and is there other possibility to calculate mesh tangents?
[1]: /storage/temp/35129-normal+normals.jpg
[2]: /storage/temp/35130-broken+normals.jpglightingnormalsprocedural meshtangentWed, 12 Nov 2014 17:43:10 GMTPolak149What is the length of the Keyframe tangent?
http://answers.unity.com/questions/777792/what-is-the-length-of-the-keyframe-tangent.html
Hi guys
I'm trying to make sense of the AnimationCurve and KeyFrame objects.
I've been able to figure out the in/out tangent angles, but I'm not sure how Unity assigns lengths to the tangents.
I had hoped I could simply take 1/3 of the length of the line from the current Keyframe to the next, but this doesn't seem to be correct:
**AnimationCurve editor window (goes from 0,0 to 1,1 - the aspect ratio is just weird)**
![alt text][1]
**My reconstruction**
![alt text][2]
The co-ordinates and tangent angles are all correct, the problem however is the shape of the curve.
Does anyone know what length Unity assigns to Keyframe tangents? Or perhaps it's some function of the angle?
Thanks,
Ves
[1]: http://i.gyazo.com/4b0c8bcc4dbcd906454552bbe3d038e7.png
[2]: http://i.gyazo.com/9154b0779cde549a94f37df1f2c18023.pnganimationcurvekeyframelengthbeziertangentSun, 24 Aug 2014 22:18:32 GMTVesuvianPrimeHow can I get an accurate bounding rect for an AnimationCurve
http://answers.unity.com/questions/762280/how-can-i-get-an-accurate-bounding-rect-for-an-ani.html
Hi guys
I'm currently using the following to get my curve bounding rect:
public static Rect GetBounds(this AnimationCurve extends)
{
if (extends.length == 0)
return new Rect();
float xMin = extends.keys.First().time;
float xMax = extends.keys.Last().time;
float yMin = extends.keys.First().value;
float yMax = yMin;
foreach (Keyframe frame in extends.keys)
{
if (frame.value < yMin)
yMin = frame.value;
if (frame.value > yMax)
yMax = frame.value;
}
return Rect.MinMaxRect(xMin, yMax, xMax, yMin);
}
The problem is that this method doesn't consider the tangents of each KeyFrame.
I presume Unity already has some hidden method for getting the bounding Rect since it is able to focus curves in the curve editor.
Does anyone know how I can get an accurate bounding Rect for my AnimationCurves?
Thanks,
VesboundsrectanimationcurvetangentSat, 02 Aug 2014 18:35:46 GMTVesuvianPrimeHow do I scale an animation curve by time and value while retaining my tangent values?
http://answers.unity.com/questions/707390/how-do-i-scale-an-animation-curve-by-time-and-valu.html
I have an artist defined animationCurve that is supposed to describe how an object comes to a stop. The first key frame is at 0, 1 and the last is at 1, 0. I need to scale that curve's time by stopTime and its value by maxSpeed.
Here is a test I did:
///////////////////////////
using UnityEngine;
using System.Collections;
public class AnimCurveScaleTest : MonoBehaviour {
public AnimationCurve artistCurve;
public AnimationCurve scaledCurve;
Keyframe[] tempKeys;
float speed = 1000f;
float stopTime = 0.5f;
// Use this for initialization
void Start () {
tempKeys = new Keyframe[artistCurve.length];
for ( int i = 0; i < artistCurve.length; i++ ) {
tempKeys[i] = new Keyframe(
artistCurve[i].time * stopTime,
artistCurve[i].value * speed,
artistCurve[i].inTangent,
artistCurve[i].outTangent
);
}
scaledCurve = new AnimationCurve( tempKeys );
}
}
//////////////////////////////
And this is the result:
![alt text][1]
[1]: https://dl.dropboxusercontent.com/u/36289/xfer/2014/Unity_Answers_AnimationCurve_Tangents.jpgc#animationcurvekeyframetangentTue, 13 May 2014 23:57:59 GMTMatt-Ostgardfind the tangent of a box / circle collider
http://answers.unity.com/questions/707106/find-the-tangent-of-a-box-circle-collider.html
I am trying to find the tangent of a box collier to add an explosion force, which isn't built in to unity 2D
It should find either the ray, or the point where the tangent hits.
Any ideas on how to do that?
Thanks in advance.2d2d-physicsboxcollidertangentTue, 13 May 2014 16:31:48 GMTOrbitGamesWeird Animation clip curves tangents
http://answers.unity.com/questions/670994/weird-animation-clip-curves-tangents.html
When i create an animation curve with custom keyframes in C#, the result curve has strange tangents. Here's an image which rapresents the problem:
![alt text][1]
The final result show be: ![alt text][2]
I want to know how can i solve this problem... Thanks for your replies...
**EDIT:**
This is a piece of code:
currKeyframe = -frameStep; nextKeyframe();
Keyframe[] keysPosX = new Keyframe[totalFrames], keysPosY = new Keyframe[totalFrames], keysPosZ = new Keyframe[totalFrames];
Keyframe[] keysRotX = new Keyframe[totalFrames], keysRotY = new Keyframe[totalFrames], keysRotZ = new Keyframe[totalFrames], keysRotW = new Keyframe[totalFrames];
float frameRate = animation.clip.frameRate;
for(int k = 0; k < totalFrames; k++)
{
keysPosX[k] = new Keyframe(frameStep * k / frameRate, currTransform.localPosition.x);
keysPosY[k] = new Keyframe(frameStep * k / frameRate, currTransform.localPosition.y);
keysPosZ[k] = new Keyframe(frameStep * k / frameRate, currTransform.localPosition.z);
keysRotX[k] = new Keyframe(frameStep * k / frameRate, currTransform.localRotation.x);
keysRotY[k] = new Keyframe(frameStep * k / frameRate, currTransform.localRotation.y);
keysRotZ[k] = new Keyframe(frameStep * k / frameRate, currTransform.localRotation.z);
keysRotW[k] = new Keyframe(frameStep * k / frameRate, currTransform.localRotation.w);
nextKeyframe();
}
AnimationCurve cPosX = new AnimationCurve(keysPosX), cPosY = new AnimationCurve(keysPosY), cPosZ = new AnimationCurve(keysPosZ), cRotX = new AnimationCurve(keysRotX), cRotY = new AnimationCurve(keysRotY), cRotZ = new AnimationCurve(keysRotZ), cRotW = new AnimationCurve(keysRotW);
animation.clip.SetCurve(AnimationUtility.CalculateTransformPath(currTransform, transform), typeof(Transform), "localPosition.x", cPosX);
animation.clip.SetCurve(AnimationUtility.CalculateTransformPath(currTransform, transform), typeof(Transform), "localPosition.y", cPosY);
animation.clip.SetCurve(AnimationUtility.CalculateTransformPath(currTransform, transform), typeof(Transform), "localPosition.z", cPosZ);
animation.clip.SetCurve(AnimationUtility.CalculateTransformPath(currTransform, transform), typeof(Transform), "localRotation.x", cRotX);
animation.clip.SetCurve(AnimationUtility.CalculateTransformPath(currTransform, transform), typeof(Transform), "localRotation.y", cRotY);
animation.clip.SetCurve(AnimationUtility.CalculateTransformPath(currTransform, transform), typeof(Transform), "localRotation.z", cRotZ);
animation.clip.SetCurve(AnimationUtility.CalculateTransformPath(currTransform, transform), typeof(Transform), "localRotation.w", cRotW);
[1]: /storage/temp/24097-image.png
[2]: /storage/temp/24099-image2.pnganimationclipcurvetangentSun, 23 Mar 2014 11:10:05 GMTqwee