Updates
This commit is contained in:
parent
d3a505bfcc
commit
46363f19c9
26
README.md
26
README.md
|
@ -51,7 +51,8 @@ f 1 2 3
|
|||
|
||||
**Attention :** en OBJ, les indices commencent à partir de 1
|
||||
|
||||
**Attention :** dans notre logiciel, seules les faces triangulaires sont implémentées.
|
||||
**Attention :** dans notre logiciel, seules les faces triangulaires sont
|
||||
implémentées.
|
||||
|
||||
###### Edition d'un sommet
|
||||
|
||||
|
@ -64,6 +65,16 @@ v 0.0 0.0 0.0
|
|||
ev 1 1.0 1.0 1.0
|
||||
```
|
||||
|
||||
###### Translation d'un sommet
|
||||
|
||||
De la même façon, un sommet peut être translaté grâce aux caractères `tv`. Par
|
||||
exemple :
|
||||
|
||||
```
|
||||
v 1.0 2.0 3.0
|
||||
tv 1 1.0 1.0 1.0
|
||||
```
|
||||
|
||||
###### Edition d'une face
|
||||
|
||||
Notre format OBJ permet la modification d'une ancienne face. Pour modifier une
|
||||
|
@ -79,6 +90,19 @@ f 1 2 3
|
|||
ef 1 1 2 4
|
||||
```
|
||||
|
||||
On peut aussi changer un seul sommet d'une face grâce aux caractères `efv`,
|
||||
suivi de l'indice de la face à modifier, de l'indice du sommet à modifier (1, 2
|
||||
ou 3) et de la nouvelle valeur du sommet. Par exemple :
|
||||
|
||||
```
|
||||
v 0.0 0.0 0.0
|
||||
v 1.0 0.0 0.0
|
||||
v 1.0 1.0 0.0
|
||||
v 1.0 1.0 1.0
|
||||
f 1 2 3
|
||||
efv 1 3 4
|
||||
```
|
||||
|
||||
###### Suppression d'une face
|
||||
Notre format OBJ permet la suppression d'une ancienne face. Pour supprimer une
|
||||
face, il suffit d'utiliser les caracètres `df` suivis de l'indice de la face à
|
||||
|
|
39
js/obja.js
39
js/obja.js
|
@ -88,6 +88,23 @@ function parseLine(line) {
|
|||
);
|
||||
return element;
|
||||
|
||||
case "tv":
|
||||
element.type = Element.TranslateVertex;
|
||||
element.id = parseInt(split[1], 10) - 1;
|
||||
element.value = new THREE.Vector3(
|
||||
parseFloat(split[2]),
|
||||
parseFloat(split[3]),
|
||||
parseFloat(split[4]),
|
||||
);
|
||||
return element;
|
||||
|
||||
case "efv":
|
||||
element.type = Element.EditFaceVertex;
|
||||
element.id = parseInt(split[1], 10) - 1;
|
||||
element.oldIndex = parseInt(split[2], 10) - 1;
|
||||
element.value = parseInt(split[3], 10) - 1;
|
||||
return element;
|
||||
|
||||
case "ef":
|
||||
element.type = Element.EditFace;
|
||||
element.id = parseInt(split[1], 10) - 1;
|
||||
|
@ -120,6 +137,8 @@ Element.AddTriangleStrip = "AddTriangleStrip";
|
|||
Element.AddTriangleFan = "AddTriangleFan";
|
||||
Element.EditVertex = "EditVertex";
|
||||
Element.EditFace = "EditFace";
|
||||
Element.EditFaceVertex = "EditFaceVertex";
|
||||
Element.TranslateVertex = "TranslateVertex";
|
||||
Element.DeleteFace = "DeleteFace";
|
||||
|
||||
class Loader {
|
||||
|
@ -244,6 +263,12 @@ class Model extends THREE.Mesh {
|
|||
this.geometry.verticesNeedUpdate = true;
|
||||
break;
|
||||
|
||||
case Element.TranslateVertex:
|
||||
this.checkVertex(element.id);
|
||||
this.geometry.vertices[element.id].add(element.value);
|
||||
this.geometry.verticesNeedUpdate = true;
|
||||
break;
|
||||
|
||||
case Element.AddFace:
|
||||
|
||||
f = element.value;
|
||||
|
@ -297,6 +322,20 @@ class Model extends THREE.Mesh {
|
|||
this.geometry.elementsNeedUpdate = true;
|
||||
break;
|
||||
|
||||
case Element.EditFaceVertex:
|
||||
|
||||
this.checkFaceId(element.id);
|
||||
|
||||
switch (element.oldIndex) {
|
||||
case 0: this.geometry.faces[element.id].a = element.value; break;
|
||||
case 1: this.geometry.faces[element.id].b = element.value; break;
|
||||
case 2: this.geometry.faces[element.id].c = element.value; break;
|
||||
default: this.throwError("Old vertex id in EditFaceVertex must be 1, 2 or 3, but was " + element.oldIndex + 1);
|
||||
}
|
||||
|
||||
this.geometry.elementsNeedUpdate = true;
|
||||
break;
|
||||
|
||||
case Element.DeleteFace:
|
||||
this.geometry.faces[element.id].materialIndex = 1;
|
||||
this.geometry.elementsNeedUpdate = true;
|
||||
|
|
|
@ -88,6 +88,23 @@ function parseLine(line) {
|
|||
);
|
||||
return element;
|
||||
|
||||
case "tv":
|
||||
element.type = Element.TranslateVertex;
|
||||
element.id = parseInt(split[1], 10) - 1;
|
||||
element.value = new THREE.Vector3(
|
||||
parseFloat(split[2]),
|
||||
parseFloat(split[3]),
|
||||
parseFloat(split[4]),
|
||||
);
|
||||
return element;
|
||||
|
||||
case "efv":
|
||||
element.type = Element.EditFaceVertex;
|
||||
element.id = parseInt(split[1], 10) - 1;
|
||||
element.oldIndex = parseInt(split[2], 10) - 1;
|
||||
element.value = parseInt(split[3], 10) - 1;
|
||||
return element;
|
||||
|
||||
case "ef":
|
||||
element.type = Element.EditFace;
|
||||
element.id = parseInt(split[1], 10) - 1;
|
||||
|
@ -120,6 +137,8 @@ Element.AddTriangleStrip = "AddTriangleStrip";
|
|||
Element.AddTriangleFan = "AddTriangleFan";
|
||||
Element.EditVertex = "EditVertex";
|
||||
Element.EditFace = "EditFace";
|
||||
Element.EditFaceVertex = "EditFaceVertex";
|
||||
Element.TranslateVertex = "TranslateVertex";
|
||||
Element.DeleteFace = "DeleteFace";
|
||||
|
||||
class Loader {
|
||||
|
|
20
src/Model.js
20
src/Model.js
|
@ -64,6 +64,12 @@ class Model extends THREE.Mesh {
|
|||
this.geometry.verticesNeedUpdate = true;
|
||||
break;
|
||||
|
||||
case Element.TranslateVertex:
|
||||
this.checkVertex(element.id);
|
||||
this.geometry.vertices[element.id].add(element.value);
|
||||
this.geometry.verticesNeedUpdate = true;
|
||||
break;
|
||||
|
||||
case Element.AddFace:
|
||||
|
||||
f = element.value;
|
||||
|
@ -117,6 +123,20 @@ class Model extends THREE.Mesh {
|
|||
this.geometry.elementsNeedUpdate = true;
|
||||
break;
|
||||
|
||||
case Element.EditFaceVertex:
|
||||
|
||||
this.checkFaceId(element.id);
|
||||
|
||||
switch (element.oldIndex) {
|
||||
case 0: this.geometry.faces[element.id].a = element.value; break;
|
||||
case 1: this.geometry.faces[element.id].b = element.value; break;
|
||||
case 2: this.geometry.faces[element.id].c = element.value; break;
|
||||
default: this.throwError("Old vertex id in EditFaceVertex must be 1, 2 or 3, but was " + element.oldIndex + 1);
|
||||
}
|
||||
|
||||
this.geometry.elementsNeedUpdate = true;
|
||||
break;
|
||||
|
||||
case Element.DeleteFace:
|
||||
this.geometry.faces[element.id].materialIndex = 1;
|
||||
this.geometry.elementsNeedUpdate = true;
|
||||
|
|
Loading…
Reference in New Issue