Last active
August 29, 2015 14:22
-
-
Save rev087/079923df0d4105397740 to your computer and use it in GitHub Desktop.
Procedural DNA Double Helix 3D model using Forge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using Forge; | |
using Forge.Primitives; | |
using Forge.Filters; | |
public class DNADoubleHelix : ProceduralAsset { | |
private float Radius = 0.04f; | |
private float Offset = 0.4f; | |
[Range(0, 70)] public int Copies = 1; | |
[Range(-20f, 20f)] public float Twist = 5f; | |
[Range(0.0f, 0.5f)] public float SegmentLength = 0.05f; | |
private int Detail = 8; | |
public override Geometry Build() { | |
// A | |
var circle1 = new Circle(); | |
circle1.Radius = Radius; | |
circle1.Center = new Vector3(Offset, 0f, 0f); | |
circle1.Segments = Detail; | |
var copy1 = new Copy(circle1.Output()); | |
copy1.Rotation = new Vector3(0f, Twist, 0f); | |
copy1.Position = new Vector3(0f, SegmentLength, 0f); | |
copy1.Copies = Copies; | |
var bridge1 = new Bridge(copy1.Output()); | |
// B | |
var circle2 = new Circle(); | |
circle2.Radius = Radius; | |
circle2.Center = new Vector3(-Offset, 0f, 0f); | |
circle2.Segments = Detail; | |
var copy2 = new Copy(circle2.Output()); | |
copy2.Rotation = new Vector3(0f, Twist, 0f); | |
copy2.Position = new Vector3(0f, SegmentLength, 0f); | |
copy2.Copies = Copies; | |
var bridge2 = new Bridge(copy2.Output()); | |
// C | |
var circle3 = new Circle(); | |
circle3.Radius = Radius / 3; | |
circle3.Orientation = OrientationPreset.ZY; | |
circle3.Center = new Vector3(Offset, 0f, 0f); | |
circle3.Segments = Detail; | |
var mirror = new Mirror(circle3.Output()); | |
var mid = new Merge(Reverse.Process(circle3.Output()), mirror.Output()); | |
var midBridge = new Bridge(mid.Output()); | |
midBridge.RecalculateNormals = true; | |
var midCopy = new Copy(midBridge.Output()); | |
midCopy.Copies = Copies / 2 - 1; | |
midCopy.Rotation = new Vector3(0f, Twist * 2, 0f); | |
midCopy.Position = new Vector3(0f, SegmentLength * 2, 0f); | |
// Glue all the pieces now! | |
var merge = new Merge( | |
bridge1.Output(), | |
midCopy.Output(), | |
bridge2.Output() | |
); | |
return merge.Output(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment