Ejemplo n.º 1
0
	public override void Modify(MegaModifiers mc)
	{
		for ( int i = 0; i < verts.Length; i++ )
		{
			Vector3 p = tm.MultiplyPoint3x4(verts[i]);

			sp.x = p.x * scale + 0.5f;
			sp.y = p.y * scale + 0.5f;
			sp.z = p.z * scale + 0.5f;

			if ( Fractal )
			{
				d.x = iperlin.fBm1(sp.y, sp.z, time, rt, 2.0f, Iterations);
				d.y = iperlin.fBm1(sp.x, sp.z, time, rt, 2.0f, Iterations);
				d.z = iperlin.fBm1(sp.x, sp.y, time, rt, 2.0f, Iterations);
			}
			else
			{
				d.x = iperlin.Noise(sp.y, sp.z, time);
				d.y = iperlin.Noise(sp.x, sp.z, time);
				d.z = iperlin.Noise(sp.x, sp.y, time);
			}

			p.x += d.x * Strength.x;
			p.y += d.y * Strength.y;
			p.z += d.z * Strength.z;

			sverts[i] = invtm.MultiplyPoint3x4(p);
		}
	}
Ejemplo n.º 2
0
    public override void GetSelection(MegaModifiers mc)
    {
        if ( enabled )
        {
            if ( modselection == null || modselection.Length != mc.verts.Length )
                modselection = new float[mc.verts.Length];

            if ( update )
            {
                update = false;

                if ( mc.cols != null && mc.cols.Length > 0 )
                {
                    int c = (int)channel;
                    for ( int i = 0; i < mc.verts.Length; i++ )
                        modselection[i] = ((mc.cols[i][c] - threshold) / (1.0f - threshold)) * weight;
                }
                else
                {
                    for ( int i = 0; i < mc.verts.Length; i++ )
                        modselection[i] = weight;
                }
            }

            mc.selection = modselection;
        }
    }
Ejemplo n.º 3
0
    public override void Modify(MegaModifiers mc)
    {
        for ( int i = 0; i < verts.Length; i++ )
        {
            Vector3 p = tm.MultiplyPoint3x4(verts[i]);
            ip = p;

            sp.x = p.x * scale + 0.5f;	//half;
            sp.z = p.z * scale + 0.5f;	//half;

            float dist = Mathf.Sqrt(p.x * p.x + p.z * p.z);
            float dcy = Mathf.Exp(-decay * Mathf.Abs(dist));

            if ( Fractal )
                d.y = iperlin.fBm1(sp.x, sp.z, time, rt, 2.0f, Iterations);
            else
                d.y = iperlin.Noise(sp.x, sp.z, time);

            p.y += d.y * Strength;

            p.y = ip.y + ((p.y - ip.y) * dcy);

            sverts[i] = invtm.MultiplyPoint3x4(p);
        }
    }
Ejemplo n.º 4
0
    public override void GetSelection(MegaModifiers mc)
    {
        if ( ModEnabled )
        {
            if ( modselection == null || modselection.Length != mc.verts.Length )
                modselection = new float[mc.verts.Length];

            if ( update )
            {
                update = false;

                if ( matnum < 0 )
                    matnum = 0;

                if ( matnum >= mc.mesh.subMeshCount )
                    matnum = mc.mesh.subMeshCount - 1;

                int[] tris = mc.mesh.GetTriangles(matnum);

                for ( int i = 0; i < modselection.Length; i++ )
                    modselection[i] = otherweight;

                for ( int i = 0; i < tris.Length; i++ )
                    modselection[tris[i]] = weight;
            }

            mc.selection = modselection;
        }
    }
Ejemplo n.º 5
0
 public override bool InitMod(MegaModifiers mc)
 {
     bsize = mc.bbox.size;
     bcenter = mc.bbox.center;
     Init();
     return true;
 }
Ejemplo n.º 6
0
    public override void Modify(MegaModifiers mc)
    {
        // Copy the verts to start
        verts.CopyTo(sverts, 0);
        /*
        int vertCount = verts.Length;
        for (int i = 0; i < vertCount; i++) {
            sverts[i] = verts[i];
        }
        */

        // Find [resolution] offsets from source to target shape
        bool type = false;
        int knot = 0;
        float alpha = 0f;
        float step = 1f / (resolution - 1);
        Matrix4x4 trans = transform.worldToLocalMatrix * target.transform.localToWorldMatrix;
        for ( int i = 0; i < resolution; i++ )
        {
            //targetOffsets[i] = trans.MultiplyPoint3x4(target.Interpolate(alpha, type, ref knot)) - sourcePositions[i];
            targetOffsets[i] = trans.MultiplyPoint3x4(target.InterpCurve3D(0, alpha, type)) - sourcePositions[i];
            alpha += step;
        }

        int wireVertCount = wireVerts.Length;
        Debug.Log("Modify() moving " + wireVertCount + " verts.");
        for ( int i = 0; i < wireVertCount; i++ )
        {
            sverts[wireVerts[i].vert] += targetOffsets[wireVerts[i].u] * wireVerts[i].w;
        }
    }
