-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpc_procedural_mesh.js
52 lines (48 loc) · 1.43 KB
/
pc_procedural_mesh.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
mesh_from_buffers = function(indices, positions, uvs) {
var normals = pc.calculateNormals(positions, indices);
var options = {
normals: normals,
uvs: uvs,
uvs1: uvs,
indices: indices
};
options.tangents = pc.calculateTangents(positions, normals, uvs, indices);
var mesh = pc.createMesh(app.graphicsDevice, positions, options);
return mesh;
}
/*
pc.calculateTangents(maila.vertices, maila.normals, maila.uvs, maila.triangles)
calculated tangents differ alot from exported ones, i dont know which are "better" yet
*/
mesh_from_buffers_full = function(indices, positions, uvs, normals, tangents) {
if (normals == undefined)
normals = pc.calculateNormals(positions, indices)
if (tangents == undefined)
tangents = pc.calculateTangents(positions, normals, uvs, indices)
var options = {
normals: normals,
uvs: uvs,
uvs1: uvs,
indices: indices,
tangents: tangents
};
var mesh = pc.createMesh(app.graphicsDevice, positions, options);
return mesh;
}
entity_from_mesh_layerid_material = function(mesh, layer_id, material) {
var entity = new pc.Entity();
entity.addComponent("model", {
layers: [layer_id]
})
var model = model_from_mesh(mesh, material)
entity.model.model = model;
return entity;
}
model_from_mesh = function(mesh, material) {
var model = new pc.Model()
var node = new pc.GraphNode();
model.graph = node
model.meshInstances = [new pc.MeshInstance(node, mesh, material)];
model.material = material;
return model;
}