public createGrid(effectName: string) {
var _maxTicks = 4;
const node = new Node(effectName);
node.parent = this.node;
node.setWorldPosition(v3(0, 0, 0));
const model = node.addComponent(ModelComponent);
const positions = [
0,0,
0,10,
10,10,
10,0,
];
const colors = [];
const indices = [
0,1,2,0,2,3
];
// 直接创建一大块Mesh用的内存,方便后面动态加线
for (let i = 0; i < _maxTicks * _maxTicks; i++) {
// positions.push(i, i);
colors.push(1, 0.5, 1, 1);
}
for (let i = 0; i < positions.length; i += 2) {
// indices.push(i / 2);
}
const primitiveMode = cc.gfx.PrimitiveMode.LINE_LIST;
// 使用二维顶点来节省顶点数据
const attributes = [{
name: cc.gfx.AttributeName.ATTR_POSITION,
format: cc.gfx.Format.RG32F,
}];
const mesh = utils.createMesh({positions, indices, colors, primitiveMode, attributes,});
model.mesh = mesh;
// const effect = cc.EffectAsset.get('builtin-standard'); // this is the EffectAsset resource instance
/*
const mat = new cc.Material();
mat.initialize({ effectName: 'builtin-standard' });
const pass = mat.passes[0];
const hColor = pass.getHandle('mainColor');
const color = new Color(110,0,0,255);
pass.setUniform(hColor, color);
const comp = node.getComponent(MeshRenderer);
comp.setMaterial(mat,0);
*/
// comp.material.setProperty('albedo',new Color(110,255,0,255))
// var property = comp.material.getProperty('albedo')
// console.log(property); //输出为null。证明材质的 setProperty 和 getProperty 都不能修改和获取到材质
const mat = new cc.Material();
mat.initialize({ effectName: 'builtin-standard'});
mat.setProperty('albedo',new Color(0,255,0,255))
const comp2 = node.getComponent(MeshRenderer);
comp2.material = mat;
return model;
}
我试了很多种方式,全都无效,材质一直是白色的。我无语了。这引擎也太难用了吧。