private static ECS_Skeleton_Frame ConvertVAnimToAnim(V_Skeleton_Frame vSkeletonFrame)
        {
            UVType  uvType = vSkeletonFrame.GetUVType();
            Vector2 uv00, uv11;

            uvType.GetUVCoords(out uv00, out uv11);
            float2 skeletonPos = new float2(vSkeletonFrame.pos.x, vSkeletonFrame.pos.y);

            return(new ECS_Skeleton_Frame {
                quad = new Quad {
                    quadVertices = new QuadVertices {
                        v00 = skeletonPos + new float2(vSkeletonFrame.v00.x + vSkeletonFrame.v00offset.x, vSkeletonFrame.v00.y + vSkeletonFrame.v00offset.y),
                        v01 = skeletonPos + new float2(vSkeletonFrame.v01.x + vSkeletonFrame.v01offset.x, vSkeletonFrame.v01.y + vSkeletonFrame.v01offset.y),
                        v10 = skeletonPos + new float2(vSkeletonFrame.v10.x + vSkeletonFrame.v10offset.x, vSkeletonFrame.v10.y + vSkeletonFrame.v10offset.y),
                        v11 = skeletonPos + new float2(vSkeletonFrame.v11.x + vSkeletonFrame.v11offset.x, vSkeletonFrame.v11.y + vSkeletonFrame.v11offset.y),
                    },
                    quadUV = new QuadUV {
                        uv00 = new float2(uv00.x, uv00.y),
                        //uv01 = new float2(uv00.x, uv11.y),
                        //uv10 = new float2(uv11.x, uv00.y),
                        uv11 = new float2(uv11.x, uv11.y),
                    }
                }
            });
        }
Example #2
0
    /// <summary>
    /// Creates a SuperPlane game object on the XZ plane from the given rectangle, Y=0, facing +Y. This function will build the mesh right away.
    /// </summary>
    /// <param name="aRect">A rectangle describing the location and size of the plane on the XZ axis</param>
    /// <param name="aMaterial">The material to assign to it, don't want that awful pink color!</param>
    /// <param name="aType">What type of UV coordinates do you want on the plane?</param>
    /// <param name="aSliceDistance">How far apart should extra verts be spaced out on the surface? 0 for none at all. floor(size/sliceDistance)</param>
    /// <returns>A ready-to-go SuperPlane GameObject named "SuperPlane" with a with a fully built SuperPlane, MeshFilter, Renderer, and BoxCollider component!</returns>
    public static GameObject CreateRectXZ(Rect aRect, Material aMaterial, UVType aType = UVType.Unit, float aSliceDistance = 0)
    {
        Vector3 middle  = new Vector3(aRect.xMin + aRect.width / 2, 0, aRect.yMin - aRect.height / 2);
        Vector2 extents = new Vector2(aRect.width, aRect.height);

        return(Create(middle, extents, aMaterial, aType, aSliceDistance));
    }
Example #3
0
 public void RemoveUVGroup(UVType uvType)
 {
     for (int i = 0; i < MeshObjectList.Count; ++i)
     {
         MeshObjectList[i].RemoveUVGroup(uvType);
     }
 }
Example #4
0
 public NullUVGroup()
 {
     mUVScale    = 1.0;
     mUVType     = UVType.UVT_DEFAULT;
     mUVDataType = NullDataStructType.DST_FLOAT;
     mUVArray    = new List <Vector2>();
 }
Example #5
0
 public void RemoveUVGroup(UVType uvType)
 {
     if (uvType == UVType.UVT_DEFAULT)
     {
         return;
     }
     mUVGroupList.RemoveAll((uvGroup) => { return(uvGroup.GetUVType() == uvType); });
 }
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    {
        Material targetMat = materialEditor.target as Material;

        Undo.RecordObject(targetMat, targetMat.name);
        bool useMotionVector = targetMat.GetShaderPassEnabled("MotionVector");

        useMotionVector = EditorGUILayout.Toggle("MotionVector", useMotionVector);
        targetMat.SetShaderPassEnabled("MotionVector", useMotionVector);
        UVType    mainTexUseUV1   = targetMat.IsKeywordEnabled("FIRST_TEX_USE_UV1") ? UVType.UV1 : UVType.UV0;
        UVType    secondTexUseUV1 = targetMat.IsKeywordEnabled("SECOND_TEX_USE_UV1") ? UVType.UV1 : UVType.UV0;
        BlendMode blendAdd        = targetMat.IsKeywordEnabled("BLEND_ADD") ? BlendMode.Add : BlendMode.Multiple;

        mainTexUseUV1   = (UVType)EditorGUILayout.EnumPopup("MainTex UV Type", mainTexUseUV1);
        secondTexUseUV1 = (UVType)EditorGUILayout.EnumPopup("SecondaryTex UV Type", secondTexUseUV1);
        blendAdd        = (BlendMode)EditorGUILayout.EnumPopup("Texture Blend Mode", blendAdd);
        bool useCutoff = targetMat.GetTexture("_CutOffTex");

        if (blendAdd == BlendMode.Add)
        {
            targetMat.EnableKeyword("BLEND_ADD");
        }
        else
        {
            targetMat.DisableKeyword("BLEND_ADD");
        }
        if (mainTexUseUV1 == UVType.UV1)
        {
            targetMat.EnableKeyword("FIRST_TEX_USE_UV1");
        }
        else
        {
            targetMat.DisableKeyword("FIRST_TEX_USE_UV1");
        }
        if (secondTexUseUV1 == UVType.UV1)
        {
            targetMat.EnableKeyword("SECOND_TEX_USE_UV1");
        }
        else
        {
            targetMat.DisableKeyword("SECOND_TEX_USE_UV1");
        }
        if (useCutoff)
        {
            targetMat.EnableKeyword("CUT_OFF");
            targetMat.SetInt("_ZWrite", 0);
            targetMat.SetInt("_ZTest", (int)UnityEngine.Rendering.CompareFunction.Equal);
            targetMat.renderQueue = 2450;
        }
        else
        {
            targetMat.DisableKeyword("CUT_OFF");
            targetMat.SetInt("_ZWrite", 1);
            targetMat.SetInt("_ZTest", (int)UnityEngine.Rendering.CompareFunction.Less);
            targetMat.renderQueue = 2000;
        }
        base.OnGUI(materialEditor, properties);
    }