Ejemplo n.º 7
0
    public override void Modify(MegaModifiers mc)
    {
        if ( conformColliders.Count > 0 )
        {
            int ax = (int)axis;

            Vector3 hitpos = Vector3.zero;

            for ( int i = 0; i < verts.Length; i++ )
            {
                Vector3 origin = ctm.MultiplyPoint(verts[i]);
                origin.y += raystartoff;
                ray.origin = origin;
                ray.direction = Vector3.down;

                sverts[i] = verts[i];

                if ( DoRayCast(ray, ref hitpos, raydist) )
                {
                    Vector3 lochit = cinvtm.MultiplyPoint(hitpos);

                    sverts[i][ax] = Mathf.Lerp(verts[i][ax], lochit[ax] + offsets[i] + offset, conformAmount);
                    last[i] = sverts[i][ax];
                }
                else
                {
                    Vector3 ht = ray.origin;
                    ht.y -= raydist;
                    sverts[i][ax] = last[i];
                }
            }
        }
        else
            verts.CopyTo(sverts, 0);
    }
Ejemplo n.º 8
0
	public override void Modify(MegaModifiers mc)
	{
		Vector2[]	uvs = mc.GetSourceUvs();
		Vector2[]	newuvs = mc.GetDestUvs();

		if ( uvs.Length > 0 )
		{
			Vector3 pos = -gizmoPos;
			Vector3 scl = gizmoScale;
			Vector3 rot = gizmoRot;

			Matrix4x4 tm1 = Matrix4x4.identity;
			Vector3 p = Vector3.zero;
			for ( int i = 0; i < uvs.Length; i++ )
			{
				p.x = uvs[i].x - Offset.x - 0.5f;
				p.z = uvs[i].y - Offset.z - 0.5f;
				p.y = 0.0f;

				float d = Mathf.Sqrt(p.x * p.x + p.z * p.z) * spiral;

				rot = new Vector3(gizmoRot.x, gizmoRot.y + d, gizmoRot.z);
				tm1 = Matrix4x4.TRS(pos, Quaternion.Euler(rot), scl);

				p = tm1.MultiplyPoint(p);
				newuvs[i].x = p.x;
				newuvs[i].y = p.z;
			}
		}
	}
Ejemplo n.º 9
0
	void Start()
	{
		if ( source != null )
		{
			context = (MegaModifiers)source.GetComponent<MegaModifyObject>();

			if ( context != null )
			{
				mods = source.GetComponents<MegaModifier>();
				showmod = new bool[mods.Length];
			}

			gcontext = (MegaModifiers)ground.GetComponent<MegaModifyObject>();

			if ( gcontext != null )
			{
				gmods = ground.GetComponents<MegaModifier>();
				showgmod = new bool[gmods.Length];
			}
		}

		//if ( book )
		//{
			//pageturn = book.GetComponent<PageTurn>();
		//}
		//windowRect.yMax = Screen.height - dsize;
		//svh = windowRect.yMax * svd;	//(float)Screen.height * 0.5f;	// - dsize;	//25.0f;	//* 0.955f;
		SizeChange();
	}
Ejemplo n.º 10
0
	//void Reset()
	//{
		//if ( SourceWarpObj != null )
			//warp = SourceWarpObj.GetComponent<Warp>();
	//}

	public override void ModStart(MegaModifiers mc)
	{
		if ( SourceWarpObj != null && SourceWarpObj != current )
		{
			current = SourceWarpObj;
			warp = SourceWarpObj.GetComponent<MegaWarp>();
		}
	}
Ejemplo n.º 11
0
	// remove dups
	void Init(MegaModifiers mod)
	{
		if ( mod.verts == null )
			return;

		List<int> noweights = new List<int>();
		List<int> ActiveVertex = new List<int>();

		int wc = (int)channel;

		for ( int i = 0; i < mod.verts.Length; i++ )
		{
			// Dont add if we have already
			if ( channel == MegaWeightChannel.None || mod.cols == null || mod.cols.Length == 0 )
			{
				//if ( !HavePoint(mod.verts, ActiveVertex, mod.verts[i]) )
					//ActiveVertex.Add(i);
			}
			else
			{
				if ( mod.cols[i][wc] > threshold )
				{
					if ( !HavePoint(mod.verts, ActiveVertex, mod.verts[i]) )
						ActiveVertex.Add(i);
				}
				else
					noweights.Add(i);
			}
		}

		notmoved = noweights.ToArray();

		if ( ActiveVertex.Count > 0 )
		{
			vr = new VertexRubber[ActiveVertex.Count];

			for ( int i = 0; i < ActiveVertex.Count; i++ )
			{
				int ref_index = (int)ActiveVertex[i];

				float stiff = 1.0f;
				if ( stiffchannel != MegaWeightChannel.None && mod.cols != null && mod.cols.Length > 0 )
				{
					stiff = mod.cols[ref_index][(int)stiffchannel];
				}

				//if ( channel != MegaWeightChannel.None && mod.cols != null && mod.cols.Length > 0 )
				float intens = (mod.cols[ref_index][wc] - threshold) / (1.0f - threshold);

				vr[i] = new VertexRubber(transform.TransformPoint(mod.verts[ref_index]), intens, stiff);
				vr[i].indices = FindVerts(mod.verts, mod.verts[ref_index]);
			}
		}
		else
			vr = null;

		defined = true;
	}
