- Home /
Make curve of cube?
Hi everyone, i dont know how it say.. but i need to make curving cube at run-time. Is it possible? I cant use blender, Creo, 3DsMax or something like that. I have to do in unity at run-Time.. I want to do a room, with 4 walls.. but last wall will be curving or edge radius. Like this -> " ) ". Can u help me with this horrible problem?
Thanks Kind regards Thomas
You could use Blender for it, using Shape$$anonymous$$eys (BlendShapes). Aside from that you would have to manipulate the $$anonymous$$esh data. $$anonymous$$egaFiers did things like this I believe.
Thnaks, but i cant use bleder... i have to do only in unity editor... at run-time.. do you have any idea how to do it?
Doesnt exist some modul or script with this function? i mean, i have high polygone cube... and i cant to do by creating polygones from script... simple like this
I suggest you include any attempts you have made for yourself.
Answer by Andres-Fernandez · Jul 07, 2014 at 12:03 PM
You have to create the mesh at runtime. Check here for the details. You'll have to do some math to get the curved wall. It'll probably take some time, but it's possible.
Thanks, i saw this website.. but i dont know how to start with it... Can u write me more? i mean... need i a cube from unity, or other cube from any 3D model, or nothing? and create a cube from script? thnaks.. again
Read the docs and check the links we posted. The steps you need to follow are:
Create the GameOBject (if needed).
Add a $$anonymous$$eshFilter component.
Create a new $$anonymous$$esh.
Create an array of vertices positions.
Create an array of triangle indexes.
Create an array of UVs (if needed).
Apply the arrays to the mesh.
Calculate the normals of the mesh.
Set the mesh to the meshFilter component.
Here you have some examples. Then, apply material, color, texture or whatever.
Thank you very much :) sorry for my stupidity... but im newbie in unity, and this is my first complicate problem.
It's not being stupid, it's just being new to something. Start with the small examples.
Answer by Raynoko · Jul 08, 2014 at 10:23 AM
i have this source code ...
public var mat : Material;
public var vert : Vector3[];
public var tris : int[];
var normals: Vector3[];
var uv: Vector2[];
function Start(){
vert = new Vector3[5];
tris = new int[6];
tris [0] = 0; tris [3] = 3;
tris [1] = 2; tris [4] = 2;
tris [2] = 1; tris [5] = 4;
normals = new Vector3[5];
normals[0] = -Vector3.forward;
normals[1] = -Vector3.forward;
normals[2] = -Vector3.forward;
normals[3] = -Vector3.forward;
normals[4] = -Vector3.forward;
uv = new Vector2[5];
uv[0] = new Vector2(0, 0);
uv[1] = new Vector2(1, 0);
uv[2] = new Vector2(1, 1);
uv[3] = new Vector2(0, 0);
uv[4] = new Vector2(1, 0);
}
function Update(){
vert [0] = new Vector3 (transform.GetChild(0).gameObject.transform.position.x,
transform.GetChild(0).gameObject.transform.position.y,
transform.GetChild(0).gameObject.transform.position.z);
vert [1] = new Vector3 (transform.GetChild(1).gameObject.transform.position.x,
transform.GetChild(1).gameObject.transform.position.y,
transform.GetChild(1).gameObject.transform.position.z);
vert [2] = new Vector3 (transform.GetChild(2).gameObject.transform.position.x,
transform.GetChild(2).gameObject.transform.position.y,
transform.GetChild(2).gameObject.transform.position.z);
vert [3] = new Vector3 (transform.GetChild(3).gameObject.transform.position.x,
transform.GetChild(3).gameObject.transform.position.y,
transform.GetChild(3).gameObject.transform.position.z);
vert [4] = new Vector3 (transform.GetChild(4).gameObject.transform.position.x,
transform.GetChild(4).gameObject.transform.position.y,
transform.GetChild(4).gameObject.transform.position.z);
var mesh : Mesh = new Mesh ();
mesh.vertices = vert;
mesh.triangles = tris;
mesh.normals = normals;
mesh.uv = uv;
if (!GetComponent(MeshFilter)) {
gameObject.AddComponent(MeshFilter);
}
if (!GetComponent(MeshRenderer)) {
gameObject.AddComponent(MeshRenderer);
}
if (!GetComponent(MeshCollider)) {
gameObject.AddComponent(MeshCollider);
}
gameObject.GetComponent(MeshFilter).mesh = mesh;
gameObject.GetComponent(MeshRenderer).material = mat;
}
wich i have 5 children, when i move one of them my plane changing, and recalculate size, but i dont know how to do "for" i mean source code, wich it will automatic create this children next to one. and then create plane looks like one plane of cube.
this is screenShot, where are my moveable children...
Answer by musaranya · Jul 08, 2014 at 07:07 AM
what about making the wall using small cubes and then move this cubes to get the curve effect? This way you don't need to edit any mesh so it may be easier...
i was thinking about this solution, but i think that its complicate for my later work, i need one cube with engle radius, because i will apply material, color or textures, and i think that textures will be deformed if ill make one cube from a lot of small cubes.
Your answer
Follow this Question
Related Questions
See colors when inside Cube - Worldbuilding in a gameobject 2 Answers
How do i detect if a certain cube is being touched? 6 Answers
Instantiating Cube Prefabs with scale 3 Answers
Sorting list of Transforms 1 Answer
Is there a way to edit the dimensions of a gameobject such as a cube or a plane? 2 Answers