Hi,
I want to create a simple Charackter Editor and I was thinking about doing this by changing the position of the Vertices.
But is this possible? I can’t find documentation about this topic and I have been looking thought the mesh Object, but coud only found the Vertices count (numVertices).
I think the data is stored in the VertexBuffer, but I can’t find it there.
Thanks!
–Update–
I also tried to create a new Mesh. But I keep getting this error in chrome:
[.Offscreen-For-WebGL-000002B279D04ED0]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 0
and firefox:
Error: WebGL: drawElements: Driver rejected indexed draw call, possibly due to out-of-bounds indices.
The code is
var VertexTest = pc.createScript('vertexTest');
var vertexData = {
"position": [new pc.Vec3(0.5, -0.5, 0.5), new pc.Vec3(-0.5, -0.5, 0.5), new pc.Vec3(0.5, 0.5, 0.5), new pc.Vec3(-0.5, 0.5, 0.5), new pc.Vec3(0.5, 0.5, -0.5), new pc.Vec3(-0.5, 0.5, -0.5), new pc.Vec3(0.5, -0.5, -0.5), new pc.Vec3(-0.5, -0.5, -0.5), new pc.Vec3(0.5, 0.5, 0.5), new pc.Vec3(-0.5, 0.5, 0.5), new pc.Vec3(0.5, 0.5, -0.5), new pc.Vec3(-0.5, 0.5, -0.5), new pc.Vec3(0.5, -0.5, -0.5), new pc.Vec3(0.5, -0.5, 0.5), new pc.Vec3(-0.5, -0.5, 0.5), new pc.Vec3(-0.5, -0.5, -0.5), new pc.Vec3(-0.5, -0.5, 0.5), new pc.Vec3(-0.5, 0.5, 0.5), new pc.Vec3(-0.5, 0.5, -0.5), new pc.Vec3(-0.5, -0.5, -0.5), new pc.Vec3(0.5, -0.5, -0.5), new pc.Vec3(0.5, 0.5, -0.5), new pc.Vec3(0.5, 0.5, 0.5), new pc.Vec3(0.5, -0.5, 0.5)],
"normals": [new pc.Vec3(0, 0, 1), new pc.Vec3(0, 0, 1), new pc.Vec3(0, 0, 1), new pc.Vec3(0, 0, 1), new pc.Vec3(0, 1, 0), new pc.Vec3(0, 1, 0), new pc.Vec3(0, 0, -1), new pc.Vec3(0, 0, -1), new pc.Vec3(0, 1, 0), new pc.Vec3(0, 1, 0), new pc.Vec3(0, 0, -1), new pc.Vec3(0, 0, -1), new pc.Vec3(0, -1, 0), new pc.Vec3(0, -1, 0), new pc.Vec3(0, -1, 0), new pc.Vec3(0, -1, 0), new pc.Vec3(-1, 0, 0), new pc.Vec3(-1, 0, 0), new pc.Vec3(-1, 0, 0), new pc.Vec3(-1, 0, 0), new pc.Vec3(1, 0, 0), new pc.Vec3(1, 0, 0), new pc.Vec3(1, 0, 0), new pc.Vec3(1, 0, 0)],
"uvs": [new pc.Vec2(0, 0), new pc.Vec2(1, 0), new pc.Vec2(0, 1), new pc.Vec2(1, 1), new pc.Vec2(0, 1), new pc.Vec2(1, 1), new pc.Vec2(0, 1), new pc.Vec2(1, 1), new pc.Vec2(0, 0), new pc.Vec2(1, 0), new pc.Vec2(0, 0), new pc.Vec2(1, 0), new pc.Vec2(0, 0), new pc.Vec2(0, 1), new pc.Vec2(1, 1), new pc.Vec2(1, 0), new pc.Vec2(0, 0), new pc.Vec2(0, 1), new pc.Vec2(1, 1), new pc.Vec2(1, 0), new pc.Vec2(0, 0), new pc.Vec2(0, 1), new pc.Vec2(1, 1), new pc.Vec2(1, 0)],
"indices": [0, 2, 3, 0, 3, 1, 8, 4, 5, 8, 5, 9, 10, 6, 7, 10, 7, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23]
};
VertexTest.attributes.add('material', {
type: 'asset',
assetType: 'material'
});
VertexTest.prototype.initialize = function() {
var node = new pc.GraphNode();
var material = this.material.resource;
var mesh = pc.createMesh(this.app.graphicsDevice, vertexData.position, {
normals: vertexData.normals,
uvs: vertexData.uvs,
indices: vertexData.indices
});
var meshInstance = new pc.MeshInstance(node, mesh, material);
var model = new pc.Model();
model.graph = node;
model.meshInstances.push(meshInstance);
this.entity.model.model = model;
console.log(model);
};
Thanks a lot!