Chugging along

- Fix compile errors with new flywheel light update system.
- Fix compile errors in instance shaders.
- Call Instance#setChanged where needed.
This commit is contained in:
Jozufozu 2024-01-23 13:56:36 -08:00
parent 1c46bc8ae1
commit b6d1f02d6a
38 changed files with 146 additions and 199 deletions

View file

@ -23,7 +23,7 @@ use_parchment = true
# dependency versions
registrate_version = MC1.20-1.3.3
flywheel_minecraft_version = 1.20.1
flywheel_version = 1.0.0-alpha-18
flywheel_version = 1.0.0-alpha-27
jei_minecraft_version = 1.20.1
jei_version = 15.2.0.22
curios_minecraft_version = 1.20.1

View file

@ -20,7 +20,7 @@ import com.simibubi.create.foundation.outliner.Outliner;
import com.simibubi.create.foundation.ponder.element.WorldSectionElement;
import com.simibubi.create.foundation.render.AllInstanceTypes;
import com.simibubi.create.foundation.render.CachedBufferer;
import com.simibubi.create.foundation.render.CreateContexts;
import com.simibubi.create.foundation.render.StitchedSprite;
import com.simibubi.create.foundation.render.SuperByteBufferCache;
import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.ModelSwapper;
@ -64,6 +64,8 @@ public class CreateClient {
modEventBus.addListener(CreateClient::clientInit);
modEventBus.addListener(AllParticleTypes::registerFactories);
modEventBus.addListener(StitchedSprite::onTextureStitchPost);
AllInstanceTypes.init();
MODEL_SWAPPER.registerListeners(modEventBus);

View file

@ -44,6 +44,7 @@ public class HarvesterActorVisual extends ActorVisual {
horizontalAngle = facing.toYRot() + ((facing.getAxis() == Direction.Axis.X) ? 180 : 0);
harvester.setBlockLight(localBlockLight());
harvester.setChanged();
}
protected PartialModel getRollingPartial() {
@ -90,7 +91,8 @@ public class HarvesterActorVisual extends ActorVisual {
.uncenter()
.translate(getRotationOffset())
.rotateXDegrees((float) getRotation())
.translateBack(getRotationOffset());
.translateBack(getRotationOffset())
.setChanged();
}
protected double getRotation() {

View file

@ -24,6 +24,7 @@ public class PSIVisual extends AbstractBlockEntityVisual<PortableStorageInterfac
@Override
public void init(float pt) {
instance.init(isLit());
super.init(pt);
}
@Override

View file

@ -36,13 +36,15 @@ public class RollerActorVisual extends HarvesterActorVisual {
.translate(0, -.25, 17 / 16f)
.rotateXDegrees((float) getRotation())
.translate(0, -.5, .5)
.rotateYDegrees(90);
.rotateYDegrees(90)
.setChanged();
frame.loadIdentity()
.translate(context.localPos)
.center()
.rotateYDegrees(horizontalAngle + 180)
.uncenter();
.uncenter()
.setChanged();
}
@Override

View file

@ -43,7 +43,9 @@ public class BearingVisual<B extends KineticBlockEntity & IBearingBlockEntity> e
topInstance = instancerProvider.instancer(InstanceTypes.ORIENTED, Models.partial(top), RenderStage.AFTER_BLOCK_ENTITIES)
.createInstance();
topInstance.setPosition(getVisualPosition()).setRotation(blockOrientation);
topInstance.setPosition(getVisualPosition())
.setRotation(blockOrientation)
.setChanged();
}
@Override
@ -53,7 +55,8 @@ public class BearingVisual<B extends KineticBlockEntity & IBearingBlockEntity> e
rot.mul(blockOrientation);
topInstance.setRotation(rot);
topInstance.setRotation(rot)
.setChanged();
}
@Override

View file

@ -3,21 +3,15 @@ package com.simibubi.create.content.contraptions.elevator;
import com.jozufozu.flywheel.api.visual.DynamicVisual;
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.jozufozu.flywheel.lib.light.TickingLightListener;
import com.simibubi.create.content.kinetics.base.ShaftVisual;
// TODO
public class ElevatorPulleyVisual extends ShaftVisual<ElevatorPulleyBlockEntity> implements DynamicVisual, TickingLightListener {
public class ElevatorPulleyVisual extends ShaftVisual<ElevatorPulleyBlockEntity> implements DynamicVisual {
public ElevatorPulleyVisual(VisualizationContext context, ElevatorPulleyBlockEntity blockEntity) {
super(context, blockEntity);
}
@Override
public boolean tickLightListener() {
return false;
}
@Override
public void beginFrame(VisualFrameContext ctx) {
}

View file

@ -74,7 +74,8 @@ public class GantryCarriageVisual extends ShaftVisual<GantryCarriageBlockEntity>
.translate(0, -9 / 16f, 0)
.rotateX(-cogAngle)
.translate(0, 9 / 16f, 0)
.uncenter();
.uncenter()
.setChanged();
}
static float getRotationMultiplier(Direction.Axis gantryAxis, Direction facing) {

View file

@ -7,12 +7,10 @@ import com.jozufozu.flywheel.api.instance.Instancer;
import com.jozufozu.flywheel.api.visual.DynamicVisual;
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.jozufozu.flywheel.lib.box.Box;
import com.jozufozu.flywheel.lib.box.MutableBox;
import com.jozufozu.flywheel.lib.instance.OrientedInstance;
import com.jozufozu.flywheel.lib.light.LightPacking;
import com.jozufozu.flywheel.lib.light.LightVolume;
import com.jozufozu.flywheel.lib.light.TickingLightListener;
import com.mojang.math.Axis;
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
import com.simibubi.create.content.kinetics.base.ShaftVisual;
@ -21,11 +19,9 @@ import com.simibubi.create.foundation.render.GroupInstance;
import com.simibubi.create.foundation.render.SelectInstance;
import net.minecraft.core.Direction;
import net.minecraft.core.SectionPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.LightLayer;
public abstract class AbstractPulleyVisual<T extends KineticBlockEntity> extends ShaftVisual<T> implements DynamicVisual, TickingLightListener {
public abstract class AbstractPulleyVisual<T extends KineticBlockEntity> extends ShaftVisual<T> implements DynamicVisual {
final OrientedInstance coil;
final SelectInstance<OrientedInstance> magnet;
@ -47,6 +43,7 @@ public abstract class AbstractPulleyVisual<T extends KineticBlockEntity> extends
coil = getCoilModel().createInstance()
.setPosition(getVisualPosition());
coil.setChanged();
magnet = new SelectInstance<>(this::getMagnetModelIndex);
magnet.addModel(getMagnetModel())
@ -78,7 +75,8 @@ public abstract class AbstractPulleyVisual<T extends KineticBlockEntity> extends
data.setPosition(getVisualPosition())
.nudgePosition(0, -offset, 0)
.setBlockLight(LightPacking.getBlock(packed))
.setSkyLight(LightPacking.getSky(packed));
.setSkyLight(LightPacking.getSky(packed))
.setChanged();
});
halfRope.update()
@ -91,7 +89,8 @@ public abstract class AbstractPulleyVisual<T extends KineticBlockEntity> extends
rope1.setPosition(getVisualPosition())
.nudgePosition(0, -halfRopeNudge, 0)
.setBlockLight(LightPacking.getBlock(packed))
.setSkyLight(LightPacking.getSky(packed));
.setSkyLight(LightPacking.getSky(packed))
.setChanged();
});
if (isRunning()) {
@ -104,7 +103,8 @@ public abstract class AbstractPulleyVisual<T extends KineticBlockEntity> extends
.setPosition(getVisualPosition())
.nudgePosition(0, -offset + i + 1, 0)
.setBlockLight(LightPacking.getBlock(packed))
.setSkyLight(LightPacking.getSky(packed));
.setSkyLight(LightPacking.getSky(packed))
.setChanged();
}
} else {
rope.clear();
@ -114,6 +114,7 @@ public abstract class AbstractPulleyVisual<T extends KineticBlockEntity> extends
@Override
public void updateLight() {
super.updateLight();
light.copyLight(volume);
relight(pos, coil);
}
@ -141,7 +142,6 @@ public abstract class AbstractPulleyVisual<T extends KineticBlockEntity> extends
protected abstract boolean isRunning();
@Override
public boolean tickLightListener() {
if (updateVolume()) {
light.move(volume);
@ -182,17 +182,6 @@ public abstract class AbstractPulleyVisual<T extends KineticBlockEntity> extends
}
}
@Override
public Box getVolume() {
return volume;
}
@Override
public void onLightUpdate(LightLayer type, SectionPos pos) {
super.onLightUpdate(type, pos);
light.onLightUpdate(type, pos);
}
@Override
public void collectCrumblingInstances(Consumer<Instance> consumer) {
super.collectCrumblingInstances(consumer);

View file

@ -3,17 +3,14 @@ package com.simibubi.create.content.contraptions.render;
import com.jozufozu.flywheel.lib.box.Box;
import com.jozufozu.flywheel.lib.box.MutableBox;
import com.jozufozu.flywheel.lib.light.GPULightVolume;
import com.jozufozu.flywheel.lib.light.LightListener;
import com.jozufozu.flywheel.lib.light.LightUpdater;
import com.simibubi.create.content.contraptions.Contraption;
import net.minecraft.core.SectionPos;
import net.minecraft.world.level.LightLayer;
public abstract class ContraptionLighter<C extends Contraption> implements LightListener {
public abstract class ContraptionLighter<C extends Contraption> {
protected final C contraption;
public final GPULightVolume lightVolume;
protected final LightUpdater lightUpdater;
protected final MutableBox bounds;
@ -21,7 +18,6 @@ public abstract class ContraptionLighter<C extends Contraption> implements Light
protected ContraptionLighter(C contraption) {
this.contraption = contraption;
lightUpdater = LightUpdater.get(contraption.entity.level());
bounds = getContraptionBounds();
growBoundsForEdgeData(bounds);
@ -30,18 +26,14 @@ public abstract class ContraptionLighter<C extends Contraption> implements Light
lightVolume.initialize();
scheduleRebuild = true;
lightUpdater.addListener(this);
}
public abstract MutableBox getContraptionBounds();
@Override
public boolean isInvalid() {
return lightVolume.isInvalid();
}
@Override
public void onLightUpdate(LightLayer type, SectionPos pos) {
lightVolume.onLightUpdate(type, pos);
}
@ -51,13 +43,11 @@ public abstract class ContraptionLighter<C extends Contraption> implements Light
bounds.grow(2);
}
@Override
public Box getVolume() {
return bounds;
}
public void delete() {
lightUpdater.removeListener(this);
lightVolume.delete();
}
}

View file

@ -2,16 +2,14 @@ package com.simibubi.create.content.contraptions.render;
import com.jozufozu.flywheel.lib.box.Box;
import com.jozufozu.flywheel.lib.box.MutableBox;
import com.jozufozu.flywheel.lib.light.TickingLightListener;
import com.simibubi.create.content.contraptions.Contraption;
import com.simibubi.create.infrastructure.config.AllConfigs;
public class NonStationaryLighter<C extends Contraption> extends ContraptionLighter<C> implements TickingLightListener {
public class NonStationaryLighter<C extends Contraption> extends ContraptionLighter<C> {
public NonStationaryLighter(C contraption) {
super(contraption);
}
@Override
public boolean tickLightListener() {
if (getVolume().volume() > AllConfigs.client().maxContraptionLightVolume.get())
return false;

View file

@ -38,6 +38,7 @@ public class ToolBoxVisual extends AbstractBlockEntityVisual<ToolboxBlockEntity>
lid = instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.partial(AllPartialModels.TOOLBOX_LIDS.get(blockEntity.getColor())), RenderStage.AFTER_BLOCK_ENTITIES)
.createInstance();
super.init(pt);
}
@Override

View file

@ -67,7 +67,8 @@ public class FluidValveVisual extends ShaftVisual<FluidValveBlockEntity> impleme
.rotateY((float) yRot)
.rotateX((float) xRot)
.rotateY(pointerRotationOffset + pointerRotation)
.uncenter();
.uncenter()
.setChanged();
}
@Override

View file

@ -35,7 +35,8 @@ public abstract class KineticBlockEntityVisual<T extends KineticBlockEntity> ext
instance.setRotationAxis(axis)
.setRotationOffset(getRotationOffset(axis))
.setRotationalSpeed(speed)
.setColor(blockEntity);
.setColor(blockEntity)
.setChanged();
}
protected final RotatingInstance setup(RotatingInstance key) {
@ -55,7 +56,8 @@ public abstract class KineticBlockEntityVisual<T extends KineticBlockEntity> ext
.setRotationalSpeed(speed)
.setRotationOffset(getRotationOffset(axis))
.setColor(blockEntity)
.setPosition(getVisualPosition());
.setPosition(getVisualPosition())
.setChanged();
return key;
}

View file

@ -22,6 +22,7 @@ public class SingleRotatingVisual<T extends KineticBlockEntity> extends KineticB
rotatingModel = instancerProvider.instancer(AllInstanceTypes.ROTATING, model(), RenderStage.AFTER_BLOCK_ENTITIES)
.createInstance();
setup(rotatingModel);
super.init(pt);
}
@Override

