Coder Social home page Coder Social logo

cloth-physics's Introduction

Cloth-Physics

Cloth Simulation showing moving curtains,a table cloth and how they interact with a ball.

The environment has been created to represent a house which is the Gui window. All the assets for the house were created in Maya and exported to Unity.

The picture frame belongs to the artist @Dimitris Giannakopoulos.

Curtains Mesh

In order to have the natural movement of the curtain first i created a mesh in studio 3D Max to represent the cloth. Therefore i created a plane where i increased the polygon counter regarding the width and the lengh. Afterwards i created the bones that will act as the constraints points in Unity 3D.By clicking from the vertex where i wanted to constrained, the vertex that i want to start the bone and drag until the vertex i wanted to stop constrained. The last step is to connect the mesh to the actual bone. Therefore i selected the mesh and i added a skin modifier.After selecting the bones and the mesh i exported into Unity.

After drag and drop the object into the scene , i created a cloth component where i specified the constraints. I added an external acceleration to add a bit of realism and by pressing play,the cloth is reacting as it is shown in the scene.

I added a sphere collider to demonstrate physics interaction with the cloth. You can move the sphere with the script:

// Update is called once per frame void Update () {

    float depth = 0.0f;
    if(Input.GetKey(KeyCode.Z))
       depth = 1.0f;
    else if (Input.GetKey(KeyCode.X))
        depth = -1.0f;

    bd.velocity = new Vector3(
        Input.GetAxisRaw("Horizontal"),
        Input.GetAxisRaw("Vertical"),
        depth) * Time.deltaTime * Speed;

}

#Shader

Shader "Custom/cloth_shader" {
Properties {
	_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {

            Cull Off


	Tags { "RenderType"="Opaque" }
	LOD 200
	
	CGPROGRAM
	#pragma surface surf Lambert

	sampler2D _MainTex;

	struct Input {
		float2 uv_MainTex;
	};

	void surf (Input IN, inout SurfaceOutput o) {
		half4 c = tex2D (_MainTex, IN.uv_MainTex);
		o.Albedo = c.rgb;
		o.Alpha = c.a;
	}
	ENDCG
} 
FallBack "Diffuse"

}

cloth-physics's People

Contributors

elenaamanita avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.