有没有办法在现有Mesh的面上更改materialIndex?" 如何更新事物"文档中未对此进行讨论,因此我不确定是否可行.我正在使用WebGLRenderer上下文.
这基本上就是我要做的事情:
// Make a mesh with two materials
var texture = THREE.ImageUtils.loadTexture(IMAGE_URL);
var geometry = new THREE.Geometry();
geometry.materials.push(new THREE.MeshBasicMaterial({ wireframe: true, vertexColors: THREE.FaceColors}));
geometry.materials.push(new THREE.MeshBasicMaterial({ map: texture, overdraw: true}));
whatever.forEach(function(w, i) {
geometry.vertices.push(makeVerts(w));
var materialIndex = 0;
var color = new THREE.Color(i);
geometry.faces.push(new THREE.Face4(i*4+0, i*4+1, i*4+2, i*4+3,
null, color, materialIndex));
});
var mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial());
scene.add(mesh)
// Later on, change some faces to a different material
geometry.faces.filter(someFilter).forEach(function(face) {
face.color = someOtherColor;
face.materialIndex = 1; …Run Code Online (Sandbox Code Playgroud) 从可变bytearray类型转换为非可变bytes类型会产生副本吗?是否有与之相关的成本,或者解释器是否将其视为不可变的字节序列,就像在C++中转换char*为a 一样const char* const?
ba = bytearray()
ba.extend("some big long string".encode('utf-8'))
# Is this conversion free or expensive?
write_bytes(bytes(ba))
Run Code Online (Sandbox Code Playgroud)
这是不同的Python 3,bytes它自己的类型和Python 2.7,bytes它只是一个别名str?