Ejemplo n.º 12
0
    public override void Modify(MegaModifiers mc)
    {
        for ( int i = 0; i < verts.Length; i++ )
        {
            Vector3 p = tm.MultiplyPoint3x4(verts[i]);

            // So this mod should transform world point into local space of mod (gizmo offset if OSM, node tm if warp)
            p = warp.Map(i, p);

            sverts[i] = invtm.MultiplyPoint3x4(p);
        }
    }
Ejemplo n.º 13
0
    public override void GetSelection(MegaModifiers mc)
    {
        if ( modselection == null || modselection.Length != mc.verts.Length )
        {
            modselection = new float[mc.verts.Length];
        }

        // we dont need to update if nothing changes
        if ( useCurrentVerts )
        {
            for ( int i = 0; i < verts.Length; i++ )
            {
                float d = Vector3.Distance(origin, verts[i]) - radius;

                if ( d < 0.0f )
                    modselection[i] = 1.0f;
                else
                {
                    float w = Mathf.Exp(-falloff * Mathf.Abs(d));
                    modselection[i] = w;	//mc.cols[i][c];
                }
            }
        }
        else
        {
            for ( int i = 0; i < verts.Length; i++ )
            {
                float d = Vector3.Distance(origin, verts[i]) - radius;

                if ( d < 0.0f )
                    modselection[i] = 1.0f;
                else
                {
                    float w = Mathf.Exp(-falloff * Mathf.Abs(d));
                    modselection[i] = w;	//mc.cols[i][c];
                }
            }
        }
        //if ( weight == 1.0f )
        //	mc.selection = null;	// Normal system

        // We only need the copy if we are first mod
        if ( (mc.dirtyChannels & MegaModChannel.Verts) == 0 )
        {
            mc.InitVertSource();
            //verts.CopyTo(sverts, 0);
            //mc.UpdateMesh = 1;
        }

        //Debug.Log("sel " + modselection.Length);
        mc.selection = modselection;
    }
Ejemplo n.º 14
0
    public override void DoWork(MegaModifiers mc, int index, int start, int end, int cores)
    {
        //if ( useWeights )

        if ( selection != null )
        {
            DoWorkWeighted(mc, index, start, end, cores);
            return;
        }

        for ( int i = start; i < end; i++ )
            sverts[i] = MapMT(i, verts[i]);
    }
Ejemplo n.º 15
0
	void Replace(MegaModifiers mc, int startvert, int endvert)
	{
		for ( int i = startvert; i < endvert; i++ )
		{
			MegaBezVector3KeyControl bc = (MegaBezVector3KeyControl)Verts[i].con;

			Vector3 off = bc.GetVector3(t);

			// ******* We must have duplicate verts in the indices array, so check that, if so same will apply to pc mod
			for ( int v = 0; v < Verts[i].indices.Length; v++ )
				sverts[Verts[i].indices[v]] = off;
		}
	}
Ejemplo n.º 16
0
	public override void Modify(MegaModifiers mc)
	{
		//if ( uvs.Length == 0 )
			//uvs = mc.uvs;

		//if ( normals.Length == 0 )
			//normals = mc.mesh.normals;
		//Vector3[]	verts = mc.GetSourceVerts();
		//Vector3[]	sverts = mc.GetDestVerts();

		for ( int i = 0; i < verts.Length; i++ )
			sverts[i] = Map(i, verts[i]);
	}
Ejemplo n.º 17
0
    public void LoadMDD(string filename)
    {
        MegaPointCache am = (MegaPointCache)target;
        mods = am.gameObject.GetComponent<MegaModifiers>();

        if ( mods == null)
        {
            Debug.LogWarning("You need to add a Mega Modify Object component first!");
            return;
        }
        lastpath = filename;

        // Clear what we have
        Verts.Clear();

        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read);

        BinaryReader br = new BinaryReader(fs);

        int numSamples = MegaParse.ReadMotInt(br);
        int numPoints = MegaParse.ReadMotInt(br);

        float t = 0.0f;

        for ( int i = 0; i < numSamples; i++ )
            t = MegaParse.ReadMotFloat(br);

        am.maxtime = t;

        am.Verts = new MegaPCVert[numPoints];

        for ( int i = 0; i < am.Verts.Length; i++ )
        {
            am.Verts[i] = new MegaPCVert();
            am.Verts[i].points = new Vector3[numSamples];
        }

        for ( int i = 0; i < numSamples; i++ )
        {
            for ( int v = 0; v < numPoints; v++ )
            {
                am.Verts[v].points[i].x = MegaParse.ReadMotFloat(br);
                am.Verts[v].points[i].y = MegaParse.ReadMotFloat(br);
                am.Verts[v].points[i].z = MegaParse.ReadMotFloat(br);
            }
        }

        BuildData(mods, am, filename);
        br.Close();
    }
Ejemplo n.º 18
0
	void LinearAbs(MegaModifiers mc, int start, int end)
	{
		for ( int i = start; i < end; i++ )
		{
			Vector3 p = Verts[i].points[sindex];
			Vector3 p1 = Verts[i].points[sindex + 1];
			p.x = p.x + ((p1.x - p.x) * dalpha);
			p.y = p.y + ((p1.y - p.y) * dalpha);
			p.z = p.z + ((p1.z - p.z) * dalpha);

			for ( int v = 0; v < Verts[i].indices.Length; v++ )
				sverts[Verts[i].indices[v]] = p;
		}
	}