Example #7
0
    /// <summary>
    /// Creates a SuperPlane game object on the XY plane from the given rectangle, Z=0, facing -Z. This function will build the mesh right away.
    /// </summary>
    /// <param name="aRect">A rectangle describing the location and size of the plane on the XY axis</param>
    /// <param name="aMaterial">The material to assign to it, don't want that awful pink color!</param>
    /// <param name="aType">What type of UV coordinates do you want on the plane?</param>
    /// <param name="aSliceDistance">How far apart should extra verts be spaced out on the surface? 0 for none at all. floor(size/sliceDistance)</param>
    /// <returns>A ready-to-go SuperPlane GameObject named "SuperPlane" with a with a fully built SuperPlane, MeshFilter, Renderer, and BoxCollider component!</returns>
    public static GameObject CreateRectXY(Rect aRect, Material aMaterial, UVType aType = UVType.Unit, float aSliceDistance = 0)
    {
        Vector3    middle  = new Vector3(aRect.xMin + aRect.width / 2, aRect.yMin - aRect.height / 2, 0);
        Vector2    extents = new Vector2(aRect.width, aRect.height);
        GameObject go      = Create(middle, extents, aMaterial, aType, aSliceDistance);

        go.transform.localEulerAngles = new Vector3(-90, 0, 0);
        return(go);
    }
Example #8
0
        public NullUVGroup AppendUV(UVType uvType, int uvSize)
        {
            NullUVGroup group = this[uvType];

            if (group != null)
            {
                return(null);
            }
            group = new NullUVGroup(CurrentVersion, uvType, uvSize);
            mUVGroupList.Add(group);
            return(group);
        }
Example #9
0
    /// <summary>
    /// Creates a SuperCube game object, and assigns the given data! This function will build the cube mesh right away.
    /// </summary>
    /// <param name="aAt">The center of the SuperCube.</param>
    /// <param name="aSize">The width, height, and depth of the SuperCube.</param>
    /// <param name="aMaterial">The default material for the entire SuperCube.</param>
    /// <param name="aWallUV">The type of UV calculations to use for the +X, -X, +Z, -Z faces.</param>
    /// <param name="aTopBottomUV">The type of UV calculations to use for the +Y, -Y faces.</param>
    /// <param name="aSliceDistance">How far apart shall we try and place vertex slices on the faces? floor(size/sliceDistance)</param>
    /// <param name="aHideFaces">A bit mask describing which faces should be hidden.</param>
    /// <param name="aOverrideTop">Material override for the +Y face.</param>
    /// <param name="aOverrideBottom">Material override for the -Y face.</param>
    /// <param name="aOverrideLeft">Material override for the -X face.</param>
    /// <param name="aOverrideRight">Material override for the +X face.</param>
    /// <param name="aOverrideFront">Material override for the -Z face.</param>
    /// <param name="aOverrideBack">Material override for the +Z face.</param>
    /// <returns>A GameObject named "SuperCube" with a fully built SuperCube, MeshFilter, Renderer, and BoxCollider component!</returns>
    public static GameObject Create(Vector3 aAt, Vector3 aSize, Material aMaterial, UVType aWallUV = UVType.WorldCoordinates, UVType aTopBottomUV = UVType.WorldCoordinates, float aSliceDistance = 0, PivotType aHideFaces = PivotType.None, Material aOverrideTop = null, Material aOverrideBottom = null, Material aOverrideLeft = null, Material aOverrideRight = null, Material aOverrideFront = null, Material aOverrideBack = null)
    {
        GameObject go  = new GameObject("SuperCube");
        SuperCube  box = go.AddComponent <SuperCube>();

        box.mWallUVType        = aWallUV;
        box.mTopBottomUVType   = aTopBottomUV;
        box.Extents            = aSize;
        box.transform.position = aAt;
        if (aSliceDistance > 0)
        {
            box.mSliceDistance = aSliceDistance;
            box.mSliceFaces    = true;
        }

        if ((aHideFaces & PivotType.Back) > 0)
        {
            box.FaceBack = false;
        }
        if ((aHideFaces & PivotType.Bottom) > 0)
        {
            box.FaceBottom = false;
        }
        if ((aHideFaces & PivotType.Front) > 0)
        {
            box.FaceFront = false;
        }
        if ((aHideFaces & PivotType.Left) > 0)
        {
            box.FaceLeft = false;
        }
        if ((aHideFaces & PivotType.Right) > 0)
        {
            box.FaceRight = false;
        }
        if ((aHideFaces & PivotType.Top) > 0)
        {
            box.FaceTop = false;
        }

        box.mOverrideBack   = aOverrideBack;
        box.mOverrideFront  = aOverrideFront;
        box.mOverrideTop    = aOverrideTop;
        box.mOverrideBottom = aOverrideBottom;
        box.mOverrideLeft   = aOverrideLeft;
        box.mOverrideRight  = aOverrideRight;

        box.Build(true);
        go.GetComponent <Renderer>().sharedMaterial = aMaterial;

        go.AddComponent <BoxCollider>();
        return(go);
    }
Example #10
0
 public NullUVGroup this[UVType uvType]
 {
     get
     {
         for (int i = 0; i < GetUVGroupCount(); i++)
         {
             NullUVGroup group = mUVGroupList[i];
             if (group.GetUVType() == uvType)
             {
                 return(group);
             }
         }
         return(null);
     }
 }
Example #11
0
        public bool LoadFromStream(NullMemoryStream stream)
        {
            Clear();
            bool res = stream.ReadList(out mUVArray);

            if (mUVArray.Count == 0)
            {
                return(res);
            }
            byte b;

            res        &= stream.ReadByte(out b);
            mUVType     = (UVType)b;
            res        &= stream.ReadByte(out b);
            mUVDataType = (NullDataStructType)b;
            return(res);
        }
