Hi,
Apologies if this specific topic has been covered…I searched around but didn’t quite find an exact match.
I’m currently working on a genomics analysis project, where two sequences are compared using a custom algorithm. My intention was to use Unity to visualize each sequence, so: load the sequence (FASTA format in case anyone is interested) and translate each specific amino acid into a chunk of geometry, then display. I’ve worked out a basic loading mechanism, but the geometry just doesn’t want to display…I swapped in some basic code to create the verts/polys for a cube, tried opposite index ordering when it didn’t display, still nothing…hence my question (i.e. is the free version limited in this regard?).
I could create an importer for the editor and save off the ‘genomic geometry’, but I lose the main intent of the project which is to dynamically compare and pinpoint sections of similarity.
The scale of the verts I’m defining are similar to a cube already in the scene (reference object, just to confirm scene rendering is up/running). I’m assuming a default material is applied here, but maybe I shouldn’t assume this…?
Thanks in advance for any pointers. Snippet of basic code currently being used follows.
Cheers,
-Eric
public class ReadSequence : MonoBehaviour
{
string m_sequence1;
string m_sequence2;
int m_curReadIndex;
Mesh m_mesh1;
Mesh m_mesh2;
GameObject m_meshObject1;
GameObject m_meshObject2;
static UnityEngine.Object m_finalObj = null;
const float kCuboidBaseLength = 2.0f;
void Start ()
{
Logger.logMessage(“Loading sequence1”);
try
{
m_sequence1 = System.IO.File.ReadAllText(“.\sequence1.txt”);
if (m_sequence1 == “”)
return;
}
catch (Exception ex)
{
return;
}
//Skip the FASTA header and ensure only the base amino acids are present
skipFASTAHeader();
//Reading complete
Logger.logMessage(“Sequence reading #1 complete”);
//Logger.logMessage(m_sequence1);//debug/verbose purposes only
//Create the objects
Logger.logMessage(“Creating sequence objects”);
CreateObject(ref m_sequence1, ref m_mesh1, ref m_meshObject1);
Logger.logMessage(“Sequence objects constructed”);
}
[snip]
private void CreateObject (ref string inStr, ref Mesh inMesh, ref GameObject inObj)
{
Vector3 posVec = new Vector3(0.0f, 0.0f, 0.0f);
Vector3 rotVec = new Vector3(0.0f, 0.0f, 0.0f);
Vector3 objPos = new Vector3(0.0f, 0.0f, 0.0f);
Quaternion objRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
int index;
//Init the mesh
inMesh = new Mesh();
Vector3[ ] vertices = new Vector3[8];
int[ ] triangles = new int[24];
Logger.logMessage(“–Allocated vector buffer”);
//Create the points
vertices[0].Set(-kCuboidBaseLength, kCuboidBaseLength, -kCuboidBaseLength);
vertices[1].Set(-kCuboidBaseLength, -kCuboidBaseLength, -kCuboidBaseLength);
vertices[2].Set(kCuboidBaseLength, -kCuboidBaseLength, -kCuboidBaseLength);
vertices[3].Set(kCuboidBaseLength, kCuboidBaseLength, -kCuboidBaseLength);
vertices[4].Set(-kCuboidBaseLength, kCuboidBaseLength, kCuboidBaseLength);
vertices[5].Set(kCuboidBaseLength, kCuboidBaseLength, kCuboidBaseLength);
vertices[6].Set(kCuboidBaseLength, -kCuboidBaseLength, kCuboidBaseLength);
vertices[7].Set(-kCuboidBaseLength, -kCuboidBaseLength, kCuboidBaseLength);
Logger.logMessage(“–Set points”);
//Create polys
index = 0;
triangles[index++] = 2;
triangles[index++] = 1;
triangles[index++] = 0;
triangles[index++] = 2;
triangles[index++] = 3;
triangles[index++] = 0;
triangles[index++] = 4;
triangles[index++] = 5;
triangles[index++] = 6;
triangles[index++] = 6;
triangles[index++] = 7;
triangles[index++] = 4;
triangles[index++] = 3;
triangles[index++] = 2;
triangles[index++] = 6;
triangles[index++] = 6;
triangles[index++] = 5;
triangles[index++] = 3;
triangles[index++] = 0;
triangles[index++] = 4;
triangles[index++] = 7;
triangles[index++] = 7;
triangles[index++] = 1;
triangles[index++] = 0;
Logger.logMessage(“–Created polys”);
//Finish the mesh
inMesh.triangles = triangles;
inMesh.vertices = vertices;
inMesh.RecalculateNormals();
inMesh.RecalculateBounds();
//inMesh.Optimize();
Logger.logMessage(“–Finalized mesh”);
//Setup the object
inObj = new GameObject(“Amino Sequence”);
inObj.AddComponent(typeof(MeshRenderer));
MeshFilter filter = inObj.GetComponent(typeof(MeshFilter)) as MeshFilter;
if (filter == null)
{
Logger.logMessage(“Adding mesh filter”);
filter = inObj.AddComponent(typeof(MeshFilter)) as MeshFilter;
}
filter.renderer.material.color = Color.white;
filter.mesh = inMesh;
Logger.logMessage(“–Added mesh and filter to object”);
//Add it to the world and make it viewable
m_finalObj = Instantiate(inObj, objPos, objRot);
if (m_finalObj == null)
Logger.logMessage(“Object instantiation failed”);
Logger.logMessage(“–Instantiated object”);
}