Ejemplo n.º 19
0
    public override void ModStart(MegaModifiers mc)
    {
        xsize = bbox.max.x - bbox.min.x;
        ysize = bbox.max.y - bbox.min.y;
        zsize = bbox.max.z - bbox.min.z;
        size = (xsize > ysize) ? xsize : ysize;
        size = (zsize > size) ? zsize : size;
        size /= 2.0f;
        cx = bbox.center.x;
        cy = bbox.center.y;
        cz = bbox.center.z;

        // Get the percentage to spherify at this time
        per = percent / 100.0f;
    }
	void LoadVertexAnim()
	{
		MegaVertexAnim am = (MegaVertexAnim)target;
		mods = am.gameObject.GetComponent<MegaModifiers>();

		string filename = EditorUtility.OpenFilePanel("Vertex Animation File", lastpath, "mpc");

		if ( filename == null || filename.Length < 1 )
			return;

		lastpath = filename;

		// Clear what we have
		Verts.Clear();

		ParseFile(filename, AnimatedMeshCallback);
		am.Verts = Verts.ToArray();

		BitArray animated = new BitArray(mods.verts.Length);
		int count = 0;
		for ( int i = 0; i < Verts.Count; i++ )
		{
			for ( int v = 0; v < Verts[i].indices.Length; v++ )
			{
				if ( !animated[Verts[i].indices[v]] )
				{
					animated[Verts[i].indices[v]] = true;
					count++;
				}
			}
		}

		am.NoAnim = new int[mods.verts.Length - count];
		int index = 0;
		for ( int i = 0; i < animated.Count; i++ )
		{
			if ( !animated[i] )
				am.NoAnim[index++] = i;
		}

		am.maxtime = 0.0f;
		for ( int i = 0; i < Verts.Count; i++ )
		{
			float t = Verts[i].con.Times[Verts[i].con.Times.Length - 1];
			if ( t > am.maxtime )
					am.maxtime = t;
		}
	}
Ejemplo n.º 21
0
    public void ModifyCompressedMT(MegaModifiers mc, int tindex, int cores)
    {
        //Vector3[]	verts = mc.GetSourceVerts();
        //Vector3[]	sverts = mc.GetDestVerts();

        int step = NoAnim.Length / cores;
        int startvert = (tindex * step);
        int endvert = startvert + step;

        if ( tindex == cores - 1 )
            endvert = NoAnim.Length;

        if ( NoAnim != null )
        {
            for ( int i = startvert; i < endvert; i++ )
            {
                int index = NoAnim[i];
                sverts[index] = verts[index];
            }
        }

        //Debug.Log("tindex " + tindex + " cores " + cores + " Verts " + Verts.Length);
        step = Verts.Length / cores;
        startvert = (tindex * step);
        endvert = startvert + step;

        if ( tindex == cores - 1 )
            endvert = Verts.Length;

        switch ( blendMode )
        {
            case MegaBlendAnimMode.Additive:	Additive(mc, startvert, endvert); break;
            case MegaBlendAnimMode.Replace:		Replace(mc, startvert, endvert); break;
        }
        #if false
        for ( int i = startvert; i < endvert; i++ )
        {
            MegaBezVector3KeyControl bc = (MegaBezVector3KeyControl)Verts[i].con;

            Vector3 off = bc.GetVector3(t);

            for ( int v = 0; v < Verts[i].indices.Length; v++ )
                sverts[Verts[i].indices[v]] = off;
        }
        #endif
    }
Ejemplo n.º 22
0
	// Example to show could override the Modify method, Map is still needed for gizmo
#if plop
	public override void Modify(MegaModifiers mc)
	{
		Vector3[]	verts = mc.GetSourceVerts();
		Vector3[]	sverts = mc.GetDestVerts();

		float z;
		float l = bbox.max[(int)axis] - bbox.min[(int)axis];

		if ( l != 0.0f )
		{
			for ( int i = 0; i < verts.Length; i++ )
			{
				Vector3 p = tm.MultiplyPoint3x4(verts[i]);

				if ( doRegion )
				{
					if ( p.y < from )
						z = from / l;
					else
					{
						if ( p.y > to )
							z = to / l;
						else
							z = p.y / l;
					}
				}
				else
					z = p.y / l;

				if ( sym && z < 0.0f )
					z = -z;

				float f = 1.0f + z * k1 + k2 * z * (1.0f - z);

				if ( doX )
					p.x *= f;

				if ( doY )
					p.z *= f;

				sverts[i] = invtm.MultiplyPoint3x4(p);
			}
		}
	}
	// Remove morph and pass tolerance then can morph to Utils
	// TODO: report error if target vert counts dont match base mapping
	bool DoMapping(MegaModifiers mod, MegaMorphOMatic morph, MegaTargetMesh tm, float scale, bool flipyz, bool negx)
	{
		for ( int i = 0; i < mod.verts.Length; i++ )
		{
			float a = (float)i / (float)mod.verts.Length;

			EditorUtility.DisplayProgressBar("Mapping", "Mapping vertex " + i, a);
			int map = MegaUtils.FindVert(mod.verts[i], tm.verts, morph.tolerance, scale, flipyz, negx, i);

			if ( map == -1 )
			{
				// Failed
				EditorUtility.ClearProgressBar();
				return false;
			}
		}

		EditorUtility.ClearProgressBar();
		return true;
	}
