- Home /
RealTime Dynamic Modeling
Hi All I am working on a scientific application to show bacterias activities in a real-time 3D viewer. I am pretty good in C# but i don't have any idea about 3D viewing. I have a big 3D matrix which is changing per millisecond and I want to create an object based on that matrix on Unity. I was wondering if you guide me to to create a dynamic 3D object on unity in real-time.
Sounds very interesting, but can you go a bit more in detail? how big is your matrix (and what dimention count) and what do you want to render actually? just a "sprite" for each bacteria? what information do you need to display? does each cell have a fix position (in 3D space)? in other words do you want to display your matrix as plane or cube rasterized? Another thing: you said you update your matrix (once) per millisec.? In Unity you're bound to the actual (drawing) frame rate. You can use seperate threads but the whole Unity api isn't thread safe, so it won't help much.
Answer by kennypu · Apr 18, 2011 at 07:58 PM
you basicly edit the mesh data of an object( http://unity3d.com/support/documentation/ScriptReference/Mesh.html ).
You can check out examples in the procedural programming examples here: http://unity3d.com/support/resources/example-projects/procedural-examples.html
Answer by Mortennobel · Apr 18, 2011 at 08:06 PM
What use are asking is if Unity supports volumetric rendering (of your data stored in a 3D matrix).
The short answer is no. At least there is no simple way to do it.
You could try to visualize your data as procedural generated voxels - but this may be too slow for large data sets.
A more advanced approach is to do ray-tracing in the Cg shader. This is indeed possible - but requires that you know how to program Cg shaders in Unity.
More info about volumetric rendering: http://http.developer.nvidia.com/GPUGems3/gpugems3_ch30.html
Also checkout the wikipedia about volume rendering: http://en.wikipedia.org/wiki/Volume_rendering#External_links
A way to get started with procedural mesh generation in Unity can be found on my blog: http://blog.nobel-joergensen.com/2010/12/25/procedural-generated-mesh-in-unity/
I have read "procedural mesh generation in Unity" it was awesome, but my raw data is a bulk of points in a 3D world. special device scans each millisecond and returns 10,000 points like (x,y,z). Do you think that this way is feasible?
No. I don't think Unity is the best tool for this problem.
Answer by DaveA · Apr 18, 2011 at 09:11 PM
You can generate this scene, either at Startup or in an Editor script, something like:
var dataPoint : Transform; // assign this to something in the Inspector var dataPoints : Transform[]; // this could be a multi-dim array but I forget exact syntax offhand
function Start()
{
dataPoints = new Transform[33*33*33]; // holds our new datapoint objects
for (var x = 0; x < 33; x++)
for (var y = 0; y < 33; y++)
for (var z = 0; z < 33; z++)
dataPoints[x+y*33+z*33*33] = Instantiate (dataPoint, new Vector3(x,y,z),Quaternion.identity);
}
Then you have an array of your points. The thing you assign to dataPoint could be like a particle or cube or something very simple. Billboarded triangle would be cool and fast, but billboarding 10000 objects might be slow, unless your view never changes (boring). Tetrahedron is the next simplest object. Anyway, you'd grab your objects and set them something like:
Update()
{
for (whatever changed, get index to the object)
dataPoints[x+y*33+z*33*33].GetComponent(Renderer).material.color = new Color (somethng based on the data);
}
But you'd also need like 10000 separate materials, so read this: http://unity3d.com/support/documentation/ScriptReference/Renderer-material.html
You actually don't need to create 10000 materials ;) Every mesh rederer owns his own material instance that get copied from the shared$$anonymous$$aterial which have been assigned to the renderer in the editor. I also wouldn't use seperate gameobjects objects for that amount. I would use a logical object (like the particleEmitter do) and use just a few renderer. Just to have it mentioned: your examples are in JS ;)
Thanks Bunny83. Yeah, my examples are also psuedo-code! Good points all. He could also try sub-meshes fwiw. If there are a limited number of representations (I was assu$$anonymous$$g color, but it could be anything), then there could be one mesh per appearance, and just assign things as needed, but Combine$$anonymous$$eshes would be too slow for his cycle time. Very interesting problem.
Thanks for your attention to my problem, I am working on it and i will let you know my result.
Answer by pooyax · Apr 19, 2011 at 07:02 PM
Dear Bunny83 the result of scan comes up each 30 millisecond. this device scans the surface of bacterias and returns bunch of points in 3D world. in this case, Z axis determines our depth. regardless of shape of that, i wanna model it on a 3D viewer.The number of matrix element is constant (10,000) and i also know that some of them are not changed.
Answer by Jordane Almeida · Jul 31, 2012 at 08:40 PM
I've got a problem, not yet assimilated how to make the UVs of a cube here is the code can someone help me?
using UnityEngine; using System.Collections;
[RequireComponent (typeof (MeshCollider))] [RequireComponent (typeof (MeshFilter))] [RequireComponent (typeof (MeshRenderer))]
public class Create_Cube : MonoBehaviour {
public Color ColorBloc; public Texture2D Textura;
// Use this for initialization void Start () {
Mesh mesh = new Mesh ();
mesh=GetComponent<MeshFilter>().mesh;
Vector3 p0 = new Vector3(0,0,0); Vector3 p1 = new Vector3(1,0,0); Vector3 p2 = new Vector3(0,1,0); Vector3 p3 = new Vector3(0,0,1); Vector3 p4 = new Vector3(1,0,1); Vector3 p5 = new Vector3(1,1,0); Vector3 p6 = new Vector3(0,1,1); Vector3 p7 = new Vector3(1,1,1);
mesh.vertices = new Vector3[]{p0,p1,p2,p3,p4,p5,p6,p7};
mesh.triangles = new int[]{ 0,2,1, 1,2,5, //face 1 3,0,1, 1,4,3, //face 2 0,3,2, 2,3,6, //face 3 1,5,4, 5,7,4, //face 4 6,3,4, 6,4,7, //face 5 6,5,2, 7,5,6 //face 6 };
//mesh.uv = new Vector2[]{new Vector2(0.0f,0.0f),new Vector2(1.0f,0.0f),new Vector2(0.0f,1.0f),new Vector2(0.0f,0.0f),new Vector2(1.0f,0.0f),new Vector2(1.0f,1.0f),new Vector2(0.0f,1.0f),new Vector2(1.0f,1.0f)};
mesh.uv = new Vector2[]{
new Vector2(0,0), new Vector2(0,1),
new Vector2(1,0),new Vector2(0,1),
new Vector2(1,1), new Vector2(0,0),
new Vector2(0,0), new Vector2(1,0)
};
renderer.material = new Material(Shader.Find("Diffuse"));
renderer.material.mainTexture = Textura; renderer.material.color = ColorBloc;
mesh.RecalculateNormals(); mesh.RecalculateBounds (); mesh.Optimize();
} // Update is called once per frame void Update () {
} }
Your answer
