Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rendering #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/Mod Development/Blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ This component determines a few properties of your block, namely if it is a cube
### `Category`
This is the category (equivalent to a creative tab in Minecraft) that this block belongs to.

### `ItemRenderer`
This handles the rendering of the block in your inventory and hand.

### `Renderer`
This is responsible for rendering the block in the world. In the example above, `StaticRenderer` is used but there are a few others you can use as well.

Expand Down Expand Up @@ -78,6 +75,8 @@ To render your block you have several options:
- Use any of the other built-in NOVA renderers
- Create your own block renderer

More information can be found on the [Rendering](Rendering.md) page.

### `BlockRenderPipeline`
This is used for rendering simple cubes.

Expand Down
12 changes: 7 additions & 5 deletions docs/Mod Development/Items.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ItemScrewdriver extends Item {

public ItemScrewdriver() {
components.add(Category.TOOLS);
components.add(new ItemRenderer()).setTexture(NovaItem.screwTexture); // TODO: Deprecated
components.add(new StaticRenderer().onRender(new ItemRenderPipeline(this).withTexture(NovaItem.screwTexture).build()));

events.on(UseEvent.class).bind(event -> event.action = true);
}
Expand All @@ -26,8 +26,8 @@ There are some components you will probably always want to implement in your ite
### `Category`
This is the category (equivalent to a creative tab in Minecraft) that this item belongs to.

### `ItemRenderer`
This handles the rendering of the item in your inventory and hand.
### `Renderer`
This handles the rendering of the item in your inventory and hand. In the example above, `StaticRenderer` is used but there are a few others you can use as well.

## Special Interfaces
### `Syncable`
Expand All @@ -40,9 +40,11 @@ Examples include: Electric charge of batteries, amount of fuel in a canister, et
## Rendering
To render your item you have several options:

- Use the `ItemRenderer` (Deprecated)
- Use the `StaticRenderer` and the `ItemRenderPipeline`.
- Use any of the other built-in NOVA renderers
- Create your own item renderer

### `ItemRenderer`
More information can be found on the [Rendering](Rendering.md) page.

### `ItemRenderPipeline`
This is used for rendering simple items with a single texture.
83 changes: 83 additions & 0 deletions docs/Mod Development/Rendering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
So far, we've learned to create Blocks and Items, however they are currently invisible to the player. Therefore, we are going to learn how to render them and make them visible to the player.
Rendering in NOVA is handled using `Renderer`s and pipelines. To create a rendering pipeline, you must first choose a renderer and supply a pipeline to it in the `onRender` method.

```java
components.add(new StaticRenderer().onRender(new BlockRenderPipeline(this).withTexture(YourMod.blockTexture).build());
```

The code above adds a `StaticRenderer` to this object, then creates a `BlockRenderPipeline` for this object with the texture `blockTexture` provided by `YourMod`. After this is done, the `build()` method is called to finish the creation of the rendering pipeline and return a function for rendering the block.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too abrupt into code without establishing the context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context has been established.


## Renderers
A renderer is a component that determines how an object will appear ingame and how often the object will be redrawn. The following are all the renderers you can use in nova.

### `StaticRenderer`
This is used for rendering providers that only redraw the renderer when either the provider notifies the renderer to do so, or in case of blocks, the world notifies the renderer. To notify the block's `StaticRenderer` to redraw the model, you would call the following code:

```java
world().markStaticRender(position());
```

### `DynamicRenderer`
This is used for rendering providers that redraw the renderer every frame. This renderer should only be reserved for providers which truly need it.

## Render pipelines
A renderer needs to be supplied a rendering pipeline, which contains information on how to actually render the object. You can either create your own, or use any of the pre-built ones. To finish rendering with a pre-built pipeline, you have to call the `build()` method on the instance.

```java
components.add(new StaticRenderer().onRender(new RenderPipeline(this).build());
```

Where `RenderPipeline` is an implementation of the `RenderPipeline` abstract class. The following are implementations of the `RenderPipeline` class that come with NOVA which can be used on any provider type.

### `BlockRenderPipeline`
This is used for rendering simple cubes.

### `ItemRenderPipeline`
This is used for rendering flat one voxel thick squares.

## Models
NOVA also allows using of models to render renderable component providers. To load a model, you do the following:

```java
providedModel = renderManager.registerModel(new ModelProvider(MOD_ID, "grinder"));
```

Where `ModelProvieder` is an implementation of the `ModelProvider` abstract class. The following are implementations of the `ModelProvider` class that come with NOVA.

To render the model, you have to provide your own rendering pipeline. The following is a simple way to render the model shown above.

```java
components.add(new StaticRenderer().onRender(model -> {
Model providedModel = YourMod.providedModel.getModel();

if (providedModel instanceof MeshModel)
((MeshModel)providedModel).bindAll(YourMod.providedModelTexture);

model.children.add(grinderModel);
}
```

### `WavefrontObjectModelProvider`
Loads wavefront `.obj` models for use by your mod. Wavefront models are some of the most common model formats in use on the Internet.

### `TechneModelProvider`
Loads Techne `.tcn` models for use by your mod. Techne was created to easily make entity models for Minecraft, but it has seen application of it's model format in other places as well, such as rendering blocks and items.

### Advanced model usage

It is also possible to do some more advanced things when rendering models. The following is the code of `BlockStateful`'s rendering pipeline from NOVA Blocks Example.

```java
components.add(new StaticRenderer().onRender(model -> {
Model grinderModel = NovaBlock.grinderModel.getModel();

grinderModel
.combineChildren("crank", "crank1", "crank2", "crank3")
.matrix.rotate(new Rotation(RotationUtil.DEFAULT_ORDER, 0, 0, angle));

if (grinderModel instanceof MeshModel)
((MeshModel)grinderModel).bindAll(NovaBlock.grinderTexture);

model.children.add(grinderModel);
}));
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pages:
- Blocks: Mod Development/Blocks.md
- Items: Mod Development/Items.md
- Events: Mod Development/Events.md
- Rendering: Mod Development/Rendering.md
- NOVA Development:
- Development Workspace Setup: NOVA Development/Development Workspace Setup.md
- Formatting: NOVA Development/Formatting.md
Expand Down