Skip to content

Commit

Permalink
change: Add documentation and change ticks to milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed Sep 21, 2023
1 parent 692bf38 commit f57141a
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 30 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {

modRuntimeOnly "maven.modrinth:lazydfu:0.1.3"
modRuntimeOnly "maven.modrinth:lithium:mc1.20.1-0.11.2"
modRuntimeOnly "maven.modrinth:sodium:mc1.20.1-0.5.3"
modRuntimeOnly "maven.modrinth:sodium:mc1.20.1-0.5.2"

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
Expand Down
115 changes: 115 additions & 0 deletions docs/schema-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This specification defines a format for a set of rules for the purpose of custom
- [Animated](#animated-skyboxes)
- [`animated-square-textured`](#animated-square-textured-skybox)
- [`single-sprite-animated-square-textured`](#single-sprite-animated-square-textured-skybox)
- [`multi-texture`](#multi-texture-skybox)
- [Data Types](#data-types)
- [Properties Object](#properties-object)
- [Conditions Object](#conditions-object)
Expand All @@ -38,6 +39,8 @@ This specification defines a format for a set of rules for the purpose of custom
- [Blend Object](#blend-object)
- [Blender Object](#blender-object)
- [Loop Object](#loop-object)
- [Animation Object](#animation-object)
- [UV Ranges Object](#uv-ranges-object)
- [Full Example](#full-example)

# Structure
Expand Down Expand Up @@ -271,6 +274,24 @@ The basic structure of a fabricskyboxes skybox file may look something like this
[
/* single sprite texture for first frame (string) */
// ...
],
"animations": [ // animation objects for animation (multi-texture)
{
"texture": "", // animation sprite sheet texture (string)
"uvRanges": { // uv ranges for animation (uv-ranges-object)
"minU": 0.25,
"minV": 0.25,
"maxU": 0.50,
"maxV": 0.50
},
"gridColumns": 32, // number of columns in sprite sheet
"gridRows": 1, // number of rows in sprite sheet
"duration": 40, // duration of each sprite in milliseconds
"frameDuration": { // map of frame duration in milliseconds
"1": 20,
"5": 10
}
}
]
}
```
Expand Down Expand Up @@ -374,6 +395,14 @@ Only the `single-sprite-animated-square-textured` skybox type uses these fields
|:-------------------:|:-----------------------------------------:|:----------------------------------------------------:|:------------------:|:-------------:|
| `animationTextures` | Array of [Namespaced Ids](#namespaced-id) | Specifies a list of locations to textures to be used | :white_check_mark: | - |

### Multi Texture Skybox

Only the `multi-texture` skybox type uses these fields

| Name | Datatype | Description | Required | Default value |
|:------------:|:-----------------------------------------------:|:------------------------------------------------:|:--------:|:-------------:|
| `animations` | Array of [Animation objects](#animation-object) | Specifies a list of animation objects to be used | :x: | - |

## Data types

### Properties Object
Expand Down Expand Up @@ -681,6 +710,32 @@ Does not contain any fields.
]
```

### Map Object

Represents an object consisting of key-value pairs.

**Specification**

This object does not have specific predefined fields. It's a flexible structure that can hold various types of keys and values.

**Examples**

Example 1: Map with integer keys and integer values
```json
{
"100": 0,
"2000": 512
}
```
Example 2: Map with [Namespaced Ids](#namespaced-id) as keys and boolean values
```json
{
"minecraft:the_nether": false,
"minecraft:overworld": true
}
```


### Rotation Object

Specifies static and axis rotation for a skybox.
Expand Down Expand Up @@ -881,6 +936,66 @@ Specifies the loop condition.
}
```

### Animation Object

Specifies an animation object.

**Specification**

| Name | Datatype | Description | Required | Default Value |
|:---------------:|:-------------------------------------------:|:-----------------------------------------------------------------------------:|:------------------:|:-------------:|
| `texture` | [Namespaced Id](#namespaced-id) | Specifies the location of the texture to be used when rendering the animation | :white_check_mark: | - |
| `uvRanges` | [UV Ranges Object](#uv-ranges-object) | Specifies the location in UV ranges to render the animation | :white_check_mark: | - |
| `gridColumns` | Integer | Specifies the amount of columns the animation texture has | :white_check_mark: | - |
| `gridRows` | Integer | Specifies the amount of rows the animation texture has | :white_check_mark: | - |
| `duration` | Integer | Specifies the default duration of each animation frame in milliseconds | :white_check_mark: | - |
| `frameDuration` | [Map Object](#map-object)<Integer, Integer> | Specifies the specific duration per animation frame | :x: | - |

**Example**

```json
{
"texture": "fabricskyboxes:/sky/anim_texture.png",
"uvRanges": {
"minU": 0.25,
"minV": 0.25,
"maxU": 0.50,
"maxV": 0.50
},
"gridColumns": 32,
"gridRows": 1,
"duration": 40,
"frameDuration": {
"1": 20,
"5": 10
}
}
```

### UV Ranges Object

Specifies a UV range object for defining texture coordinates.

**Specification**

| Name | Data Type | Description | Required | Default Value |
|:------:|:--------------:|:----------------------------------:|:------------------:|:-------------:|
| `minU` | Floating Point | Specifies the minimum U coordinate | :white_check_mark: | - |
| `minV` | Floating Point | Specifies the minimum V coordinate | :white_check_mark: | - |
| `maxU` | Floating Point | Specifies the maximum U coordinate | :white_check_mark: | - |
| `maxV` | Floating Point | Specifies the maximum V coordinate | :white_check_mark: | - |

**Example**

```json
{
"minU": 0.25,
"minV": 0.25,
"maxU": 0.50,
"maxV": 0.50
}
```

# Full Example

Here is a full skybox file for example purposes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.github.amerebagatelle.fabricskyboxes.util.object.*;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.Util;
import net.minecraft.util.math.RotationAxis;
import org.joml.Matrix4f;
Expand Down Expand Up @@ -85,8 +84,9 @@ public void renderSkybox(WorldRendererAccess worldRendererAccess, MatrixStack ma

// animations
for (Animation animation : this.animations) {
animation.tick();
UVRange intersect = Utils.findUVIntersection(faceUVRange, animation.getUvRanges()); // todo: cache this intersections so we don't waste gpu cycles
if (intersect != null && animation.getCurrentFrame() != null && animation.getNextFrame() != null) {
if (intersect != null && animation.getCurrentFrame() != null) {
UVRange intersectionOnCurrentTexture = Utils.mapUVRanges(faceUVRange, this.quad, intersect);
UVRange intersectionOnCurrentFrame = Utils.mapUVRanges(animation.getUvRanges(), animation.getCurrentFrame(), intersect);

Expand All @@ -105,14 +105,6 @@ public void renderSkybox(WorldRendererAccess worldRendererAccess, MatrixStack ma
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
}

@Override
public void tick(ClientWorld clientWorld) {
super.tick(clientWorld); // Don't remove :)
for (Animation animation : this.animations) {
animation.tick();
}
}

public List<Animation> getAnimations() {
return animations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.fabricskyboxes.util.Utils;
import net.minecraft.util.Util;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -27,9 +28,8 @@ public class Animation {
private final Map<Integer, Integer> frameDuration;

private UVRange currentFrame;
private UVRange nextFrame;
private int index;
private int currentTicks;
private long nextTime;

public Animation(Texture texture, UVRange uvRange, int gridColumns, int gridRows, int duration, boolean interpolate, Map<Integer, Integer> frameDuration) {
this.texture = texture;
Expand Down Expand Up @@ -70,33 +70,18 @@ public Map<Integer, Integer> getFrameDuration() {
}

public void tick() {
if (this.currentTicks == this.frameDuration.getOrDefault(this.index, this.duration)) {
if (this.nextTime <= Util.getEpochTimeMs()) {
// Current Frame
this.index = (this.index + 1) % (this.gridRows * this.gridColumns);
this.currentFrame = this.calculateNextFrameUVRange(this.index);

// Next Frame
int nextFrameIndex = (this.index + 1) % (this.gridRows * this.gridColumns);
this.nextFrame = this.calculateNextFrameUVRange(nextFrameIndex);

this.currentTicks = 0;
return;
this.nextTime = Util.getEpochTimeMs() + this.frameDuration.getOrDefault((this.index + 1) % (this.gridRows * this.gridColumns), this.duration);
}
this.currentTicks++;
}

public UVRange getNextFrame() {
return this.nextFrame;
}

public UVRange getCurrentFrame() {
return currentFrame;
}

public float interpolationFactor() {
return (float) this.currentTicks / this.frameDuration.getOrDefault(this.index, this.duration);
}

private UVRange calculateNextFrameUVRange(int nextFrameIndex) {
float frameWidth = 1.0F / this.gridColumns;
float frameHeight = 1.0F / this.gridRows;
Expand Down

0 comments on commit f57141a

Please sign in to comment.