{"id":1693,"date":"2013-03-13T19:19:13","date_gmt":"2013-03-13T16:19:13","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=1693"},"modified":"2013-03-13T23:08:15","modified_gmt":"2013-03-13T20:08:15","slug":"three-js-planegeometry-js-to-unity-c","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2013\/03\/13\/three-js-planegeometry-js-to-unity-c\/","title":{"rendered":"Three.js PlaneGeometry.js to Unity C#"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1694\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/03\/13\/three-js-planegeometry-js-to-unity-c\/planegeometry_unity_csharp_1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/planegeometry_unity_csharp_1.jpg?fit=680%2C527&amp;ssl=1\" data-orig-size=\"680,527\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"planegeometry_unity_csharp_1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/planegeometry_unity_csharp_1.jpg?fit=680%2C527&amp;ssl=1\" class=\"alignnone size-full wp-image-1694\" alt=\"planegeometry_unity_csharp_1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/planegeometry_unity_csharp_1.jpg?resize=680%2C527\" width=\"680\" height=\"527\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/planegeometry_unity_csharp_1.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/planegeometry_unity_csharp_1.jpg?resize=300%2C232&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Converted this <a title=\"http:\/\/threejsdoc.appspot.com\/doc\/three.js\/src.source\/extras\/geometries\/PlaneGeometry.js.html\" href=\"http:\/\/threejsdoc.appspot.com\/doc\/three.js\/src.source\/extras\/geometries\/PlaneGeometry.js.html\" target=\"_blank\">THREE.js PlaneGeometry.js<\/a> (by mr.doob) to Unity c# (its similar to <a title=\"http:\/\/wiki.unity3d.com\/index.php\/CreatePlane\" href=\"http:\/\/wiki.unity3d.com\/index.php\/CreatePlane\" target=\"_blank\">CreatePlane<\/a> from unity wiki, but more limited)<\/p>\n<p><strong>Current version:<\/strong><br \/>\n&#8211; Using MeshTopology.Quads<br \/>\n&#8211; Still some problems with the UV&#8217;s, if using more than one segments<br \/>\n&#8211; Also currently all the variables are as ints, so need to use even numbers<br \/>\n&#8211; And missing normals..<\/p>\n<p><strong>Source: <\/strong><em>** Use the finished source from alexzzzz on comment section links instead **<\/em><strong><br \/>\n<\/strong><\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\r\nusing UnityEngine;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\n\r\npublic class PlaneGeometry : MonoBehaviour\r\n{\r\nvoid Start()\r\n{\r\nCreatePlane(4,4,4,4);\r\n}\r\n\r\nvoid CreatePlane(int width, int height, int segmentsWidth, int segmentsHeight)\r\n{\r\nint ix, iy,\r\nwidth_half = width \/ 2,\r\nheight_half = height \/ 2,\r\ngridX = segmentsWidth,\r\ngridY = segmentsHeight,\r\ngridX1 = gridX + 1,\r\ngridY1 = gridY + 1,\r\nsegment_width = width \/ gridX,\r\nsegment_height = height \/ gridY;\r\nVector3 normal = new Vector3( 0, 0, 1 );\r\nList&lt;Vector3&gt; vertices = new List&lt;Vector3&gt;();\r\nList&lt;Vector3&gt; vertexNormals = new List&lt;Vector3&gt;();\r\nList&lt;int&gt; faces = new List&lt;int&gt;();\r\nList&lt;Vector2&gt; faceVertexUvs = new List&lt;Vector2&gt;();\r\nfor ( iy = 0; iy &lt; gridY1; iy++ ) {\r\nfor ( ix = 0; ix &lt; gridX1; ix++ ) {\r\nfloat x = ix * segment_width - width_half;\r\nfloat y = iy * segment_height - height_half;\r\nvertices.Add(new Vector3(x, -y, 0));\r\n}\r\n}\r\n\r\nfor ( iy = 0; iy &lt; gridY; iy++ ) {\r\nfor ( ix = 0; ix &lt; gridX; ix++ ) {\r\nint a = ix + gridX1 * iy;\r\nint b = ix + gridX1 * (iy + 1);\r\nint c = (ix + 1) + gridX1 * (iy + 1);\r\nint d = (ix + 1) + gridX1 * iy;\r\nfaces.Add(a);\r\nfaces.Add(b);\r\nfaces.Add(c);\r\nfaces.Add(d);\r\nfaceVertexUvs.Add(new Vector2(ix \/ gridX, iy \/ gridY));\r\nfaceVertexUvs.Add(new Vector2(ix \/ gridX, (iy + 1) \/ gridY));\r\nfaceVertexUvs.Add(new Vector2((ix + 1 ) \/ gridX, ( iy + 1 ) \/ gridY));\r\nfaceVertexUvs.Add(new Vector2((ix + 1 ) \/ gridX, iy \/ gridY));\r\n}\r\n}\r\n\/\/ create mesh\r\nMesh m = GetComponent&lt;MeshFilter&gt;().mesh;\r\nm.vertices = vertices.ToArray();\r\nm.SetIndices(faces.ToArray(), MeshTopology.Quads, 0);\r\nm.uv = faceVertexUvs.ToArray();\r\n}\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Converted this THREE.js PlaneGeometry.js (by mr.doob) to Unity c# (its similar to CreatePlane from unity wiki, but more limited) Current version: &#8211; Using MeshTopology.Quads &#8211; Still some problems with the UV&#8217;s, if using more than one segments &#8211; Also currently all the variables are as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1694,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3],"tags":[428,430,5,429,427],"class_list":["post-1693","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-unity3d","tag-create","tag-geometry","tag-mesh","tag-plane","tag-three-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/planegeometry_unity_csharp_1.jpg?fit=680%2C527&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-rj","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=1693"}],"version-history":[{"count":5,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1693\/revisions"}],"predecessor-version":[{"id":1698,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1693\/revisions\/1698"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/1694"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=1693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=1693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=1693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}