Ejemplo n.º 24
0
    public override void DoWorkWeighted(MegaModifiers mc, int index, int start, int end, int cores)
    {
        for ( int i = start; i < end; i++ )
        {
            Vector3 p = verts[i];

            float w = selection[i];	//[(int)weightChannel];

            if ( w > 0.001f )
            {
                Vector3 mp = MapMT(i, verts[i]);

                sverts[i].x = p.x + (mp.x - p.x) * w;
                sverts[i].y = p.y + (mp.y - p.y) * w;
                sverts[i].z = p.z + (mp.z - p.z) * w;
            }
            else
                sverts[i] = p;	//verts[i];
        }
    }
Ejemplo n.º 25
0
	public override void GetSelection(MegaModifiers mc)
	{
		if ( modselection == null || modselection.Length != mc.verts.Length )
		{
			modselection = new float[mc.verts.Length];
		}

		//int c = (int)channel;

		// we dont need to update if nothing changes
		for ( int i = 0; i < mc.verts.Length; i++ )
		{
			modselection[i] = weight;	//mc.cols[i][c];
		}

		if ( weight == 1.0f )
			mc.selection = null;	// Normal system

		mc.selection = modselection;
	}
Ejemplo n.º 26
0
    public override void Modify(MegaModifiers mc)
    {
        //Vector3[]	verts = mc.GetSourceVerts();
        //Vector3[]	sverts = mc.GetDestVerts();

        switch ( blendMode )
        {
            case MegaBlendAnimMode.Additive:	Additive(mc, 0, Verts.Length);	break;
            case MegaBlendAnimMode.Replace:		Replace(mc, 0, Verts.Length); break;
        }

        if ( NoAnim != null )
        {
            for ( int i = 0; i < NoAnim.Length; i++ )
            {
                int index = NoAnim[i];
                sverts[index] = verts[index];
            }
        }
    }
Ejemplo n.º 27
0
    // TODO: Option to lerp or even bez, depends on how many samples
    public override void Modify(MegaModifiers mc)
    {
        if ( Verts != null )
        {
            switch ( interpMethod )
            {
                case MegaInterpMethod.Linear:
                    switch ( blendMode )
                    {
                        case MegaBlendAnimMode.Additive:	LinearRel(mc, 0, Verts.Length);	break;
                        case MegaBlendAnimMode.Replace:		LinearAbs(mc, 0, Verts.Length);	break;
                    }
                    break;

                case MegaInterpMethod.Bez:
                    switch ( blendMode )
                    {
                        case MegaBlendAnimMode.Additive:	LinearRel(mc, 0, Verts.Length); break;
                        case MegaBlendAnimMode.Replace:		LinearAbs(mc, 0, Verts.Length); break;
                    }
                    break;

                case MegaInterpMethod.None:
                    switch ( blendMode )
                    {
                        case MegaBlendAnimMode.Additive:	NoInterpRel(mc, 0, Verts.Length); break;
                        case MegaBlendAnimMode.Replace:		NoInterpAbs(mc, 0, Verts.Length); break;
                    }
                    break;
            }
        }
        else
        {
            //Vector3[]	verts = mc.GetSourceVerts();
            //Vector3[]	sverts = mc.GetDestVerts();

            for ( int i = 0; i < verts.Length; i++ )
                sverts[i] = verts[i];
        }
    }
Ejemplo n.º 28
0
    //public override void Modify(ref Vector3[] sverts, ref Vector3[] verts)
    public override void Modify(MegaModifiers mc)
    {
        Vector2[]	uvs = mc.GetSourceUvs();
        Vector2[]	newuvs = mc.GetDestUvs();

        if ( mat == null || twidth == 0.0f )
            Init();

        if ( uvs.Length > 0 )
        {
            //Debug.Log("twidth " + twidth);
            xtiles = twidth / TileWidth;
            ytiles = theight / TileHeight;

            tuvw = (float)TileWidth / (float)twidth;
            tuvh = (float)TileHeight / (float)theight;

            maxframe = xtiles * ytiles;

            Frame = Frame % maxframe;

            int x = Frame % xtiles;
            int y = Frame / xtiles;

            float su = (x * tuvw);
            float sv = (y * tuvh);

            for ( int i = 0; i < uvs.Length; i++ )
            {
                Vector2 uv = Vector2.Scale(uvs[i] + off, scale);

                if ( flipy )	uv.y = 1.0f - uv.y;
                if ( flipx )	uv.x = 1.0f - uv.x;

                uv.x = su + (tuvw * uv.x);
                uv.y = 1.0f - (sv + (tuvh * uv.y));
                newuvs[i] = uv;
            }
        }
    }
Ejemplo n.º 29
0
	void ReplaceWeighted(MegaModifiers mc, int startvert, int endvert)
	{
		//Vector3[] vts = mc.GetSourceVerts();
		//int wc = (int)weightChannel;

		for ( int i = startvert; i < endvert; i++ )
		{
			MegaBezVector3KeyControl bc = (MegaBezVector3KeyControl)Verts[i].con;

			Vector3 off = bc.GetVector3(t);

			//float w = mc.cols[Verts[i].indices[0]][wc] * weight;
			float w = mc.selection[Verts[i].indices[0]] * weight;	//[wc];

			Vector3 p1 = verts[Verts[i].indices[0]];

			off = p1 + ((off - p1) * w);

			for ( int v = 0; v < Verts[i].indices.Length; v++ )
				sverts[Verts[i].indices[v]] = off;
		}
	}
