- Home /
Question by
sebascontra · Jun 05, 2012 at 03:46 PM ·
c#if statement
[c#} Combining if statements
Hi there, I'm newbie scripting and I want to draw lines (or thin cylinders) to connect the nodes represented in this code.
Let me explain a bit how it works: Given an certain atlas, this function calls some nodes from a specific label and plots them in an "empty universe". I'm trying to connect them by colored lines assigned to each label.
I mean, for example, if I create nodes from the labels 1, 2, 3 and 4, I want to connect the nodes having the same starting point or ending point.
Here is the code:
//nodes
foreach (Transform location in subregion)
{
foreach (atlasRegionSubregionLocation node in connectomeModel.NodesGlobalIndexer.Values)
{
if(location.name == node.globalIndex.ToString())
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = location.position;
MeshRenderer currentSubRegionRenderer = sphere.GetComponent ("MeshRenderer") as MeshRenderer;
Material material = new Material(Shader.Find("Transparent/Diffuse"));
Color color;
if (node.regionRef.label == "lateralorbitofrontal")
color = new Color (1,0,0);
else
color = new Color(0.5f, 0.5f, 0.5f);
material.color = color;
currentSubRegionRenderer.material = material;
continue;
// how to add another if statement to create a Primitive as a
// cylinder (or a simple line) and render it if its in the same
// label or Index than the node??
}
}
}
// Berenger : I don't know what are those, you must have forgot
// the beginning of your code.
/* }
}
RENDER = true;
}*/
thanks in advance for any help
Comment
Answer by sebascontra · Jun 05, 2012 at 07:51 PM
well, I have this part of code that creates a polyhedron to connect btw locations, the thing is how to merge them?
// nodes
foreach (Transform location in subregion)
{
try
{
int nodeindex = System.Convert.ToInt16(location.gameObject.name);
atlasRegionSubregionLocation currentNode = connectomeModel.NodesGlobalIndexer[nodeindex] as atlasRegionSubregionLocation;
int edgeinstanceIndex = 0;
foreach (int edgeIndex in currentNode.EdgeTo)
{
ConnectomeModel.Edge currentEdge = connectomeModel.Edges[edgeIndex];
// Look for gameobjects representing edges
Vector3 fromCoord = (GameObject.Find(currentEdge.NodeFrom.ToString())).transform.position;
// transform to local region
fromCoord = fromCoord - subregion.transform.position;
Vector3 toCoord = (GameObject.Find(currentEdge.NodeTo.ToString())).transform.position;
toCoord = toCoord - subregion.transform.position;
instanceEdge(fromCoord , toCoord , (float)currentEdge.Weight * 1.5f + 0.5f, edgeinstanceIndex, ref tempEdges, ref tempTriangles);
edgeinstanceIndex++;
}
}
catch (System.Exception e)
{
Debug.Log("Skipped Node " + e.Message +" " + e.Source + " " + e.Data);
continue;
}
}
currentSubRegionMesh.mesh.vertices = tempEdges;
currentSubRegionMesh.mesh.triangles = tempTriangles;
currentSubRegionMesh.mesh.uv = new Vector2[ NodeTo_EdgeCount*12];
currentSubRegionMesh.mesh.RecalculateNormals();
currentSubRegionMesh.mesh.RecalculateBounds();
}
}
thanks!