View file

@ -14,8 +14,6 @@ import java.util.function.Function;
import com.jozufozu.flywheel.lib.box.Box;
import com.jozufozu.flywheel.lib.box.MutableBox;
import com.jozufozu.flywheel.lib.light.LightListener;
import com.jozufozu.flywheel.lib.light.LightUpdater;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.kinetics.base.IRotate;
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
@ -579,13 +577,11 @@ public class BeltBlockEntity extends KineticBlockEntity {
* Hide this behavior in an inner class to avoid loading LightListener on servers.
*/
@OnlyIn(Dist.CLIENT)
class BeltLighter implements LightListener {
class BeltLighter {
private byte[] light;
public BeltLighter() {
initializeLight();
LightUpdater.get(level)
.addListener(this);
}
/**
@ -605,7 +601,6 @@ public class BeltBlockEntity extends KineticBlockEntity {
return light == null ? 0 : LightTexture.pack(light[segment * 2], light[segment * 2 + 1]);
}
@Override
public Box getVolume() {
BlockPos endPos = BeltHelper.getPositionForOffset(BeltBlockEntity.this, beltLength - 1);
var bb = MutableBox.from(worldPosition, endPos);
@ -613,27 +608,13 @@ public class BeltBlockEntity extends KineticBlockEntity {
return bb;
}
@Override
public boolean isInvalid() {
return remove;
}
@Override
public void onLightUpdate(LightLayer type, SectionPos pos) {
if (remove)
return;
if (level == null)
return;
Box beltVolume = getVolume();
if (beltVolume.intersects(MutableBox.from(pos))) {
if (type == LightLayer.BLOCK)
updateBlockLight();
if (type == LightLayer.SKY)
updateSkyLight();
}
initializeLight();
}
private void initializeLight() {

View file

@ -88,8 +88,9 @@ public class BeltVisual extends KineticBlockEntityVisual<BeltBlockEntity> {
SpriteShiftEntry spriteShiftEntry = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom);
key.setScrollTexture(spriteShiftEntry)
.setColor(blockEntity)
.setRotationalSpeed(getScrollSpeed());
.setColor(blockEntity)
.setRotationalSpeed(getScrollSpeed())
.setChanged();
bottom = false;
}
@ -165,14 +166,17 @@ public class BeltVisual extends KineticBlockEntityVisual<BeltBlockEntity> {
.setColor(blockEntity)
.setPosition(getVisualPosition())
.setBlockLight(level.getBrightness(LightLayer.BLOCK, pos))
.setSkyLight(level.getBrightness(LightLayer.SKY, pos));
.setSkyLight(level.getBrightness(LightLayer.SKY, pos))
.setChanged();
return key;
}
@Override
public void collectCrumblingInstances(Consumer<Instance> consumer) {
consumer.accept(pulleyKey);
if (pulleyKey != null) {
consumer.accept(pulleyKey);
}
keys.forEach(consumer);
}
}

View file

@ -46,11 +46,13 @@ public class HandCrankVisual extends SingleRotatingVisual<HandCrankBlockEntity>
.translate(getVisualPosition())
.center()
.rotate(angle, Direction.get(Direction.AxisDirection.POSITIVE, axis))
.uncenter();
.uncenter()
.setChanged();
}
@Override
public void init(float pt) {
// FIXME: need to call super.super.init here
if (blockEntity.shouldRenderShaft())
super.init(pt);
}

View file

@ -124,8 +124,8 @@ public class DeployerVisual extends ShaftVisual<DeployerBlockEntity> implements
float y = blockPos.getY() + ((float) facingVec.getY()) * distance;
float z = blockPos.getZ() + ((float) facingVec.getZ()) * distance;
pole.setPosition(x, y, z);
hand.setPosition(x, y, z);
pole.setPosition(x, y, z).setChanged();
hand.setPosition(x, y, z).setChanged();
}
static void updateRotation(OrientedInstance pole, OrientedInstance hand, float yRot, float xRot, float zRot) {
@ -133,11 +133,13 @@ public class DeployerVisual extends ShaftVisual<DeployerBlockEntity> implements
Quaternionf q = Axis.YP.rotationDegrees(yRot);
q.mul(Axis.XP.rotationDegrees(xRot));
hand.setRotation(q);
hand.setRotation(q)
.setChanged();
q.mul(Axis.ZP.rotationDegrees(zRot));
pole.setRotation(q);
pole.setRotation(q)
.setChanged();
}
@Override

View file

@ -62,7 +62,8 @@ public class FlywheelVisual extends KineticBlockEntityVisual<FlywheelBlockEntity
.rotate(AngleHelper.rad(angle), Direction.get(Direction.AxisDirection.POSITIVE, axis))
.uncenter();
wheel.setTransform(ms);
wheel.setTransform(ms)
.setChanged();
}
@Override

View file

@ -115,13 +115,13 @@ public abstract class GaugeVisual extends ShaftVisual<GaugeBlockEntity> implemen
msr.pushPose();
rotateToFace(msr);
getSecond().setTransform(ms);
getSecond().setTransform(ms).setChanged();
msr.translate(0, dialPivot, dialPivot)
.rotate((float) (Math.PI / 2 * -progress), Direction.EAST)
.translate(0, -dialPivot, -dialPivot);
getFirst().setTransform(ms);
getFirst().setTransform(ms).setChanged();
msr.popPose();
}

View file

@ -49,7 +49,8 @@ public class GearboxVisual extends KineticBlockEntityVisual<GearboxBlockEntity>
.setRotationOffset(getRotationOffset(axis)).setColor(blockEntity)
.setPosition(getVisualPosition())
.setBlockLight(blockLight)
.setSkyLight(skyLight);
.setSkyLight(skyLight)
.setChanged();
keys.put(direction, key);
}

View file

@ -133,22 +133,26 @@ public class ArmVisual extends SingleRotatingVisual<ArmBlockEntity> implements D
msr.rotateX(180);
ArmRenderer.transformBase(msr, baseAngle);
base.setTransform(msLocal);
base.setTransform(msLocal)
.setChanged();
ArmRenderer.transformLowerArm(msr, lowerArmAngle);
lowerBody.setTransform(msLocal)
.setColor(color);
.setColor(color)
.setChanged();
ArmRenderer.transformUpperArm(msr, upperArmAngle);
upperBody.setTransform(msLocal)
.setColor(color);
.setColor(color)
.setChanged();
ArmRenderer.transformHead(msr, headAngle);
if (ceiling && blockEntity.goggles)
msr.rotateZ(180);
claw.setTransform(msLocal);
claw.setTransform(msLocal)
.setChanged();
if (ceiling && blockEntity.goggles)
msr.rotateZ(180);
@ -166,7 +170,8 @@ public class ArmVisual extends SingleRotatingVisual<ArmBlockEntity> implements D
int flip = index * 2 - 1;
ArmRenderer.transformClawHalf(msr, hasItem, isBlockItem, flip);
clawGrips.get(index)
.setTransform(msLocal);
.setTransform(msLocal)
.setChanged();
msLocal.popPose();
}
}

View file

@ -62,12 +62,14 @@ public class MixerVisual extends EncasedCogVisual implements DynamicVisual {
mixerHead.setPosition(getVisualPosition())
.nudge(0, -renderedHeadOffset, 0)
.setRotationalSpeed(speed * 2);
.setRotationalSpeed(speed * 2)
.setChanged();
}
private void transformPole(float renderedHeadOffset) {
mixerPole.setPosition(getVisualPosition())
.nudgePosition(0, -renderedHeadOffset, 0);
.nudgePosition(0, -renderedHeadOffset, 0)
.setChanged();
}
private float getRenderedHeadOffset() {

View file

@ -45,7 +45,8 @@ public class PressVisual extends ShaftVisual<MechanicalPressBlockEntity> impleme
float renderedHeadOffset = getRenderedHeadOffset(blockEntity);
pressHead.setPosition(getVisualPosition())
.nudgePosition(0, -renderedHeadOffset, 0);
.nudgePosition(0, -renderedHeadOffset, 0)
.setChanged();
}
private float getRenderedHeadOffset(MechanicalPressBlockEntity press) {

View file

@ -31,22 +31,22 @@ public class BracketedKineticBlockEntityVisual extends SingleRotatingVisual<Brac
@Override
public void init(float pt) {
if (ICogWheel.isLargeCog(blockEntity.getBlockState())) {
// Large cogs sometimes have to offset their teeth by 11.25 degrees in order to
// mesh properly
float speed = blockEntity.getSpeed();
Direction.Axis axis = KineticBlockEntityRenderer.getRotationAxisOf(blockEntity);
BlockPos pos = blockEntity.getBlockPos();
float offset = BracketedKineticBlockEntityRenderer.getShaftAngleOffset(axis, pos);
var model = Models.partial(AllPartialModels.COGWHEEL_SHAFT, axis, BracketedKineticBlockEntityVisual::rotateToAxis);
Instancer<RotatingInstance> half = instancerProvider.instancer(AllInstanceTypes.ROTATING, model, RenderStage.AFTER_BLOCK_ENTITIES);
additionalShaft = setup(half.createInstance(), speed);
additionalShaft.setRotationOffset(offset)
.setChanged();
}
super.init(pt);
if (!ICogWheel.isLargeCog(blockEntity.getBlockState()))
return;
// Large cogs sometimes have to offset their teeth by 11.25 degrees in order to
// mesh properly
float speed = blockEntity.getSpeed();
Direction.Axis axis = KineticBlockEntityRenderer.getRotationAxisOf(blockEntity);
BlockPos pos = blockEntity.getBlockPos();
float offset = BracketedKineticBlockEntityRenderer.getShaftAngleOffset(axis, pos);
var model = Models.partial(AllPartialModels.COGWHEEL_SHAFT, axis, BracketedKineticBlockEntityVisual::rotateToAxis);
Instancer<RotatingInstance> half = instancerProvider.instancer(AllInstanceTypes.ROTATING, model, RenderStage.AFTER_BLOCK_ENTITIES);
additionalShaft = setup(half.createInstance(), speed);
additionalShaft.setRotationOffset(offset);
}
@Override
@ -72,7 +72,8 @@ public class BracketedKineticBlockEntityVisual extends SingleRotatingVisual<Brac
super.update(pt);
if (additionalShaft != null) {
updateRotation(additionalShaft);
additionalShaft.setRotationOffset(BracketedKineticBlockEntityRenderer.getShaftAngleOffset(axis, pos));
additionalShaft.setRotationOffset(BracketedKineticBlockEntityRenderer.getShaftAngleOffset(axis, pos))
.setChanged();
}
}

View file

@ -73,6 +73,8 @@ public class EncasedCogVisual extends KineticBlockEntityVisual<KineticBlockEntit
else
rotatingBottomShaft = Optional.of(data);
}
super.init(pt);
}
@Override

View file

@ -64,6 +64,7 @@ public class EjectorVisual extends ShaftVisual<EjectorBlockEntity> implements Dy
float angle = lidProgress * 70;
EjectorRenderer.applyLidAngle(blockEntity, angle, plate.loadIdentity().translate(getVisualPosition()));
plate.setChanged();
}
@Override

View file

@ -32,13 +32,14 @@ public class CarriageContraptionVisual extends AbstractEntityVisual<CarriageCont
public void init(float pt) {
carriage = entity.getCarriage();
if (carriage == null)
return;
if (carriage != null) {
bogeys = carriage.bogeys.mapNotNullWithParam((bogey, manager) -> bogey.getStyle()
.createVisual(bogey, bogey.type.getSize(), manager), visualizationContext);
updateLight();
}
bogeys = carriage.bogeys.mapNotNullWithParam((bogey, manager) ->
bogey.getStyle().createVisual(bogey, bogey.type.getSize(), manager), visualizationContext);
updateLight();
}
super.init(pt);
}
public void setBogeyVisibility(boolean first, boolean visible) {
bogeyHidden.set(first, !visible);
@ -86,7 +87,6 @@ public class CarriageContraptionVisual extends AbstractEntityVisual<CarriageCont
ms.popPose();
}
@Override
public void updateLight() {
if (bogeys == null)
return;

View file

@ -14,7 +14,6 @@ import com.jozufozu.flywheel.lib.box.Box;
import com.jozufozu.flywheel.lib.box.MutableBox;
import com.jozufozu.flywheel.lib.instance.InstanceTypes;
import com.jozufozu.flywheel.lib.instance.TransformedInstance;
import com.jozufozu.flywheel.lib.light.LightUpdater;
import com.jozufozu.flywheel.lib.model.Models;
import com.jozufozu.flywheel.lib.transform.TransformStack;
import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual;
@ -47,11 +46,8 @@ public class TrackVisual extends AbstractBlockEntityVisual<TrackBlockEntity> {
.map(this::createInstance)
.filter(Objects::nonNull)
.toList();
LightUpdater.get(level)
.addListener(this);
}
@Override
public Box getVolume() {
List<BlockPos> out = new ArrayList<>();
out.addAll(blockEntity.connections.keySet());

View file

@ -1,21 +1,16 @@
#define PI 3.1415926538
#include "flywheel:util/quaternion.glsl"
#include "flywheel:util/matrix.glsl"
const float uTime = 0.;
void flw_instanceVertex(in FlwInstance instance) {
flw_vertexPos = vec4(rotateVertexByQuat(flw_vertexPos.xyz - .5, instance.rotation) + instance.pos + .5, 1.);
flw_vertexPos = vec4(rotateByQuaternion(flw_vertexPos.xyz - .5, instance.rotation) + instance.pos + .5, 1.);
flw_vertexNormal = rotateVertexByQuat(flw_vertexNormal, instance.rotation);
flw_vertexNormal = rotateByQuaternion(flw_vertexNormal, instance.rotation);
float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
float scroll = fract(instance.speed * flw_renderTicks / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
flw_vertexTexCoord = flw_vertexTexCoord - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
flw_vertexLight = instance.light;
flw_vertexLight = instance.light / 15.;
#if defined(DEBUG_RAINBOW)
flw_vertexColor = instance.color;

View file

@ -1,15 +1,13 @@
#include "flywheel:util/matrix.glsl"
#include "flywheel:util/quaternion.glsl"
const float uTime = 0.;
void flw_instanceVertex(in FlwInstance instance) {
float degrees = instance.offset + uTime * instance.speed / 20.;
float degrees = instance.offset + flw_renderSeconds * instance.speed;
vec4 kineticRot = quat(instance.axis, degrees);
vec3 rotated = rotateVertexByQuat(flw_vertexPos.xyz - instance.rotationCenter, kineticRot) + instance.rotationCenter;
vec4 kineticRot = quaternionDegrees(instance.axis, degrees);
vec3 rotated = rotateByQuaternion(flw_vertexPos.xyz - instance.rotationCenter, kineticRot) + instance.rotationCenter;
flw_vertexPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
flw_vertexNormal = rotateVertexByQuat(rotateVertexByQuat(flw_vertexNormal, kineticRot), instance.rotation);
flw_vertexLight = instance.light;
flw_vertexPos.xyz = rotateByQuaternion(rotated - .5, instance.rotation) + instance.pos + .5;
flw_vertexNormal = rotateByQuaternion(rotateByQuaternion(flw_vertexNormal, kineticRot), instance.rotation);
flw_vertexLight = instance.light / 15.;
}

View file

@ -1,11 +1,6 @@
#define PI 3.1415926538
#include "flywheel:util/quaternion.glsl"
#include "flywheel:util/matrix.glsl"
const float uTime = 0.;
void flw_transformBoundingSphere(in FlwInstance instance, inout vec3 center, inout float radius) {
// FIXME: this is incorrect, but it compiles
center = rotateVertexByQuat(center - .5, instance.rotation) + instance.pos + .5;
center = rotateByQuaternion(center - .5, instance.rotation) + instance.pos + .5;
}

View file

@ -1,14 +1,11 @@
#include "flywheel:util/matrix.glsl"
#include "flywheel:util/quaternion.glsl"
const float uTime = 0.;
void flw_transformBoundingSphere(in FlwInstance instance, inout vec3 center, inout float radius) {
// FIXME: this is incorrect, but it compiles
float degrees = instance.offset + uTime * instance.speed / 20.;
float degrees = instance.offset + flw_renderSeconds * instance.speed;
vec4 kineticRot = quat(instance.axis, degrees);
vec3 rotated = rotateVertexByQuat(center - instance.rotationCenter, kineticRot) + instance.rotationCenter;
vec4 kineticRot = quaternion(instance.axis, degrees);
vec3 rotated = rotateByQuaternion(center - instance.rotationCenter, kineticRot) + instance.rotationCenter;
center = rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5;
center = rotateByQuaternion(rotated - .5, instance.rotation) + instance.pos + .5;
}

View file

@ -1,14 +1,7 @@
#define PI 3.1415926538
const float uTime = 0.;
#include "flywheel:util/matrix.glsl"
#include "flywheel:util/quaternion.glsl"
float toRad(float degrees) {
return fract(degrees / 360.) * PI * 2.;
}
float getFlapAngle(float flapness, float intensity, float scale) {
float absFlap = abs(flapness);
@ -26,9 +19,9 @@ void flw_transformBoundingSphere(in FlwInstance flap, inout vec3 center, inout f
// FIXME: this is incorrect, but it compiles
float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
vec4 orientation = quaternion(vec3(0., 1., 0.), -flap.horizontalAngle);
vec4 flapRotation = quaternion(vec3(1., 0., 0.), flapAngle);
vec3 rotated = rotateVertexByQuat(center - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
center = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
vec3 rotated = rotateByQuaternion(center - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
center = rotateByQuaternion(rotated - .5, orientation) + flap.instancePos + .5;
}

View file

@ -1,20 +1,15 @@
#define PI 3.1415926538
#include "flywheel:util/matrix.glsl"
const float uTime = 0.;
mat3 kineticRotation(float offset, float speed, vec3 axis) {
float degrees = offset + flw_renderTicks * speed * 3./10.;
mat4 kineticRotation(float offset, float speed, vec3 axis) {
float degrees = offset + uTime * speed * 3./10.;
float angle = fract(degrees / 360.) * PI * 2.;
return rotate(axis, angle);
return rotationDegrees(axis, degrees);
}
void flw_transformBoundingSphere(in FlwInstance instance, inout vec3 center, inout float radius) {
// FIXME: this is incorrect, but it compiles
mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
mat3 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
vec4 worldPos = spin * vec4(center - .5, 1.);
center = worldPos.xyz + instance.pos + .5;
vec3 worldPos = spin * (center - .5);
center = worldPos + instance.pos + .5;
}

View file

@ -1,14 +1,7 @@
#define PI 3.1415926538
const float uTime = 0.;
#include "flywheel:util/matrix.glsl"
#include "flywheel:util/quaternion.glsl"
float toRad(float degrees) {
return fract(degrees / 360.) * PI * 2.;
}
float getFlapAngle(float flapness, float intensity, float scale) {
float absFlap = abs(flapness);
@ -25,13 +18,12 @@ float getFlapAngle(float flapness, float intensity, float scale) {
void flw_instanceVertex(in FlwInstance flap) {
float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
vec4 orientation = quaternion(vec3(0., 1., 0.), -flap.horizontalAngle);
vec4 flapRotation = quaternion(vec3(1., 0., 0.), flapAngle);
vec3 rotated = rotateVertexByQuat(flw_vertexPos.xyz - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
vec3 rotated = rotateByQuaternion(flw_vertexPos.xyz - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
flw_vertexPos = vec4(rotated, 1.);
flw_vertexNormal = rotateVertexByQuat(rotateVertexByQuat(flw_vertexNormal, flapRotation), orientation);
flw_vertexLight = flap.light;
flw_vertexPos.xyz = rotateByQuaternion(rotated - .5, orientation) + flap.instancePos + .5;
flw_vertexNormal = rotateByQuaternion(rotateByQuaternion(flw_vertexNormal, flapRotation), orientation);
flw_vertexLight = flap.light / 15.;
}

View file

@ -1,24 +1,20 @@
#define PI 3.1415926538
#include "flywheel:util/matrix.glsl"
const float uTime = 0.;
mat4 kineticRotation(float offset, float speed, vec3 axis) {
float degrees = offset + uTime * speed * 3./10.;
float angle = fract(degrees / 360.) * PI * 2.;
return rotate(axis, angle);
mat3 kineticRotation(float offset, float speed, vec3 axis) {
float degrees = offset + flw_renderTicks * speed * 3./10.;
return rotationDegrees(axis, degrees);
}
void flw_instanceVertex(in FlwInstance instance) {
mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
mat3 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
vec4 worldPos = spin * vec4(flw_vertexPos.xyz - .5, 1.);
flw_vertexPos = vec4(worldPos.xyz + instance.pos + .5, 1.);
vec3 worldPos = spin * (flw_vertexPos.xyz - .5);
flw_vertexPos.xyz = worldPos.xyz + instance.pos + .5;
flw_vertexNormal = modelToNormal(spin) * flw_vertexNormal;
flw_vertexLight = instance.light;
flw_vertexNormal = spin * flw_vertexNormal;
flw_vertexLight = instance.light / 15.;
#if defined(DEBUG_RAINBOW)
flw_vertexColor = instance.color;