Ejemplo n.º 30
0
	void LinearAbsWeighted(MegaModifiers mc, int start, int end)
	{
		//Vector3[] vts = mc.GetSourceVerts();

		//int wc = (int)weightChannel;

		for ( int i = start; i < end; i++ )
		{
			Vector3 p = Verts[i].points[sindex];
			Vector3 p1 = Verts[i].points[sindex + 1];
			p.x = p.x + ((p1.x - p.x) * dalpha);
			p.y = p.y + ((p1.y - p.y) * dalpha);
			p.z = p.z + ((p1.z - p.z) * dalpha);

			//float w = mc.cols[Verts[i].indices[0]][wc];
			float w = mc.selection[Verts[i].indices[0]];	//[wc];
			p1 = verts[Verts[i].indices[0]];

			p = p1 + ((p - p1) * w);
			for ( int v = 0; v < Verts[i].indices.Length; v++ )
				sverts[Verts[i].indices[v]] = p;
		}
	}
 public override void PrepareMT(MegaModifiers mc, int cores)
 {
 }
    public override void Modify(MegaModifiers mc)
    {
        // Calc collision force
        float colForce = ColForce;        //Mathf.Min(1, collision.impactForceSum.sqrMagnitude / 1000);

        sizeFactor = mc.bbox.size.magnitude;
        // distFactor is the amount of deforming in local coordinates
        float distFactor = colForce * (sizeFactor * (impactFactor / Mathf.Max(impactFactor, Hardness)));

        // Deform process
        if (colpoints != null)
        {
            for (int c = 0; c < colpoints.Length; c++)
            {
                ContactPoint contact = colpoints[c];

                for (int i = 0; i < verts.Length; i++)
                {
                    // Apply deformation only on vertex inside "blast area"
                    Vector3 vp = verts[i] + offsets[i];

                    Vector3 p = transform.InverseTransformPoint(contact.point);
                    float   d = (vp - p).sqrMagnitude;
                    if (d <= distFactor)
                    {
                        // Deformation is the collision normal with local deforming ratio
                        // Vertices near the impact point must also be more deformed
                        Vector3 n = transform.InverseTransformDirection(contact.normal * (1.0f - (d / distFactor)) * distFactor);

                        // Apply hardness map if any
                        if (map != null)
                        {
                            n *= 1.0f - map[i];
                        }

                        // Deform vertex
                        //vertices[i] += n;
                        offsets[i] += n;

                        // Apply max vertex movement if configured
                        // Here the deformed vertex position is just scaled down to keep the best deformation while respecting limits
                        if (MaxVertexMov > 0.0f)
                        {
                            float max = MaxVertexMov;
                            n = offsets[i];                             //vertices[i] - baseVertices[i];
                            d = n.magnitude;
                            if (d > max)
                            {
                                offsets[i] = (n * (max / d));
                            }

                            // Apply vertex color deformation
                            // Deform color is applied in proportional amount with vertex distance and max deform
                            if (baseColors.Length > 0)
                            {
                                d          = (d / MaxVertexMov);
                                mc.cols[i] = Color.Lerp(baseColors[i], DeformedVertexColor, d);
                            }
                        }
                        else
                        {
                            if (mc.cols.Length > 0)
                            {
                                // Apply vertex color deformation
                                // Deform color is applied in proportional amount with vertex distance and mesh distance factor
                                mc.cols[i] = Color.Lerp(baseColors[i], DeformedVertexColor, offsets[i].magnitude / (distFactor * 10.0f));
                            }
                        }
                    }
                }
            }
        }

        colpoints = null;

        if (!usedecay)
        {
            for (int i = 0; i < verts.Length; i++)
            {
                sverts[i].x = verts[i].x + offsets[i].x;
                sverts[i].y = verts[i].y + offsets[i].y;
                sverts[i].z = verts[i].z + offsets[i].z;
            }
        }
        else
        {
            for (int i = 0; i < verts.Length; i++)
            {
                offsets[i].x *= decay;
                offsets[i].y *= decay;
                offsets[i].z *= decay;

                sverts[i].x = verts[i].x + offsets[i].x;
                sverts[i].y = verts[i].y + offsets[i].y;
                sverts[i].z = verts[i].z + offsets[i].z;
            }
        }
    }
 // We could find the megamod comp
 public void Repair(float repair, MegaModifiers mc)
 {
     Repair(repair, Vector3.zero, 0.0f, mc);
 }
Ejemplo n.º 34
0
 public override void ModStart(MegaModifiers mc)
 {
 }
Ejemplo n.º 35
0
 public override void ModStart(MegaModifiers mc)
 {
     CalcNormals(mc.mesh);
 }