Example #12
0
    void LoadSettings()
    {
        _uvType = (UVType)EditorPrefs.GetInt("VP_IT_UV", (int)UVType.UV1);
        _tile   = new Vector2(EditorPrefs.GetFloat("VP_IT_TileX", 1f), EditorPrefs.GetFloat("VP_IT_TileY", 1f));
        _offset = new Vector2(EditorPrefs.GetFloat("VP_IT_OffsetX", 1f), EditorPrefs.GetFloat("VP_IT_OffsetY", 1f));

        string s = EditorPrefs.GetString("VP_IT_TX", "null");

        if (s == "null")
        {
            _texture = null;
        }
        else
        {
            texture = AssetDatabase.LoadAssetAtPath(s, typeof(Texture2D)) as Texture2D;
        }
    }
Example #13
0
        public static Vector2 GetUV(Matrix4x4 aTransform, UVType aUVType, Vector3 aPt, Vector3 aNorm, float aUStart, float aUEnd, float aPercentX, float aPercentY)
        {
            Vector2 uv = new Vector2(aPercentX + 0.5f, (aPercentY) + 0.5f);

            if (aUVType == UVType.WallSlide)
            {
                uv = new Vector2(Mathf.Lerp(aUEnd, aUStart, aPercentX + 0.5f), aPercentY + 0.5f);
            }
            else if (aUVType == UVType.WorldCoordinates)
            {
                uv = PosToUV(aTransform.MultiplyPoint3x4(aPt), aTransform.MultiplyVector(aNorm));
            }
            else if (aUVType == UVType.LocalCoordinates)
            {
                uv = PosToUV(aPt, aNorm);
            }
            return(uv);
        }
Example #14
0
    /// <summary>
    /// Creates a SuperPlane game object, and assigns the given data! This function will build the mesh right away.
    /// </summary>
    /// <param name="aAt">Location in world space.</param>
    /// <param name="aSize">The width and height of the SuperPlane.</param>
    /// <param name="aMaterial">The material to assign to it, don't want that awful pink color!</param>
    /// <param name="aType">What type of UV coordinates do you want on the plane?</param>
    /// <param name="aSliceDistance">How far apart should extra verts be spaced out on the surface? 0 for none at all. floor(size/sliceDistance)</param>
    /// <returns>A ready-to-go SuperPlane GameObject named "SuperPlane" with a with a fully built SuperPlane, MeshFilter, Renderer, and BoxCollider component!</returns>
    public static GameObject Create(Vector3 aAt, Vector2 aSize, Material aMaterial, UVType aType = UVType.Unit, float aSliceDistance = 0)
    {
        GameObject go    = new GameObject("SuperPlane");
        SuperPlane plane = go.AddComponent <SuperPlane>();

        plane.mUVType            = aType;
        plane.Extents            = new Vector3(aSize.x, 0, aSize.y);
        plane.transform.position = aAt;
        if (aSliceDistance > 0)
        {
            plane.mSliceDistance = aSliceDistance;
            plane.mSliceFaces    = true;
        }
        plane.Build(true);
        go.GetComponent <Renderer>().sharedMaterial = aMaterial;

        go.AddComponent <BoxCollider>();
        return(go);
    }
Example #15
0
    Vector2[] GetUV(Vector2 frontPivot, Vector3 uvSize, UVType uVType)
    {
        Vector2[] uvVector2 = null;

        switch (uVType)
        {
        case UVType.FL:
            uvVector2 = GetUVFL(frontPivot, uvSize);
            break;

        case UVType.FB:
            uvVector2 = GetUVFB(frontPivot, uvSize);
            break;
        }

        if (uvVector2 == null)
        {
            Debug.LogWarning(" 처리하지 않은 사항");
        }
        return(uvVector2);
    }
Example #16
0
	/// <summary>
	/// Creates a SuperPlane game object on the XY plane from the given rectangle, Z=0, facing -Z. This function will build the mesh right away.
	/// </summary>
	/// <param name="aRect">A rectangle describing the location and size of the plane on the XY axis</param>
	/// <param name="aMaterial">The material to assign to it, don't want that awful pink color!</param>
	/// <param name="aType">What type of UV coordinates do you want on the plane?</param>
	/// <param name="aSliceDistance">How far apart should extra verts be spaced out on the surface? 0 for none at all. floor(size/sliceDistance)</param>
	/// <returns>A ready-to-go SuperPlane GameObject named "SuperPlane" with a with a fully built SuperPlane, MeshFilter, Renderer, and BoxCollider component!</returns>
	public static GameObject CreateRectXY(Rect    aRect,              Material aMaterial, UVType aType = UVType.Unit, float aSliceDistance = 0) {
		Vector3    middle  = new Vector3(aRect.xMin + aRect.width/2, aRect.yMin - aRect.height/2, 0);
		Vector2    extents = new Vector2(aRect.width, aRect.height);
		GameObject go      = Create(middle, extents, aMaterial, aType, aSliceDistance);
		go.transform.localEulerAngles = new Vector3(-90, 0, 0);
		return go;
	}
Example #17
0
	/// <summary>
	/// Creates a SuperPlane game object on the XZ plane from the given rectangle, Y=0, facing +Y. This function will build the mesh right away.
	/// </summary>
	/// <param name="aRect">A rectangle describing the location and size of the plane on the XZ axis</param>
	/// <param name="aMaterial">The material to assign to it, don't want that awful pink color!</param>
	/// <param name="aType">What type of UV coordinates do you want on the plane?</param>
	/// <param name="aSliceDistance">How far apart should extra verts be spaced out on the surface? 0 for none at all. floor(size/sliceDistance)</param>
	/// <returns>A ready-to-go SuperPlane GameObject named "SuperPlane" with a with a fully built SuperPlane, MeshFilter, Renderer, and BoxCollider component!</returns>
	public static GameObject CreateRectXZ(Rect    aRect,              Material aMaterial, UVType aType = UVType.Unit, float aSliceDistance = 0) {
		Vector3 middle  = new Vector3(aRect.xMin + aRect.width/2, 0, aRect.yMin - aRect.height/2);
		Vector2 extents = new Vector2(aRect.width, aRect.height);
		return Create(middle, extents, aMaterial, aType, aSliceDistance);
	}
