Hi,
Would someone know how to assign an fbx and/or Mesh to an InteractiveCloth’s mesh variable using javascript?
Any help would be much apprieciated ![]()
Thanks,
Dave
Hi,
Would someone know how to assign an fbx and/or Mesh to an InteractiveCloth’s mesh variable using javascript?
Any help would be much apprieciated ![]()
Thanks,
Dave
I managed to get a bit further. I wasn’t able to replace the mesh variable unless I completely recreated the InteractiveCloth (see sample code below). This solution should be fine for what I’m trying to accomplish but at the moment I can’t figure out how to add the Cloth Renderer component to my new Game Object. Would anyone out there know how to do that?
Thanks,
Dave
var myGameObj = GameObject.Find("myGameObj");
if (myGameObj != null) {
var interactCloth = myGameObj.GetComponent(InteractiveCloth);
var interactClothMesh : Mesh = interactCloth.mesh;
var vertices : Vector3[] = interactClothMesh.vertices;
var uvs : Vector2[] = interactClothMesh.uv;
var normals : Vector3[] = interactClothMesh.normals;
var triangles : int[] = interactClothMesh.triangles;
var clothRenderer = myGameObj.GetComponent(Renderer);
if (clothRenderer != null) Destroy (myGameObj.GetComponent(Renderer));
if (interactCloth != null) Destroy (myGameObj.GetComponent(InteractiveCloth));
Destroy (myGameObj);
//Changing vert positions test example
for (var i = 0; i < vertices.Length; i++) vertices[i] += normals[i] * Mathf.Sin(Time.time) * 0.01;
interactClothMesh.Clear();
interactClothMesh.vertices = vertices;
interactClothMesh.uv = uvs;
interactClothMesh.normals = normals;
interactClothMesh.triangles = triangles;
myGameObj = new GameObject("myGameObj");
interactCloth = myGameObj.AddComponent (InteractiveCloth);
interactCloth.bendingStiffness = 0.1;
interactCloth.stretchingStiffness = 0.1;
interactCloth.damping = 0.1;
interactCloth.thickness = 0.1;
interactCloth.useGravity = false;
interactCloth.selfCollision = false;
interactCloth.externalAcceleration = Vector3(0,0,0);
interactCloth.randomAcceleration = Vector3(0,0,0);
interactCloth.mesh = interactClothMesh;
interactCloth.friction = 0;
interactCloth.density = 0.5;
interactCloth.pressure = 0;
interactCloth.collisionResponse = 0.072;
interactCloth.attachmentTearFactor = 2;
interactCloth.attachmentResponse = 0.072;
interactCloth.tearFactor = 2;
}
Figured it out ![]()
clothRenderer = myGameObj.AddComponent (ClothRenderer);