Skip to content

Commit

Permalink
Update js-example-eyecandy.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 authored Jul 24, 2024
1 parent f55ecfe commit 04251ba
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions docs/js-example-eyecandy.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
# 装饰物件渲染案例

以下代码实现了在游戏中加载模型,并为每个物件独立的进行随机更换贴图和缩放模型,最终在绘制该模型的功能。

```javascript

//存储更换的贴图
var textures = [];
textures.push(Resources.idRelative("texture1.png"));
textures.push(Resources.idRelative("texture2.png"));
textures.push(Resources.idRelative("texture3.png"));
textures.push(Resources.idRelative("texture4.png"));

function create(ctx, state, block) {
// 注意在函数中Resources.idRelative(resources: String)不可用 只能使用 Resources.id(resources: String)
let rawModel = ModelManager.loadRawModel(Resources.manager(), Resources.id("mtrsteamloco:eyecandies/block.obj"), null);
//随机获得0-3的索引
let textureIndex = Math.floor(Math.random()*textures.length);
//替换模型的贴图
rawModel.replaceAllTexture(textures[textureIndex]);
//随机缩放
let scale = Math.random()*0.4 + 0.8;
//应用随机缩放
rawModel.applyScale(scale,scale,scale);
//创建动态模型
state.dynamicModelHolder= new DynamicModelHolder();
state.dynamicModelHolder.uploadLater(rawModel);
//注意这里DynamicModelHolder.getUploadedModel()不可用,要对它的ModelCluster进行操作需要等下一次主程序调用
}

function render(ctx, state, block) {
//绘制模型
ctx.drawModel(state.dynamicModelHolder, null);
}

```
(施工中)

0 comments on commit 04251ba

Please sign in to comment.