Example #18
0
	/// <summary>
	/// Creates a SuperPlane game object, and assigns the given data! This function will build the mesh right away.
	/// </summary>
	/// <param name="aPivotPt">Location to place the pivot point of the object. This is not the actual position of the object after the pivot is applied.</param>
	/// <param name="aPivotType">A bit flag that represents where the pivot is located. This only accepts Top, Bottom, Left, Right flag options, Top being +Z</param>
	/// <param name="aSize">The width and height of the SuperPlane.</param>
	/// <param name="aMaterial">The material to assign to it, don't want that awful pink color!</param>
	/// <param name="aType">What type of UV coordinates do you want on the plane?</param>
	/// <param name="aSliceDistance">How far apart should extra verts be spaced out on the surface? 0 for none at all. floor(size/sliceDistance)</param>
	/// <returns>A ready-to-go SuperPlane GameObject named "SuperPlane" with a with a fully built SuperPlane, MeshFilter, Renderer, and BoxCollider component!</returns>
	public static GameObject CreatePivot (Vector3 aPivotPt, PivotType aPivotType, Vector2 aSize, Material aMaterial, UVType aType = UVType.Unit, float aSliceDistance = 0) {
		Vector2 halfSize = aSize/2;
		Vector3 point    = aPivotPt;
		
		if ((aPivotType & PivotType.Top   ) > 0) {
			point.z -= halfSize.y;
		}
		if ((aPivotType & PivotType.Bottom) > 0) {
			point.z += halfSize.y;
		}
		if ((aPivotType & PivotType.Left  ) > 0) {
			point.x += halfSize.x;
		}
		if ((aPivotType & PivotType.Right ) > 0) {
			point.x -= halfSize.x;
		}
		
		return Create(point, aSize, aMaterial, aType, aSliceDistance);
	}
Example #19
0
	/// <summary>
	/// Creates a SuperPlane game object, and assigns the given data! This function will build the mesh right away.
	/// </summary>
	/// <param name="aAt">Location in world space.</param>
	/// <param name="aSize">The width and height of the SuperPlane.</param>
	/// <param name="aMaterial">The material to assign to it, don't want that awful pink color!</param>
	/// <param name="aType">What type of UV coordinates do you want on the plane?</param>
	/// <param name="aSliceDistance">How far apart should extra verts be spaced out on the surface? 0 for none at all. floor(size/sliceDistance)</param>
	/// <returns>A ready-to-go SuperPlane GameObject named "SuperPlane" with a with a fully built SuperPlane, MeshFilter, Renderer, and BoxCollider component!</returns>
	public static GameObject Create      (Vector3 aAt, Vector2 aSize, Material aMaterial, UVType aType = UVType.Unit, float aSliceDistance = 0) {
		GameObject go    = new GameObject("SuperPlane");
		SuperPlane plane = go.AddComponent<SuperPlane>();
		plane.mUVType = aType;
		plane.Extents = new Vector3(aSize.x, 0, aSize.y);
		plane.transform.position = aAt;
		if (aSliceDistance > 0) {
			plane.mSliceDistance = aSliceDistance;
			plane.mSliceFaces    = true;
		}        
		plane.Build(true);                          
		go.GetComponent<Renderer>().sharedMaterial = aMaterial;

		go.AddComponent<BoxCollider>();
		return go;
	}
Example #20
0
		public static Vector2 GetUV  (Matrix4x4 aTransform, UVType aUVType, Vector3 aPt, Vector3 aNorm, float aUStart, float aUEnd, float aPercentX, float aPercentY) {
			Vector2 uv = new Vector2(aPercentX + 0.5f, (aPercentY) + 0.5f);
			if (aUVType == UVType.WallSlide) {
				uv = new Vector2(Mathf.Lerp(aUEnd, aUStart, aPercentX + 0.5f), aPercentY + 0.5f);
			} else if (aUVType == UVType.WorldCoordinates) {
				uv = PosToUV(aTransform.MultiplyPoint3x4(aPt), aTransform.MultiplyVector(aNorm));
			} else if (aUVType == UVType.LocalCoordinates) {
				uv = PosToUV(aPt, aNorm);
			}
			return uv;
		}
Example #21
0
 private void RadioButtonUV_Checked(object sender, RoutedEventArgs e)
 {
     AuthUV = UVType.UV;
 }
Example #22
0
        public static void AddFace(Matrix4x4 aObjTransform, Matrix4x4 aTransform, float aOffset, UVType aUVType, Vector2 aUVOffset, Vector2 aUVTiling, float aUStart, float aUEnd, int aXSlices, int aYSlices, ref List <Vector3> aVerts, ref List <Vector2> aUVs, ref List <Vector3> aNormals, ref List <Vector4> aTangents, ref List <int> aIndices)
        {
            aXSlices = Mathf.Max(aXSlices, 2);
            aYSlices = Mathf.Max(aYSlices, 2);

            int     startID = aVerts.Count;
            Vector3 normal  = aTransform.MultiplyVector(new Vector3(0, 0, -1)).normalized;

            for (int y = 0; y < aYSlices; y++)
            {
                float percentY = (float)y / (aYSlices - 1) - 0.5f;

                for (int x = 0; x < aXSlices; x++)
                {
                    float   percentX = (float)x / (aXSlices - 1) - 0.5f;
                    Vector3 pt       = new Vector3(percentX, percentY, -aOffset);

                    aVerts.Add(aTransform.MultiplyPoint3x4(pt));
                    aNormals.Add(normal);
                    aUVs.Add(aUVOffset + Vector2.Scale(aUVTiling, GetUV(aObjTransform, aUVType, aVerts[aVerts.Count - 1], aNormals[aVerts.Count - 1], aUStart, aUEnd, percentX, percentY)));

                    if (x > 0 && y > 0)
                    {
                        if ((x + y) % 2 == 0)
                        {
                            aIndices.Add(startID + (x) + (y) * aXSlices);
                            aIndices.Add(startID + (x) + (y - 1) * aXSlices);
                            aIndices.Add(startID + (x - 1) + (y - 1) * aXSlices);

                            aIndices.Add(startID + (x - 1) + (y) * aXSlices);
                            aIndices.Add(startID + (x) + (y) * aXSlices);
                            aIndices.Add(startID + (x - 1) + (y - 1) * aXSlices);
                        }
                        else
                        {
                            aIndices.Add(startID + (x) + (y) * aXSlices);
                            aIndices.Add(startID + (x) + (y - 1) * aXSlices);
                            aIndices.Add(startID + (x - 1) + (y) * aXSlices);

                            aIndices.Add(startID + (x - 1) + (y) * aXSlices);
                            aIndices.Add(startID + (x) + (y - 1) * aXSlices);
                            aIndices.Add(startID + (x - 1) + (y - 1) * aXSlices);
                        }
                    }
                }
            }

            // calculate the tangent!
            Vector3 dir1 = aTransform.MultiplyVector(new Vector3(1, 0, 0));
            Vector3 dir2 = aTransform.MultiplyVector(new Vector3(0, -1, 0));
            Vector2 uv1  = aUVs[startID + 1] - aUVs[startID];
            Vector2 uv2  = aUVs[startID + aXSlices] - aUVs[startID];

            float   r    = 1.0f / uv1.x * uv2.y - uv2.x * uv1.y;
            Vector3 sDir = new Vector3(
                (uv2.y * dir1.x - uv1.y * dir2.x) * r,
                (uv2.y * dir1.y - uv1.y * dir2.y) * r,
                (uv2.y * dir1.z - uv1.y * dir2.z) * r
                );
            Vector3 tDir = new Vector3(
                (uv1.x * dir2.x - uv2.x * dir1.x) * r,
                (uv1.x * dir2.y - uv2.x * dir1.y) * r,
                (uv1.x * dir2.z - uv2.x * dir1.z) * r
                );

            Vector3 ttan = (sDir - aNormals[startID] * Vector3.Dot(aNormals[startID], sDir)).normalized;
            Vector4 tan  = new Vector4(ttan.x, ttan.y, ttan.z, (Vector3.Dot(Vector3.Cross(aNormals[startID], ttan), tDir) < 0) ? -1 : 1);

            for (int i = 0; i < aXSlices * aYSlices; ++i)
            {
                aTangents.Add(tan);
            }
        }
