Catlike Coding - Constructing a Fractal Flashcards
What is MeshFilter?
A class that inherits from component which is used to access Mesh of the MeshFilter.
Since MeshFilter inherits from Component, we can also say that it is a Unity component.
What is Mesh?
A class that allows creating or modifying meshes from scripts.
Mechanically, a Mesh is a construct used by the graphics hardware to draw complex stuff. It’s a 3D object that’s either imported into Unity, is of Unity’s default shapes, or generated by code.
A mesh contains at least a collection of points in 3D space plus a set of triangles – the most basic 2D shapes – defined by these points. The triangles constitute the surface of whatever the mesh represents. Often, you won’t realize that you’re looking at a bunch of triangles instead of a real object.
The triangle arrays are simply indices into the vertex arrays; three indices for each triangle.
What is MeshRederer?
Renders meshes inserted by the MeshFilter or TextMesh.
What’s a Material?
Materials are used to define the visual properties of objects. They can range from very simple, like a constant color, to very complex.
Materials consist of a shader and whatever data the shader needs. Shaders are basically scripts that tell the graphics card how an object’s polygons should be drawn.
When is Start invoked?
The Start method is called by Unity after the component (the script itslef) is created, once it’s active, and just before the first time its Update method would be called, if it had one.
It’s only called once.
How does AddComponent work?
Adds a component class of type to the game object - either current object or a specified object.
Remember that all components must be attached to a gameObject.
Current game object is always referred to within script as gameObject, without the need to create a variable/instantiate an object as it has already been done for you in UnityEngine namespace under the component class.
Not sure if the underlined is correct (ignore it for now)
What is a Generic Method?
A method template that can work with a range of types. You tell it what type to use by mentioning it between angle brackets.
What is one way you create a cube from script and add it to the scene? - Assume that you have an empty game object
Any primitive you want to add to your scene will need a mesh and a material
You add “your” specified mesh and material to an object by accessing the mesh and material properties (of type Mesh and Material) from the MeshFilter class and the MeshRenderer Class respectively.
Finally you select the mesh and material you want from the “Unity properties” in the Unity editor.
Mesh mesh;
Material material;
GameObject.AddComponent<meshfilter>().mesh = mesh;</meshfilter>
GameObject.AddComponent<meshrenderer>().material = material;</meshrenderer>
Create a GameObject, call it “Le New” and add a component to it (Do it in both ways).
new GameObject(“Le New”).AddComponent();
new GameObject(“Le New”, typeof(Script));
REMEMBER THAT ANY SCRIPT ATTACHED TO A GAMEOBJECT IS IN ITSLEF A COMPONENT!
What does “new” do?
The new keyword is used to construct a new instance of an object or a struct.
It is followed by a special constructor method, which has the same name as the class or struct it belongs to.
Below are some example constructors from the class GameObject:
<em>public GameObject(string name, params Type[] components);</em>
<em>public GameObject(string name);</em>
To instantiate the above, you just add the new keyword followed by the constructor in your “sketch”.
What is “this”?
This is the current object/struct whose method is being called.
This is the instance of the script you’re in.
It is being used implicitly the whole time when refering to stuff from the same class
Layman’s terms:
Lets say you create an object from a class
MyObject myObject_1 = new MyObject;
Now when refering to object in another class you use myObject_1 to do so. But lets say you’re in MyObject class, and you want to refer to the instance of MyObject, in this case you use the keyword “this”.
Create a Recursive GameObject that re-initilizes itself 4 times only and make each object the child of the previous.
int depth = 0, maxDepth = 4;
if (depth < maxDepth) {
new GameObject(“MyRecursiveObject”).AddComponent.Initialize(this)
}
void Initialize(Sketch sketch) {
maxDepth = sketch.maxDepth;
depth = sketch.depth + 1;
transform.parent = sketch.transform;
}
Decribe what this line does and the method below
new GameObject(“Child of Fractal”).AddComponent < sketch > (). Initialize(this);
private void Initialize(Test sketch) {
myMesh = mesh.sketch;
}
This line does 4 things
- Creates a new game object
- gives it a name
- Adds a component to it
- Does whatever the initialize method tells it to do.
Describe what each one of these lines does:
transfrom. localScale
transform. localPosition
Vector3.up
Vector3.one
Scale relative to parent
Position relative to parent
Where is up in the scene compared to the real world? (up in this case - also this is a shorthand for new Vector 3 (0,1,0)
Shorthand for new Vector3 (1,1,1)
Explain the concept of creating smaller cubes from a larger one positioning each one incrementally further the the previous.
Each cube needs to change size at a fixed scale relative to the parent cube.
Each cube also needs to change position relative to the previous position.
Our first step is to create a scalar variable which we will use to:
Multiply the size of each cube, where each cube’s size is assumed to be one.
As for the position, we also use the scalar to multiply the poistion of each cube to get the position of the new one. In this case of distances, however, we also add a fixed distance to each new cube in order to offset the distance relative to the size of the cube.