ILShapes not drawn when added as a children to ILScreenObject - overlay

I am generating image plot by setting the surface plot in 2d mode. I am trying to draw the overlay crosshair as an ILScreenObject and move it to jog/navigate
through the surface points along the wireframe.
But any shapes I add to the ILScreenObject are not visible other than the ILLabel?
I am using the following code.
ILArray<float> specialData = ILSpecialData.sincf(20, 30);
ILSurface surface = new ILSurface(specialData);
surface.MouseClick += surface_MouseClick;
ILPlotCube cube = new ILPlotCube();
cube.Add(surface);
//construct ILScreenobject
ILScreenObject screenObj = new ILScreenObject();
screenObj.Children.Add(new ILLabel("test label"));
screenObj.Children.Add(Shapes.RectangleFilled);
ilPanel1.Scene.Add(cube);
ilPanel1.Scene.Camera.Add(screenObj);
ilPanel1.Refresh();
All I could see with this code is a label centered on the image plot. Could anyone suggest me any possible solution for this? Thanks.

Related

How to close a mesh in unity?

My projet is : user could draw with finger and I generate a field base on that.
I already got that from the user drawing :
So this is a succession of mesh but it's not close. I just generate the mesh in one direction with some height.
In need to close it. I don't want to be able the see through it.
My problem is : this drawing is random, so there is convexe and not convexe part . Let's illustrate that :
1- First I put a yellow circle on each point from my mesh ( I have this list of point with each (x,y,z) coordinate)
2- Then, with each 3 point following I try to make a mesh :
It's Ok when the shape we want to fill is concave but it will (I think) bug if the shape is convex :
And there is also this kind of bug, when the mesh is too big :
At the end, I just want to be able to close any shape I have. I hope I'm clear.
So the answer was to use Triangulation Algorithm , I use this repo https://github.com/mattatz/unity-triangulation2D
Just add to your code :
using mattatz.Triangulation2DSystem;
and you could launch the example from the github repo :
// input points for a polygon2D contor
List<Vector2> points = new List<Vector2>();
// Add Vector2 to points
points.Add(new Vector2(-2.5f, -2.5f));
points.Add(new Vector2(2.5f, -2.5f));
points.Add(new Vector2(4.5f, 2.5f));
points.Add(new Vector2(0.5f, 4.5f));
points.Add(new Vector2(-3.5f, 2.5f));
// construct Polygon2D
Polygon2D polygon = Polygon2D.Contour(points.ToArray());
// construct Triangulation2D with Polygon2D and threshold angle (18f ~ 27f recommended)
Triangulation2D triangulation = new Triangulation2D(polygon, 22.5f);
// build a mesh from triangles in a Triangulation2D instance
Mesh mesh = triangulation.Build();
// GetComponent<MeshFilter>().sharedMesh = mesh;

Best way to use Farseer/Box2D's DebugDraw in Unity3D?

Box2D/Farseer 2D physics has a useful component which draws a simple representation of the physics world using primitives (lines, polygons, fills, colors). Here's an example:
What's the best way to accomplish this in Unity3D? Is there a simple way to render polygons with fill, lines, points, etc.? If so, I could implement the interface of DebugDraw with Unity's API, but I'm having trouble finding how to implement primitive rendering like this with Unity.
I understand it'll be in 3D space, but I'll just zero-out one axis and use it basically as 2D.
In case you mean actually a debug box just displayed in the SceneView not in the GameView you can use Gizmos.DrawWireCube
void OnDrawGizmos()
{
//store original gizmo color
var color = Gizmos.color;
// store original matrix
var matrix = Gizmos.matrix;
// set gizmo to local space
Gizmos.matrix = transform.localToWorldMatrix;
// Draw a yellow cube at the transform position
Gizmos.color = Color.yellow;
// here set the scale e.g. for a "almost" 2d box simply use a very small z value
Gizmos.DrawWireCube(transform.position, new Vector3(0.5f, 0.2f, 0.001f));
// restor matrix
Gizmos.matrix = matrix;
// restore color
Gizmos.color = color;
}
you can use OnDrawGizmosSelected to show the Gizmo only if the GameObject is selected
you could also extend this by getting the box size over the inspector
[SerializeField] private Vector3 _boxScale;
and using
Gizmos.DrawWireCube(transform.position, _boxScale);

Adding a collider on a list of vectors

I'm trying to detect contours in a scene and add a collider to every detected object, I used the canny edge detector to get the coordinates of the detected objects.
Here is my output image
I need to add a collider to each black line to prevent my game object from going in/out of that area but I don't know how to do so exactly.
The findContours function returns a list of detected contours each stored as a vector of points but how do I use that to generate a collider?
Thank you for your help.
Update
Here is my source code (for the update method)
void Update ()
{
if (initDone && webCamTexture.isPlaying && webCamTexture.didUpdateThisFrame) {
//convert webcamtexture to mat
Utils.webCamTextureToMat (webCamTexture, rgbaMat, colors);
//convert to grayscale
Imgproc.cvtColor (rgbaMat, grayMat, Imgproc.COLOR_RGBA2GRAY);
//Blurring
Imgproc.GaussianBlur(rgbaMat,blurMat,new Size(7,7),0);
Imgproc.Canny(blurMat, cannyMat, 50,100);
Mat inverted = ~cannyMat;
//convert back to webcam texture
Utils.matToTexture2D(inverted, texture, colors);
Mat hierarchy = new Mat();
List<MatOfPoint> contours = new List<MatOfPoint>();
Imgproc.findContours(inverted, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
}
}
Use a PolygonCollider2d.
You can edit the collider at runtime using the SetPath function, to which you will pass a list of 2d points (that you already computed using the findContours function.
You can have several paths in the polygon if you want your collider to have holes.

How to calculate UVs of a flat poligon mesh

My game generates a flat surface (the floor of a building). It's a flat poligon mesh as shown in the picture:
The poligon is generated procedurally and will be different each time.
I need to map UV coordinates so that a standard square texture of, say,a floor made of bricks, is properly displayed.
What is the best way to assing the correct UV coordinates to each vertex?
With an irregular shape, you might want to "paste" a texture across the mesh(imagine pasting a rectangular sticker across your mesh and cutting away those that fall outside your mesh shape).
For that type of mapping, you might want to use Mesh.bounds, which gives you the bounding box of your mesh in local coordinates, which is the area you are going to "paste" your texture over.
Mesh mesh = GetComponent<MeshFilter>();
Bounds bounds = mesh.bounds;
Get the vertices of your mesh:
Vector3[] vertices = mesh.vertices;
Now do the mapping:
Vector2[] uvs = new Vector2[vertices.Length];
for(int i = 0; i < vertices.Length; i++)
{
uvs[i] = new Vector2(vertices[i].x / bounds.size.x, vertices[i].z / bounds.size.z);
}
mesh.uv = uvs;

Why ploting data in ILNumerics produce the result that is not symmetry? (2D Plot)

I have ILNumerics code like this:
var scene = new ILScene();
ILColormap cm = new ILColormap(Colormaps.Hot);
ILArray<float> data = cm.Data;
data[":;0"] = ILMath.pow(data[":;0"], 3.0f);
cm.Data = data;
ILArray<float> contoh = ILMath.zeros<float>(15, 15);
contoh[7, 14] = 1;
scene.Add(
new ILPlotCube(twoDMode: false){
new ILSurface(contoh){
Wireframe = { Color = Color.FromArgb(50, Color.LightGray)},
Colormap = new ILColormap(data),
Children = { new ILColorbar()}
}
}
);
ilPanel1.Scene = scene;
Roughly speak, I want to plot 2D model. In that matrix "contoh", I have one value that different with other neighbors. I want to plot that matrix become something like this figure:
But, there is that I got:
If we see the white area, it is not symmetry. Why this is happen? When I slightly rotate the model, we can see more clearly that even I have data in [14,7] position, the white area stretching until [13,6] but not to [13,8].
And for the last. Can anyone teach me how to make code that will generate a figure as like as Figure 1?
Both plots are different because they are of different type. The matlab one is an imagesc, the ILNumerics one is a surface. Imagesc plots will be available for ILNumerics with the next release.