public bool BakeToVertexColor(bool pushUndo) { if (pushUndo) { var record = new History.Record { mesh = m_meshTarget, colors = m_meshTarget.colors }; PushUndo(null, new History.Record[1] { record }); } var colors = new Color[m_normals.Length]; for (int i = 0; i < m_normals.Length; ++i) { colors[i].r = m_normals[i].x * 0.5f + 0.5f; colors[i].g = m_normals[i].y * 0.5f + 0.5f; colors[i].b = m_normals[i].z * 0.5f + 0.5f; colors[i].a = 1.0f; } m_meshTarget.colors = colors; if (pushUndo) { var record = new History.Record { mesh = m_meshTarget, colors = colors }; PushUndo(null, new History.Record[1] { record }); } return(true); }
public static void insertInPosition(int index, History.Record data, History historyObject) { for (int i = historyObject.maxSize - 2; i > index - 1; i--) { historyObject.list[i + 1] = historyObject.list[i]; } historyObject.list[index] = data; }
public static void addByDate(History.Record newRecord, History historyObject) { insertInPosition(0, newRecord, historyObject); if (historyObject.size != historyObject.maxSize) { historyObject.size++; } }
//History methods //Regular history record update public static History.Record regLog(string score) { DateTime time = DateTime.Now; string temp2 = time.ToString(); //get current date time in nice format History.Record temp = new History.Record(); temp.username = GameData.Prefs.username; temp.date = temp2; temp.score = int.Parse(score); return(temp); }
//Create a history record and add it to the portal log public static History.Record portalLog(string startupTime) { DateTime time = DateTime.Now; string temp2 = time.ToString(); //get current date time in nice format History.Record temp = new History.Record(); temp.username = GameData.Prefs.username; temp.date = temp2; temp.time = startupTime; return(temp); }
public static void addByScore(History.Record newRecord, History historyObject) { for (int i = 0; i < historyObject.maxSize; i++) { if (historyObject.list[i].score < newRecord.score || historyObject.list[i].username == null) { insertInPosition(i, newRecord, historyObject); if (historyObject.size != historyObject.maxSize) { historyObject.size++; } break; } } }
public bool ApplyWelding2(GameObject[] targets, int weldMode, float weldAngle, bool pushUndo) { var data = new List <WeldData>(); // build weld data foreach (var t in targets) { if (!t || t == this.gameObject) { continue; } var smr = t.GetComponent <SkinnedMeshRenderer>(); if (smr) { var mesh = smr.sharedMesh; if (!IsValidMesh(mesh)) { continue; } var d = new WeldData(); d.skinned = true; d.mesh = mesh; d.transform = t.GetComponent <Transform>().localToWorldMatrix; d.vertices = new PinnedList <Vector3>(mesh.vertices); d.normals = new PinnedList <Vector3>(mesh.normals); d.weights = new PinnedList <BoneWeight>(mesh.boneWeights); d.bindposes = new PinnedList <Matrix4x4>(mesh.bindposes); d.bones = new PinnedList <Matrix4x4>(d.bindposes.Length); var bones = smr.bones; int n = System.Math.Min(d.bindposes.Length, smr.bones.Length); for (int bi = 0; bi < n; ++bi) { d.bones[bi] = smr.bones[bi].localToWorldMatrix; } d.skinData.num_vertices = d.vertices.Length; d.skinData.num_bones = d.bindposes.Length; d.skinData.weights = d.weights; d.skinData.bindposes = d.bindposes; d.skinData.bones = d.bones; d.skinData.root = d.transform; npApplySkinning(ref d.skinData, d.vertices, d.normals, null, d.vertices, d.normals, null); data.Add(d); } var mr = t.GetComponent <MeshRenderer>(); if (mr) { var mesh = t.GetComponent <MeshFilter>().sharedMesh; if (!IsValidMesh(mesh)) { continue; } var d = new WeldData(); d.mesh = mesh; d.transform = t.GetComponent <Transform>().localToWorldMatrix; d.vertices = new PinnedList <Vector3>(mesh.vertices); d.normals = new PinnedList <Vector3>(mesh.normals); data.Add(d); } } if (data.Count == 0) { Debug.LogWarning("Nothing to weld."); return(false); } // create data to pass to C++ bool mask = m_numSelected > 0; npModelData[] tdata = new npModelData[data.Count]; for (int i = 0; i < data.Count; ++i) { tdata[i].num_vertices = data[i].vertices.Length; tdata[i].vertices = data[i].vertices; tdata[i].normals = data[i].normals; tdata[i].transform = data[i].transform; } Vector3[] normalsPreWeld = null; if (pushUndo) { normalsPreWeld = m_normals.Clone(); } // do weld bool ret = false; if (npWeld2(ref m_npModelData, tdata.Length, tdata, weldMode, weldAngle, mask) > 0) { // data to undo History.Record[] records = null; if (pushUndo && (weldMode == 0 || weldMode == 2)) { records = new History.Record[data.Count]; for (int i = 0; i < data.Count; ++i) { records[i] = new History.Record(); records[i].mesh = data[i].mesh; records[i].normals = data[i].mesh.normals; } PushUndo(normalsPreWeld, records); } // update normals if (weldMode == 1 || weldMode == 2) { UpdateNormals(); } if (weldMode == 0 || weldMode == 2) { foreach (var d in data) { if (d.skinned) { npApplyReverseSkinning(ref d.skinData, null, d.normals, null, null, d.normals, null); } d.mesh.normals = d.normals; d.mesh.UploadMeshData(false); } if (pushUndo) { for (int i = 0; i < data.Count; ++i) { records[i] = new History.Record(); records[i].mesh = data[i].mesh; records[i].normals = data[i].normals; } } } if (pushUndo) { PushUndo(m_normals, records); } ret = true; } return(ret); }