Ejemplo n.º 36
0
    public void LoadMCC(string filename)
    {
        MegaPointCache am = (MegaPointCache)target;

        oldverts = am.Verts;
        mods     = am.gameObject.GetComponent <MegaModifiers>();

        if (mods == null)
        {
            Debug.LogWarning("You need to add a Mega Modify Object component first!");
            return;
        }

        lastpath = filename;

        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read);

        BinaryReader br = new BinaryReader(fs);

        string id = Read(br, 4);

        if (id != "FOR4")
        {
            Debug.Log("wrong file");
            return;
        }

        int offset = MegaParse.ReadMotInt(br);

        br.ReadBytes(offset);

        List <MCCFrame> frames = new List <MCCFrame>();

        int buflen = 0;

        //int clen = 0;

        while (true)
        {
            string btag = Read(br, 4);
            if (btag == "")
            {
                break;
            }

            if (btag != "FOR4")
            {
                Debug.Log("File format error");
                return;
            }

            int blocksize = MegaParse.ReadMotInt(br);

            int bytesread = 0;

            btag = Read(br, 4);
            if (btag != "MYCH")
            {
                Debug.Log("File format error");
                return;
            }
            bytesread += 4;

            btag = Read(br, 4);
            if (btag != "TIME")
            {
                Debug.Log("File format error");
                return;
            }
            bytesread += 4;

            br.ReadBytes(4);
            bytesread += 4;

            int time = MegaParse.ReadMotInt(br);
            bytesread += 4;

            am.maxtime = (float)time / 6000.0f;

            while (bytesread < blocksize)
            {
                btag = Read(br, 4);
                if (btag != "CHNM")
                {
                    Debug.Log("chm error");
                    return;
                }
                bytesread += 4;

                int chnmsize = MegaParse.ReadMotInt(br);
                bytesread += 4;

                int mask           = 3;
                int chnmsizetoread = (chnmsize + mask) & (~mask);
                //byte[] channelname = br.ReadBytes(chnmsize);
                br.ReadBytes(chnmsize);

                int paddingsize = chnmsizetoread - chnmsize;

                if (paddingsize > 0)
                {
                    br.ReadBytes(paddingsize);
                }

                bytesread += chnmsizetoread;

                btag = Read(br, 4);

                if (btag != "SIZE")
                {
                    Debug.Log("Size error");
                    return;
                }
                bytesread += 4;

                br.ReadBytes(4);
                bytesread += 4;

                int arraylength = MegaParse.ReadMotInt(br);
                bytesread += 4;

                MCCFrame frame = new MCCFrame();
                frame.points = new Vector3[arraylength];

                string dataformattag = Read(br, 4);
                int    bufferlength  = MegaParse.ReadMotInt(br);
                //Debug.Log("buflen " + bufferlength);

                if (buflen == 0)
                {
                    buflen = bufferlength;
                }

                bytesread += 8;

                if (dataformattag == "FVCA")
                {
                    if (bufferlength != arraylength * 3 * 4)
                    {
                        Debug.Log("buffer len error");
                        return;
                    }

                    for (int i = 0; i < arraylength; i++)
                    {
                        frame.points[i].x = MegaParse.ReadMotFloat(br);
                        frame.points[i].y = MegaParse.ReadMotFloat(br);
                        frame.points[i].z = MegaParse.ReadMotFloat(br);
                    }

                    bytesread += arraylength * 3 * 4;
                }
                else
                {
                    if (dataformattag == "DVCA")
                    {
                        if (bufferlength != arraylength * 3 * 8)
                        {
                            Debug.Log("buffer len error");
                            return;
                        }

                        for (int i = 0; i < arraylength; i++)
                        {
                            frame.points[i].x = (float)MegaParse.ReadMotDouble(br);
                            frame.points[i].y = (float)MegaParse.ReadMotDouble(br);
                            frame.points[i].z = (float)MegaParse.ReadMotDouble(br);
                        }

                        bytesread += arraylength * 3 * 8;
                    }
                    else
                    {
                        Debug.Log("Format Error");
                        return;
                    }
                }

                if (buflen == bufferlength)
                {
                    frames.Add(frame);
                }
            }
        }

        //Debug.Log("frames " + frames.Count);

        // Build table
        am.Verts = new MegaPCVert[frames[0].points.Length];

        //Debug.Log("am.Verts " + am.Verts.Length);

        for (int i = 0; i < am.Verts.Length; i++)
        {
            am.Verts[i]        = new MegaPCVert();
            am.Verts[i].points = new Vector3[frames.Count];

            for (int p = 0; p < am.Verts[i].points.Length; p++)
            {
                //Debug.Log("i " + i + " p " + p);
                am.Verts[i].points[p] = frames[p].points[i];
            }
        }

        BuildData(mods, am, filename);
        br.Close();
    }