Example #23
0
 public NullUVGroup(int version, UVType type) : this()
 {
     CurrentVersion = version;
     mUVType        = type;
 }
Example #24
0
    /// <summary>
    /// Creates a SuperCube game object using a pivot point to determine location, and assigns the given data! This function will build the cube mesh right away.
    /// </summary>
    /// <param name="aPivotPt">Location in space for the pivot point to be placed.</param>
    /// <param name="aPivotType">A bit mask defining where on the cube the pivot is placed. Opposing sides indicate to center along that axis.</param>
    /// <param name="aSize">The width, height, and depth of the SuperCube.</param>
    /// <param name="aMaterial">The default material for the entire SuperCube.</param>
    /// <param name="aWallUV">The type of UV calculations to use for the +X, -X, +Z, -Z faces.</param>
    /// <param name="aTopBottomUV">The type of UV calculations to use for the +Y, -Y faces.</param>
    /// <param name="aSliceDistance">How far apart shall we try and place vertex slices on the faces? floor(size/sliceDistance)</param>
    /// <param name="aHideFaces">A bit mask describing which faces should be hidden.</param>
    /// <param name="aOverrideTop">Material override for the +Y face.</param>
    /// <param name="aOverrideBottom">Material override for the -Y face.</param>
    /// <param name="aOverrideLeft">Material override for the -X face.</param>
    /// <param name="aOverrideRight">Material override for the +X face.</param>
    /// <param name="aOverrideFront">Material override for the -Z face.</param>
    /// <param name="aOverrideBack">Material override for the +Z face.</param>
    /// <returns>A GameObject named "SuperCube" with a fully built SuperCube, MeshFilter, Renderer, and BoxCollider component!</returns>
    public static GameObject CreatePivot(Vector3 aPivotPt, PivotType aPivotType, Vector3 aSize, Material aMaterial, UVType aWallUV = UVType.WorldCoordinates, UVType aTopBottomUV = UVType.WorldCoordinates, float aSliceDistance = 0, PivotType aHideFaces = PivotType.None, Material aOverrideTop = null, Material aOverrideBottom = null, Material aOverrideLeft = null, Material aOverrideRight = null, Material aOverrideFront = null, Material aOverrideBack = null)
    {
        Vector3 halfSize = aSize / 2;
        Vector3 point    = aPivotPt;

        if ((aPivotType & PivotType.Top) > 0)
        {
            point.y -= halfSize.y;
        }
        if ((aPivotType & PivotType.Bottom) > 0)
        {
            point.y += halfSize.y;
        }
        if ((aPivotType & PivotType.Left) > 0)
        {
            point.x += halfSize.x;
        }
        if ((aPivotType & PivotType.Right) > 0)
        {
            point.x -= halfSize.x;
        }
        if ((aPivotType & PivotType.Front) > 0)
        {
            point.z += halfSize.z;
        }
        if ((aPivotType & PivotType.Back) > 0)
        {
            point.z -= halfSize.z;
        }

        return(Create(point, aSize, aMaterial, aWallUV, aTopBottomUV, aSliceDistance, aHideFaces, aOverrideTop, aOverrideBottom, aOverrideLeft, aOverrideRight, aOverrideFront, aOverrideBack));
    }
Example #25
0
 public NullUVGroup(int version, UVType type, int uvSize) : this()
 {
     CurrentVersion = version;
     mUVType        = type;
     mUVArray       = NullMeshFile.Make <Vector2>(uvSize);
 }
