|
| 1 | +# 需求 |
| 2 | +## 快捷生成Composition |
| 3 | +1. 使用类似pointsbuilder卡片的方式编辑 |
| 4 | +2. 左边是卡片框,右边是预览框, 代码生成在该页面的第二子页面 |
| 5 | +3. 可选是否实时生成代码, 要有pointsbuilder同款的 设置页面和快捷键页面 |
| 6 | + |
| 7 | +## 项目选项 |
| 8 | +可以修改项目名字 (代表生成的是项目名.kt) |
| 9 | +可以选择类型 |
| 10 | +如果选择ParticleComposition 那么就继承 AutoParticleComposition |
| 11 | +如果选择 SequencedParticleComposition 那么就继承 AutoSequencedParticleComposition |
| 12 | + |
| 13 | +如果是SequencedParticleComposition 可以添加animate |
| 14 | +animate格式如下 |
| 15 | +```kotlin |
| 16 | +init{ |
| 17 | + // 第一个参数数字代表生成的点个数 (只能选择常数整数) |
| 18 | + // 第二个是条件表达式 |
| 19 | + // 条件表达式里的可选变量是 composition的全局变量 + composition默认提供的变量 |
| 20 | + animate.addAnimate(1) { age > 1 } |
| 21 | + .addAnimate(1) { age > 6 } |
| 22 | + .addAnimate(2) { age > 11 } |
| 23 | + .addAnimate(1) { age > 16 } |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +可以设置消散延迟 单位tick: |
| 28 | +```kotlin |
| 29 | +init{ |
| 30 | + setDisabledInterval(常数) |
| 31 | +} |
| 32 | + |
| 33 | +``` |
| 34 | +## 卡片设置 |
| 35 | +卡片是这样设置的 |
| 36 | +1. 绑定一个pointsbuilder 或者point |
| 37 | +2. 设置点 |
| 38 | + |
| 39 | +## 点设置 |
| 40 | +1. 可以设置点类型 ParticleShapeComposition 或者 SequencedParticleShapeComposition 或者 single |
| 41 | +2. 如果是single, 点选项改为如下 |
| 42 | + 1. `addParticleInstanceInit` 对应粒子选项(color,size,age,alpha,textureSheet)等 |
| 43 | + 2. `addParticleControlerInstanceInit` 可以设置粒子controler的tick变化 |
| 44 | + 设置方式如下(kotlin) |
| 45 | + ```kotlin |
| 46 | + data.addParticleControlerInstanceInit{ |
| 47 | + it.addPreTickAction{ |
| 48 | + // 可以获取和修改如下参数 |
| 49 | + // color,size,age,alpha,textureSheet |
| 50 | + } |
| 51 | + } |
| 52 | + ``` |
| 53 | +3. 卡片可以设置如下内容 |
| 54 | + 1. 添加PointsBuilder, 编辑PointsBuilder时,会跳转到pointsbuilder相似的编辑器 |
| 55 | + > 注意 这里的pointsbuilder不是直接跳转到pointsbuilder.html 而是复制pointsbuilder.html相同的页面 |
| 56 | + > |
| 57 | + > 然后加入一些标识(防止和pointsbuilder数据搞混) 然后这个 "builder" 可以直接返回到主页面 |
| 58 | + > |
| 59 | + > 所有的操作手感应该和pointsbuilder完全一致 |
| 60 | + 2. 可以加入绕轴旋转,rotateToWithAngle |
| 61 | + > 如果设置了rotateToWithAngle,那么就要指定to, 可以指定设定的全局变量 |
| 62 | + 3. 可以设置生长动画 |
| 63 | + 4. 如果是SequencedParticleShapeComposition 那么可以设置animate |
| 64 | + |
| 65 | +## 一些补充 |
| 66 | +ControlableParticle对象的实现和 single要输入的ParticleDisplayer.withSingle 要输入的effect我都放在了参考/particle 里面 |
| 67 | +ParticleDisplayer我也放在了参考里面, 只考虑withComposition和withSingle |
| 68 | + |
| 69 | +依旧是 中键旋转,滚轮缩放,右键平移 |
| 70 | +然后左键用来框选预览的点到对应的卡片 |
| 71 | + |
| 72 | + |
| 73 | +# 使用 / 生成代码 举例 |
| 74 | +## 项目设置 |
| 75 | +项目名字: TestComposition |
| 76 | +## 项目卡片设置 |
| 77 | +类型: ParticleComposition |
| 78 | +### display行为 |
| 79 | +#### display action 1 |
| 80 | +rotateToWithAngle卡片 |
| 81 | + |
| 82 | +设定 |
| 83 | + |
| 84 | +rotateSpeed= 10 |
| 85 | + |
| 86 | +to = direction.asRelative() |
| 87 | + |
| 88 | +### 全局变量列表 |
| 89 | +color - Vec3 - Vector3f(0,1,1) |
| 90 | + |
| 91 | +size - Float - 1 |
| 92 | + |
| 93 | +radius - Double - 2 |
| 94 | + |
| 95 | +countPow - int - 4 |
| 96 | + |
| 97 | +direction - Vec3 // to只接收RelativeLocation和Vec3 如果写Vec3 那么上面就要变成xxx.asRelative() |
| 98 | +### 全局非同步常量列表 |
| 99 | +options - Int - 4 |
| 100 | + |
| 101 | +## 卡片编辑 |
| 102 | +### PointsBuilder <- 导入了一个builder(这里比如只有一个ball) |
| 103 | + PointsBuilder的addBall卡片的radius参数设置为 这里的全局radius |
| 104 | +### Data设置 |
| 105 | +Effect -> Single (ControlableEnchantmentEffect) |
| 106 | +### Single设置 |
| 107 | +#### particle init |
| 108 | +currentAge = Random.nextInt(lifetime) // 可以选择定值 也可以选择随机值 |
| 109 | +color = this@TestComposition.color |
| 110 | +#### controler init |
| 111 | +定义局部变量 tick - boolean - true |
| 112 | +##### tick action 1 |
| 113 | +写表达式 |
| 114 | +```javascript |
| 115 | +if (particle.particleAlpha >= 0.9) { |
| 116 | + tick = false |
| 117 | +} |
| 118 | +if (particle.particleAlpha <= 0.2) { |
| 119 | + tick = true |
| 120 | +} |
| 121 | +particle.particleAlpha += tick ? 0.05 : -0.05 |
| 122 | +``` |
| 123 | + |
| 124 | +## 最后生成的代码如下 |
| 125 | +```kotlin |
| 126 | + |
| 127 | +@CooAutoRegister |
| 128 | +class TestComposition(position: Vec3, world: Level? = null) : AutoParticleComposition(position, world) { |
| 129 | + @CodecField |
| 130 | + var color: Vector3f = Vector3f(0f,1f,1f) |
| 131 | + |
| 132 | + @CodecField |
| 133 | + var size: Float = 1f |
| 134 | + |
| 135 | + @CodecField |
| 136 | + var r: Double = 2.0 |
| 137 | + |
| 138 | + @CodecField |
| 139 | + var countPow: Int = 4 |
| 140 | + val options: Int = 4 |
| 141 | + |
| 142 | + override fun getParticles(): Map<CompositionData, RelativeLocation> { |
| 143 | + return PointsBuilder().addBall(r, countPow * options / 2) |
| 144 | + .createWithCompositionData { |
| 145 | + CompositionData().setDisplayerSupplier { |
| 146 | + ParticleDisplayer.withSingle( |
| 147 | + ControlableEnchantmentEffect(it) |
| 148 | + ) |
| 149 | + }.addParticleInstanceInit { |
| 150 | + color = this@TestComposition.color |
| 151 | + size = this@TestComposition.size |
| 152 | + currentAge = Random.nextInt(lifetime) |
| 153 | + }.addParticleControlerInstanceInit { |
| 154 | + var tick = true |
| 155 | + addPreTickAction { // 注意下面是由js翻译过来的 |
| 156 | + if (particle.particleAlpha >= 0.9f) { |
| 157 | + tick = false |
| 158 | + } |
| 159 | + if (particle.particleAlpha <= 0.2f) { |
| 160 | + tick = true |
| 161 | + } |
| 162 | + particle.particleAlpha += if (tick) 0.05f else -0.05f |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + override fun onDisplay() { |
| 169 | + addPreTickAction { // 如果是卡片就直接加, 如果是表达式就翻译成kotlin |
| 170 | + rotateToWithAngle(direction,speed / 180 * PI) |
| 171 | + } |
| 172 | + } |
| 173 | +} |
| 174 | +``` |
0 commit comments