Ejemplo n.º 37
0
    void BuildData(MegaModifiers mods, MegaPointCache am, string filename)
    {
        bool domapping = true;

        if (am.havemapping)
        {
            domapping = EditorUtility.DisplayDialog("Point Cache Mapping", "Replace Existing Mapping?", "Yes", "No");
        }

        if (!domapping)
        {
            if (DoAdjustFirst)
            {
                AdjustVertsSimple(mods, am);
            }
        }
        else
        {
            if (DoAdjustFirst)
            {
                AdjustVerts(mods, am);
            }
        }
        // Build vector3[] of base verts
        Vector3[] baseverts = new Vector3[am.Verts.Length];

        int findex = 0;

        if (uselastframe)
        {
            findex = am.Verts[0].points.Length - 1;
        }
        for (int i = 0; i < am.Verts.Length; i++)
        {
            baseverts[i] = am.Verts[i].points[findex];
        }

#if false
        for (int i = 0; i < 32; i++)
        {
            Debug.Log("vert " + mods.verts[i].ToString("0.000"));
        }

        for (int i = 0; i < 32; i++)
        {
            Debug.Log("pc " + baseverts[i].ToString("0.000"));
        }
#endif

        if (domapping)
        {
            if (!TryMapping1(baseverts, mods.verts))
            {
                EditorUtility.DisplayDialog("Mapping Failed!", "Mapping of " + System.IO.Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
                EditorUtility.ClearProgressBar();
                am.havemapping = false;
                return;
            }

            am.negx   = negx;
            am.negz   = negz;
            am.flipyz = flipyz;
            am.scl    = scl;
        }
        else
        {
            negx   = am.negx;
            negz   = am.negz;
            flipyz = am.flipyz;
            scl    = am.scl;
        }

        am.havemapping = true;

        // Remap vertices
        for (int i = 0; i < am.Verts.Length; i++)
        {
            for (int v = 0; v < am.Verts[i].points.Length; v++)
            {
                if (negx)
                {
                    am.Verts[i].points[v].x = -am.Verts[i].points[v].x;
                }

                if (flipyz)
                {
                    float z = am.Verts[i].points[v].z;
                    am.Verts[i].points[v].z = am.Verts[i].points[v].y;
                    am.Verts[i].points[v].y = z;
                }

                if (negz)
                {
                    am.Verts[i].points[v].z = -am.Verts[i].points[v].z;
                }

                am.Verts[i].points[v] = am.Verts[i].points[v] * scl;
            }
        }

        if (domapping)
        {
            for (int i = 0; i < am.Verts.Length; i++)
            {
                am.Verts[i].indices = FindVerts(am.Verts[i].points[findex]);

                if (am.Verts[i].indices.Length == 0)
                {
                    EditorUtility.DisplayDialog("Final Mapping Failed!", "Mapping of " + System.IO.Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
                    EditorUtility.ClearProgressBar();
                    return;
                }
            }
        }
        else
        {
            for (int i = 0; i < am.Verts.Length; i++)
            {
                am.Verts[i].indices = oldverts[i].indices;
            }
        }

        oldverts = null;
    }
Ejemplo n.º 38
0
    bool TryMapping(List <MegaTargetMesh> targets, MegaMorph morph)
    {
        MegaModifiers mod = morph.GetComponent <MegaModifiers>();

        if (mod == null)
        {
            //Debug.Log("No modifyobject found");
            EditorUtility.DisplayDialog("Missing ModifyObject!", "No ModifyObject script found on the object", "OK");
            return(false);
        }

        int[] mapping = new int[mod.verts.Length];

        //for ( int i = 0; i < 18; i++ )
        //{
        //	Debug.Log("v[" + i + "] " + mod.verts[i].ToString("0.00000"));
        //}

        //for ( int i = 0; i < 18; i++ )
        //{
        //	Debug.Log("t[" + i + "] " + targets[0].verts[i].ToString("0.00000"));
        //}

        for (int t = 0; t < targets.Count; t++)
        {
            MegaTargetMesh tm = targets[t];

            // Get extents for mod verts and for imported meshes, if not the same then scale
            Vector3 min1, max1;
            Vector3 min2, max2;

            Vector3 ex1 = Extents(mod.verts, out min1, out max1);
            Vector3 ex2 = Extents(tm.verts, out min2, out max2);

            //Debug.Log("min1 " + min1.ToString("0.000"));
            //Debug.Log("max1 " + max1.ToString("0.000"));
            //Debug.Log("min2 " + min2.ToString("0.000"));
            //Debug.Log("max2 " + max2.ToString("0.000"));
            // need min max on all axis so we can produce an offset to add
            float d1 = ex1.x;
            float d2 = ex2.x;

            float scl    = d1 / d2;             //d2 / d1;
            bool  flipyz = false;
            bool  negx   = false;

            //Vector3 offset = (min2 * scl) - min1;
            //Debug.Log("offset " + offset.ToString("0.0000"));
            //Debug.Log("scl " + scl);

            // So try to match first vert using autoscale and no flip
            bool mapped = DoMapping(mod, morph, tm, mapping, scl, flipyz, negx);

            if (!mapped)
            {
                flipyz = true;
                mapped = DoMapping(mod, morph, tm, mapping, scl, flipyz, negx);
                if (!mapped)                    //DoMapping(mod, morph, tm, mapping, scl, flipyz, negx) )
                {
                    flipyz = false;
                    negx   = true;
                    mapped = DoMapping(mod, morph, tm, mapping, scl, flipyz, negx);
                    if (!mapped)
                    {
                        flipyz = true;
                        mapped = DoMapping(mod, morph, tm, mapping, scl, flipyz, negx);
                    }
                }
            }

            if (mapped)
            {
                morph.importScale = scl;
                morph.flipyz      = flipyz;
                morph.negx        = negx;

                morph.mapping = mapping;
                // if mapping was ok set opoints
                morph.oPoints = tm.verts.ToArray();

                for (int i = 0; i < morph.oPoints.Length; i++)
                {
                    Vector3 p = morph.oPoints[i];

                    if (negx)
                    {
                        p.x = -p.x;
                    }

                    if (flipyz)
                    {
                        float z = p.z;
                        p.z = p.y;
                        p.y = z;
                    }

                    morph.oPoints[i] = p * morph.importScale;
                }

                return(true);
            }
        }

        return(false);
    }