Example #26
0
		public static void AddFace       (Matrix4x4 aObjTransform, Matrix4x4 aTransform, float aOffset, UVType aUVType, Vector2 aUVOffset, Vector2 aUVTiling, float aUStart, float aUEnd, int aXSlices, int aYSlices, ref List<Vector3> aVerts, ref List<Vector2> aUVs, ref List<Vector3> aNormals, ref List<Vector4> aTangents, ref List<int> aIndices) {
			aXSlices = Mathf.Max(aXSlices, 2);
			aYSlices = Mathf.Max(aYSlices, 2);
			
			int       startID = aVerts.Count;
			Vector3   normal  = aTransform.MultiplyVector(new Vector3(0, 0, -1)).normalized;
			
			for (int y = 0; y < aYSlices; y++) {
				float percentY = (float)y / (aYSlices-1) - 0.5f;
				
				for (int x = 0; x < aXSlices; x++) {
					float   percentX = (float)x / (aXSlices-1) - 0.5f;
					Vector3 pt       = new Vector3(percentX, percentY, -aOffset);
					
					aVerts   .Add(aTransform.MultiplyPoint3x4(pt));
					aNormals .Add(normal);
					aUVs     .Add(aUVOffset + Vector2.Scale(aUVTiling, GetUV(aObjTransform, aUVType, aVerts[aVerts.Count-1], aNormals[aVerts.Count-1], aUStart, aUEnd, percentX, percentY)));

					if (x > 0 && y > 0) {
						if ((x+y)%2==0) {
							aIndices.Add(startID + (x  ) + (y  ) * aXSlices);
							aIndices.Add(startID + (x  ) + (y-1) * aXSlices);
							aIndices.Add(startID + (x-1) + (y-1) * aXSlices);
							
							aIndices.Add(startID + (x-1) + (y  ) * aXSlices);
							aIndices.Add(startID + (x  ) + (y  ) * aXSlices);
							aIndices.Add(startID + (x-1) + (y-1) * aXSlices);
						} else {
							aIndices.Add(startID + (x  ) + (y  ) * aXSlices);
							aIndices.Add(startID + (x  ) + (y-1) * aXSlices);
							aIndices.Add(startID + (x-1) + (y  ) * aXSlices);
							
							aIndices.Add(startID + (x-1) + (y  ) * aXSlices);
							aIndices.Add(startID + (x  ) + (y-1) * aXSlices);
							aIndices.Add(startID + (x-1) + (y-1) * aXSlices);
						}
					}
				}
			}
			
			// calculate the tangent!
			Vector3 dir1 = aTransform.MultiplyVector(new Vector3(1,  0, 0));
			Vector3 dir2 = aTransform.MultiplyVector(new Vector3(0, -1, 0));
			Vector2 uv1 = aUVs[startID+1       ] - aUVs[startID];
			Vector2 uv2 = aUVs[startID+aXSlices] - aUVs[startID];
			
			float r = 1.0f / uv1.x * uv2.y - uv2.x * uv1.y;
			Vector3 sDir = new Vector3(
				(uv2.y * dir1.x - uv1.y * dir2.x) * r,
				(uv2.y * dir1.y - uv1.y * dir2.y) * r,
				(uv2.y * dir1.z - uv1.y * dir2.z) * r
			);
			Vector3 tDir = new Vector3(
				(uv1.x * dir2.x - uv2.x * dir1.x) * r,
				(uv1.x * dir2.y - uv2.x * dir1.y) * r,
				(uv1.x * dir2.z - uv2.x * dir1.z) * r
			);
			
			Vector3 ttan = (sDir - aNormals[startID] * Vector3.Dot(aNormals[startID], sDir)).normalized;
			Vector4 tan  = new Vector4(ttan.x, ttan.y, ttan.z, (Vector3.Dot(Vector3.Cross(aNormals[startID], ttan), tDir) < 0) ? -1 : 1);
			for (int i = 0; i < aXSlices * aYSlices; ++i) {
				aTangents.Add(tan);
			}
		}
Example #27
0
	/// <summary>
	/// Creates a SuperCube game object, and assigns the given data! This function will build the cube mesh right away.
	/// </summary>
	/// <param name="aAt">The center of the SuperCube.</param>
	/// <param name="aSize">The width, height, and depth of the SuperCube.</param>
	/// <param name="aMaterial">The default material for the entire SuperCube.</param>
	/// <param name="aWallUV">The type of UV calculations to use for the +X, -X, +Z, -Z faces.</param>
	/// <param name="aTopBottomUV">The type of UV calculations to use for the +Y, -Y faces.</param>
	/// <param name="aSliceDistance">How far apart shall we try and place vertex slices on the faces? floor(size/sliceDistance)</param>
	/// <param name="aHideFaces">A bit mask describing which faces should be hidden.</param>
	/// <param name="aOverrideTop">Material override for the +Y face.</param>
	/// <param name="aOverrideBottom">Material override for the -Y face.</param>
	/// <param name="aOverrideLeft">Material override for the -X face.</param>
	/// <param name="aOverrideRight">Material override for the +X face.</param>
	/// <param name="aOverrideFront">Material override for the -Z face.</param>
	/// <param name="aOverrideBack">Material override for the +Z face.</param>
	/// <returns>A GameObject named "SuperCube" with a fully built SuperCube, MeshFilter, Renderer, and BoxCollider component!</returns>
	public static GameObject Create      (Vector3 aAt,                            Vector3 aSize, Material aMaterial, UVType aWallUV = UVType.WorldCoordinates, UVType aTopBottomUV = UVType.WorldCoordinates, float aSliceDistance = 0, PivotType aHideFaces = PivotType.None, Material aOverrideTop = null, Material aOverrideBottom = null, Material aOverrideLeft = null, Material aOverrideRight = null, Material aOverrideFront = null, Material aOverrideBack = null ) {
		GameObject go  = new GameObject("SuperCube");
		SuperCube  box = go.AddComponent<SuperCube>();
		box.mWallUVType        = aWallUV;
		box.mTopBottomUVType   = aTopBottomUV;
		box.Extents            = aSize;
		box.transform.position = aAt;
		if (aSliceDistance > 0) {
			box.mSliceDistance = aSliceDistance;
			box.mSliceFaces    = true;
		}

		if ((aHideFaces & PivotType.Back  ) > 0 ) box.FaceBack   = false;
		if ((aHideFaces & PivotType.Bottom) > 0 ) box.FaceBottom = false;
		if ((aHideFaces & PivotType.Front ) > 0 ) box.FaceFront  = false;
		if ((aHideFaces & PivotType.Left  ) > 0 ) box.FaceLeft   = false;
		if ((aHideFaces & PivotType.Right ) > 0 ) box.FaceRight  = false;
		if ((aHideFaces & PivotType.Top   ) > 0 ) box.FaceTop    = false;

		box.mOverrideBack   = aOverrideBack;
		box.mOverrideFront  = aOverrideFront;
		box.mOverrideTop    = aOverrideTop;
		box.mOverrideBottom = aOverrideBottom;
		box.mOverrideLeft   = aOverrideLeft;
		box.mOverrideRight  = aOverrideRight;

		box.Build(true);
		go.GetComponent<Renderer>().sharedMaterial = aMaterial;

		go.AddComponent<BoxCollider>();
		return go;
	}
Example #28
0
	/// <summary>
	/// Creates a SuperCube game object using a pivot point to determine location, and assigns the given data! This function will build the cube mesh right away.
	/// </summary>
	/// <param name="aPivotPt">Location in space for the pivot point to be placed.</param>
	/// <param name="aPivotType">A bit mask defining where on the cube the pivot is placed. Opposing sides indicate to center along that axis.</param>
	/// <param name="aSize">The width, height, and depth of the SuperCube.</param>
	/// <param name="aMaterial">The default material for the entire SuperCube.</param>
	/// <param name="aWallUV">The type of UV calculations to use for the +X, -X, +Z, -Z faces.</param>
	/// <param name="aTopBottomUV">The type of UV calculations to use for the +Y, -Y faces.</param>
	/// <param name="aSliceDistance">How far apart shall we try and place vertex slices on the faces? floor(size/sliceDistance)</param>
	/// <param name="aHideFaces">A bit mask describing which faces should be hidden.</param>
	/// <param name="aOverrideTop">Material override for the +Y face.</param>
	/// <param name="aOverrideBottom">Material override for the -Y face.</param>
	/// <param name="aOverrideLeft">Material override for the -X face.</param>
	/// <param name="aOverrideRight">Material override for the +X face.</param>
	/// <param name="aOverrideFront">Material override for the -Z face.</param>
	/// <param name="aOverrideBack">Material override for the +Z face.</param>
	/// <returns>A GameObject named "SuperCube" with a fully built SuperCube, MeshFilter, Renderer, and BoxCollider component!</returns>
	public static GameObject CreatePivot (Vector3 aPivotPt, PivotType aPivotType, Vector3 aSize, Material aMaterial, UVType aWallUV = UVType.WorldCoordinates, UVType aTopBottomUV = UVType.WorldCoordinates, float aSliceDistance = 0, PivotType aHideFaces = PivotType.None, Material aOverrideTop = null, Material aOverrideBottom = null, Material aOverrideLeft = null, Material aOverrideRight = null, Material aOverrideFront = null, Material aOverrideBack = null ) {
		Vector3 halfSize = aSize/2;
		Vector3 point    = aPivotPt;
		
		if ((aPivotType & PivotType.Top   ) > 0) {
			point.y -= halfSize.y;
		}
		if ((aPivotType & PivotType.Bottom) > 0) {
			point.y += halfSize.y;
		}
		if ((aPivotType & PivotType.Left  ) > 0) {
			point.x += halfSize.x;
		}
		if ((aPivotType & PivotType.Right ) > 0) {
			point.x -= halfSize.x;
		}
		if ((aPivotType & PivotType.Front ) > 0) {
			point.z += halfSize.z;
		}
		if ((aPivotType & PivotType.Back ) > 0) {
			point.z -= halfSize.z;
		}
		
		return Create(point, aSize, aMaterial, aWallUV, aTopBottomUV, aSliceDistance, aHideFaces, aOverrideTop, aOverrideBottom, aOverrideLeft, aOverrideRight, aOverrideFront, aOverrideBack);
	}
Example #29
0
    /// <summary>
    /// Creates a SuperPlane game object, and assigns the given data! This function will build the mesh right away.
    /// </summary>
    /// <param name="aPivotPt">Location to place the pivot point of the object. This is not the actual position of the object after the pivot is applied.</param>
    /// <param name="aPivotType">A bit flag that represents where the pivot is located. This only accepts Top, Bottom, Left, Right flag options, Top being +Z</param>
    /// <param name="aSize">The width and height of the SuperPlane.</param>
    /// <param name="aMaterial">The material to assign to it, don't want that awful pink color!</param>
    /// <param name="aType">What type of UV coordinates do you want on the plane?</param>
    /// <param name="aSliceDistance">How far apart should extra verts be spaced out on the surface? 0 for none at all. floor(size/sliceDistance)</param>
    /// <returns>A ready-to-go SuperPlane GameObject named "SuperPlane" with a with a fully built SuperPlane, MeshFilter, Renderer, and BoxCollider component!</returns>
    public static GameObject CreatePivot(Vector3 aPivotPt, PivotType aPivotType, Vector2 aSize, Material aMaterial, UVType aType = UVType.Unit, float aSliceDistance = 0)
    {
        Vector2 halfSize = aSize / 2;
        Vector3 point    = aPivotPt;

        if ((aPivotType & PivotType.Top) > 0)
        {
            point.z -= halfSize.y;
        }
        if ((aPivotType & PivotType.Bottom) > 0)
        {
            point.z += halfSize.y;
        }
        if ((aPivotType & PivotType.Left) > 0)
        {
            point.x += halfSize.x;
        }
        if ((aPivotType & PivotType.Right) > 0)
        {
            point.x -= halfSize.x;
        }

        return(Create(point, aSize, aMaterial, aType, aSliceDistance));
    }
Example #30
0
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    {
        if (ops == null)
        {
            ops = new string[23];
            for (int i = 0; i < 23; ++i)
            {
                ops[i] = "Decal Layer " + i;
            }
        }
        Material targetMat  = materialEditor.target as Material;
        UVType   currUVType = UVType.UV;

        if (targetMat.IsKeywordEnabled("WORLDXZ_UV"))
        {
            currUVType = UVType.WorldPosXZ;
        }
        if (targetMat.IsKeywordEnabled("WORLDXY_UV"))
        {
            currUVType = UVType.WorldPosXY;
        }
        if (targetMat.IsKeywordEnabled("WORLDYZ_UV"))
        {
            currUVType = UVType.WorldPosYZ;
        }
        currUVType = (UVType)EditorGUILayout.EnumPopup("UV Type", currUVType);
        bool useMotionVector = targetMat.GetShaderPassEnabled("MotionVector");

        useMotionVector = EditorGUILayout.Toggle("MotionVector", useMotionVector);
        targetMat.SetShaderPassEnabled("MotionVector", useMotionVector);
        bool targetMatEnabled      = targetMat.IsKeywordEnabled("CUT_OFF");
        bool targetUseTessellation = targetMat.IsKeywordEnabled("USE_TESSELLATION");

        targetUseTessellation = EditorGUILayout.Toggle("Tessellation", targetUseTessellation);
        targetMatEnabled      = EditorGUILayout.Toggle("Cut off", targetMatEnabled);
        int targetDecalLayer = targetMat.GetInt("_DecalLayer");

        targetDecalLayer = EditorGUILayout.MaskField("Decal Layer", targetDecalLayer, ops);
        targetMat.SetInt("_DecalLayer", targetDecalLayer);
        LightingModelType currentType = (LightingModelType)targetMat.GetInt("_LightingModel");

        currentType = (LightingModelType)EditorGUILayout.EnumPopup("Lighting Model", currentType);
        Undo.RecordObject(targetMat, targetMat.name);
        targetMat.SetInt("_LightingModel", (int)currentType);
        if (targetUseTessellation)
        {
            targetMat.EnableKeyword("USE_TESSELLATION");
        }
        else
        {
            targetMat.DisableKeyword("USE_TESSELLATION");
        }
        if (currentType != LightingModelType.Unlit)
        {
            targetMat.EnableKeyword("LIT_ENABLE");
        }
        else
        {
            targetMat.DisableKeyword("LIT_ENABLE");
        }

        switch (currUVType)
        {
        case UVType.UV:
            targetMat.DisableKeyword("WORLDXZ_UV");
            targetMat.DisableKeyword("WORLDXY_UV");
            targetMat.DisableKeyword("WORLDYZ_UV");
            break;

        case UVType.WorldPosXY:
            targetMat.DisableKeyword("WORLDXZ_UV");
            targetMat.EnableKeyword("WORLDXY_UV");
            targetMat.DisableKeyword("WORLDYZ_UV");
            break;

        case UVType.WorldPosYZ:
            targetMat.DisableKeyword("WORLDXZ_UV");
            targetMat.DisableKeyword("WORLDXY_UV");
            targetMat.EnableKeyword("WORLDYZ_UV");
            break;

        case UVType.WorldPosXZ:
            targetMat.EnableKeyword("WORLDXZ_UV");
            targetMat.DisableKeyword("WORLDXY_UV");
            targetMat.DisableKeyword("WORLDYZ_UV");
            break;
        }

        switch (currentType)
        {
        case LightingModelType.DefaultLit:
            targetMat.EnableKeyword("DEFAULT_LIT");
            targetMat.DisableKeyword("SKIN_LIT");
            targetMat.DisableKeyword("CLOTH_LIT");
            targetMat.DisableKeyword("CLEARCOAT_LIT");
            break;

        case LightingModelType.SkinLit:
            targetMat.DisableKeyword("DEFAULT_LIT");
            targetMat.EnableKeyword("SKIN_LIT");
            targetMat.DisableKeyword("CLOTH_LIT");
            targetMat.DisableKeyword("CLEARCOAT_LIT");
            break;

        case LightingModelType.ClothLit:
            targetMat.DisableKeyword("DEFAULT_LIT");
            targetMat.DisableKeyword("SKIN_LIT");
            targetMat.EnableKeyword("CLOTH_LIT");
            targetMat.DisableKeyword("CLEARCOAT_LIT");
            break;

        case LightingModelType.ClearCoat:
            targetMat.DisableKeyword("DEFAULT_LIT");
            targetMat.DisableKeyword("SKIN_LIT");
            targetMat.DisableKeyword("CLOTH_LIT");
            targetMat.EnableKeyword("CLEARCOAT_LIT");
            break;

        default:
            targetMat.DisableKeyword("DEFAULT_LIT");
            targetMat.DisableKeyword("SKIN_LIT");
            targetMat.DisableKeyword("CLOTH_LIT");
            targetMat.DisableKeyword("CLEARCOAT_LIT");
            break;
        }
        if (!targetMatEnabled)
        {
            targetMat.DisableKeyword("CUT_OFF");
            if (targetUseTessellation)
            {
                targetMat.renderQueue = 2450;
            }
            else
            {
                targetMat.renderQueue = 2000;
            }
        }
        else
        {
            targetMat.EnableKeyword("CUT_OFF");
            targetMat.renderQueue = 2451;
        }
        base.OnGUI(materialEditor, properties);
    }
Example #31
0
        /// <summary>
        /// UV情報を利用しMesh上に等間隔に点を配置
        /// </summary>
        /// <param name="data"></param>
        /// <param name="baseMesh"></param>
        /// <param name="evenIntervalOnUV"></param>
        /// <param name="uvType"></param>
        public Data.PointData BuildPointOnMesh(Mesh baseMesh, List <Vector2> evenIntervalOnUV, UVType uvType)
        {
            var data = ScriptableObject.CreateInstance <Data.PointData>();

            var result  = new List <Vector3>();
            var normals = new List <Vector3>();

            Vector2[] uvs;
            if (uvType == UVType.UV)
            {
                uvs = baseMesh.uv;
            }
            else
            {
                uvs = baseMesh.uv2;
            }

            Vector3[] meshVertices = baseMesh.vertices;
            for (int subMesh = 0; subMesh < baseMesh.subMeshCount; subMesh++)
            {
                int[] submeshTriangles = baseMesh.GetTriangles(subMesh);
                for (int i = 0; i < submeshTriangles.Length; i += 3)
                {
                    var calcedUvs = PointCalculator.GetIntermediatePoint(evenIntervalOnUV, i, uvs, submeshTriangles);

                    var meshed = PointCalculator.GetPointsOnMeshSurface(calcedUvs, i, meshVertices, submeshTriangles);

                    var surfNormal = PointCalculator.GetSurfaceNormal(i, meshVertices, submeshTriangles);
                    foreach (var m in meshed)
                    {
                        normals.Add(surfNormal);
                    }

                    result.AddRange(meshed);
                }
            }

            data.points  = result;
            data.normals = normals;
            return(data);
        }