mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-02-17 16:20:13 +08:00
Merge branch 'three-no-geo' into next
This commit is contained in:
commit
2fd97375d4
@ -308,8 +308,6 @@ class refModel {
|
||||
var mat = new THREE.MeshLambertMaterial({
|
||||
color: 0xffffff,
|
||||
map: tex,
|
||||
transparent: true,
|
||||
vertexColors: THREE.FaceColors,
|
||||
side: 2,
|
||||
alphaTest: 0.05
|
||||
});
|
||||
@ -318,7 +316,7 @@ class refModel {
|
||||
scope.material = mat
|
||||
|
||||
things.forEach(function(s) {
|
||||
var mesh = new THREE.Mesh(new THREE.CubeGeometry(s.size[0], s.size[1], s.size[2]), mat )
|
||||
var mesh = new THREE.Mesh(new THREE.BoxGeometry(s.size[0], s.size[1], s.size[2]), mat)
|
||||
if (s.origin) {
|
||||
mesh.position.set(s.origin[0], s.origin[1], s.origin[2])
|
||||
mesh.geometry.translate(-s.origin[0], -s.origin[1], -s.origin[2])
|
||||
@ -331,6 +329,25 @@ class refModel {
|
||||
mesh.r_model = s.model
|
||||
}
|
||||
|
||||
function getUVArray(face) {
|
||||
var arr = [
|
||||
[face.uv[0]/16, 1-(face.uv[1]/16)],
|
||||
[face.uv[2]/16, 1-(face.uv[1]/16)],
|
||||
[face.uv[0]/16, 1-(face.uv[3]/16)],
|
||||
[face.uv[2]/16, 1-(face.uv[3]/16)]
|
||||
]
|
||||
var rot = (face.rotation+0)
|
||||
while (rot > 0) {
|
||||
let a = arr[0];
|
||||
arr[0] = arr[2];
|
||||
arr[2] = arr[3];
|
||||
arr[3] = arr[1];
|
||||
arr[1] = a;
|
||||
rot = rot-90;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
for (var face in s) {
|
||||
if (s.hasOwnProperty(face) && s[face].uv !== undefined) {
|
||||
var fIndex = 0;
|
||||
@ -342,11 +359,14 @@ class refModel {
|
||||
case 'up': fIndex = 4; break;
|
||||
case 'down': fIndex = 6; break;
|
||||
}
|
||||
mesh.geometry.faceVertexUvs[0][fIndex] = [ getUVArray(s[face])[0], getUVArray(s[face])[1], getUVArray(s[face])[3] ];
|
||||
mesh.geometry.faceVertexUvs[0][fIndex+1] = [ getUVArray(s[face])[1], getUVArray(s[face])[2], getUVArray(s[face])[3] ];
|
||||
let uv_array = getUVArray(s[face]);
|
||||
mesh.geometry.attributes.uv.array.set(uv_array[0], fIndex*4 + 0); //0,1
|
||||
mesh.geometry.attributes.uv.array.set(uv_array[1], fIndex*4 + 2); //1,1
|
||||
mesh.geometry.attributes.uv.array.set(uv_array[2], fIndex*4 + 4); //0,0
|
||||
mesh.geometry.attributes.uv.array.set(uv_array[3], fIndex*4 + 6); //1,0
|
||||
mesh.geometry.attributes.uv.needsUpdate = true;
|
||||
}
|
||||
}
|
||||
mesh.geometry.elementsNeedUpdate = true;
|
||||
|
||||
scope.model.add(mesh);
|
||||
})
|
||||
|
@ -28,12 +28,16 @@ var codec = new Codec('obj', {
|
||||
https://github.com/mrdoob/three.js/blob/dev/examples/js/exporters/OBJExporter.js
|
||||
*/
|
||||
|
||||
var output = '# Made in Blockbench '+appVersion+'\n';
|
||||
var materials = {};
|
||||
|
||||
var indexVertex = 0;
|
||||
var indexVertexUvs = 0;
|
||||
var indexNormals = 0;
|
||||
let materials = {};
|
||||
let output = '# Made in Blockbench '+appVersion+'\n';
|
||||
let indexVertex = 0;
|
||||
let indexVertexUvs = 0;
|
||||
let indexNormals = 0;
|
||||
const vertex = new THREE.Vector3();
|
||||
const color = new THREE.Color();
|
||||
const normal = new THREE.Vector3();
|
||||
const uv = new THREE.Vector2();
|
||||
const face = [];
|
||||
|
||||
output += 'mtllib ' + (options.mtl_name||'materials.mtl') +'\n';
|
||||
|
||||
@ -47,99 +51,123 @@ var codec = new Codec('obj', {
|
||||
|
||||
var geometry = mesh.geometry;
|
||||
var element = OutlinerNode.uuids[mesh.name];
|
||||
const normalMatrixWorld = new THREE.Matrix3();
|
||||
|
||||
if (!element) return;
|
||||
if (element.export === false) return;
|
||||
|
||||
output += 'o ' + element.name + '\n';
|
||||
|
||||
var vertices = geometry.vertices;
|
||||
const vertices = geometry.getAttribute( 'position' );
|
||||
const normals = geometry.getAttribute( 'normal' );
|
||||
const uvs = geometry.getAttribute( 'uv' );
|
||||
const indices = geometry.getIndex(); // name of the mesh object
|
||||
|
||||
for ( var i = 0, l = vertices.length; i < l; i ++ ) {
|
||||
output += 'o ' + mesh.name + '\n'; // name of the mesh material
|
||||
|
||||
var vertex = vertices[ i ].clone();
|
||||
vertex.applyMatrix4( mesh.matrixWorld );
|
||||
if ( mesh.material && mesh.material.name ) {
|
||||
|
||||
output += 'v ' + (vertex.x*scale) + ' ' + (vertex.y*scale) + ' ' + (vertex.z*scale) + '\n';
|
||||
nbVertex ++;
|
||||
}
|
||||
// uvs
|
||||
var faces = geometry.faces;
|
||||
var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
|
||||
var hasVertexUvs = faces.length === faceVertexUvs.length;
|
||||
output += 'usemtl ' + mesh.material.name + '\n';
|
||||
|
||||
if ( hasVertexUvs ) {
|
||||
} // vertices
|
||||
|
||||
for ( var i = 0, l = faceVertexUvs.length; i < l; i ++ ) {
|
||||
|
||||
var vertexUvs = faceVertexUvs[ i ];
|
||||
if ( vertices !== undefined ) {
|
||||
|
||||
for ( var j = 0, jl = vertexUvs.length; j < jl; j ++ ) {
|
||||
for ( let i = 0, l = vertices.count; i < l; i ++, nbVertex ++ ) {
|
||||
|
||||
vertex.x = vertices.getX( i );
|
||||
vertex.y = vertices.getY( i );
|
||||
vertex.z = vertices.getZ( i ); // transform the vertex to world space
|
||||
|
||||
vertex.applyMatrix4( mesh.matrixWorld ); // transform the vertex to export format
|
||||
|
||||
output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n';
|
||||
|
||||
var uv = vertexUvs[ j ];
|
||||
output += 'vt ' + uv.x + ' ' + uv.y + '\n';
|
||||
nbVertexUvs ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// normals
|
||||
} // uvs
|
||||
|
||||
var normalMatrixWorld = new THREE.Matrix3();
|
||||
normalMatrixWorld.getNormalMatrix( mesh.matrixWorld );
|
||||
|
||||
for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
||||
if ( uvs !== undefined ) {
|
||||
|
||||
var face = faces[ i ];
|
||||
var vertexNormals = face.vertexNormals;
|
||||
for ( let i = 0, l = uvs.count; i < l; i ++, nbVertexUvs ++ ) {
|
||||
|
||||
if ( vertexNormals.length === 3 ) {
|
||||
uv.x = uvs.getX( i );
|
||||
uv.y = uvs.getY( i ); // transform the uv to export format
|
||||
|
||||
for ( var j = 0, jl = vertexNormals.length; j < jl; j ++ ) {
|
||||
output += 'vt ' + uv.x + ' ' + uv.y + '\n';
|
||||
|
||||
var normal = vertexNormals[ j ].clone();
|
||||
normal.applyMatrix3( normalMatrixWorld );
|
||||
|
||||
output += 'vn ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n';
|
||||
|
||||
nbNormals ++;
|
||||
}
|
||||
} else {
|
||||
|
||||
var normal = face.normal.clone();
|
||||
normal.applyMatrix3( normalMatrixWorld );
|
||||
|
||||
for ( var j = 0; j < 3; j ++ ) {
|
||||
|
||||
output += 'vn ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n';
|
||||
nbNormals ++;
|
||||
}
|
||||
}
|
||||
|
||||
} // normals
|
||||
|
||||
|
||||
if ( normals !== undefined ) {
|
||||
|
||||
normalMatrixWorld.getNormalMatrix( mesh.matrixWorld );
|
||||
|
||||
for ( let i = 0, l = normals.count; i < l; i ++, nbNormals ++ ) {
|
||||
|
||||
normal.x = normals.getX( i );
|
||||
normal.y = normals.getY( i );
|
||||
normal.z = normals.getZ( i ); // transform the normal to world space
|
||||
|
||||
normal.applyMatrix3( normalMatrixWorld ).normalize(); // transform the normal to export format
|
||||
|
||||
output += 'vn ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// material
|
||||
for (var face in element.faces) {
|
||||
var tex = element.faces[face].getTexture()
|
||||
for (let key in element.faces) {
|
||||
let tex = element.faces[key].getTexture()
|
||||
if (tex && tex.uuid && !materials[tex.id]) {
|
||||
materials[tex.id] = tex
|
||||
}
|
||||
}
|
||||
|
||||
// faces
|
||||
if ( indices !== null ) {
|
||||
|
||||
for ( var i = 0, j = 1, l = faces.length; i < l; i ++, j += 3 ) {
|
||||
for ( let i = 0, l = indices.count; i < l; i += 3 ) {
|
||||
|
||||
var face = faces[ i ];
|
||||
var f_mat = getMtlFace(element, face.materialIndex)
|
||||
if (f_mat) {
|
||||
let f_mat = getMtlFace(element, geometry.groups[ Math.floor(i / 6) ].materialIndex)
|
||||
if (f_mat) {
|
||||
|
||||
if (i % 2 === 0) {
|
||||
output += f_mat
|
||||
if (i % 2 === 0) {
|
||||
output += f_mat
|
||||
}
|
||||
|
||||
for ( let m = 0; m < 3; m ++ ) {
|
||||
|
||||
const j = indices.getX( i + m ) + 1;
|
||||
face[ m ] = indexVertex + j + ( normals || uvs ? '/' + ( uvs ? indexVertexUvs + j : '' ) + ( normals ? '/' + ( indexNormals + j ) : '' ) : '' );
|
||||
|
||||
} // transform the face to export format
|
||||
|
||||
|
||||
output += 'f ' + face.join( ' ' ) + '\n';
|
||||
}
|
||||
output += 'f ';
|
||||
output += ( indexVertex + face.a + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j ) : '' ) + '/' + ( indexNormals + j ) + ' ';
|
||||
output += ( indexVertex + face.b + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + 1 ) : '' ) + '/' + ( indexNormals + j + 1 ) + ' ';
|
||||
output += ( indexVertex + face.c + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + 2 ) : '' ) + '/' + ( indexNormals + j + 2 ) + '\n';
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for ( let i = 0, l = vertices.count; i < l; i += 3 ) {
|
||||
|
||||
for ( let m = 0; m < 3; m ++ ) {
|
||||
|
||||
const j = i + m + 1;
|
||||
face[ m ] = indexVertex + j + ( normals || uvs ? '/' + ( uvs ? indexVertexUvs + j : '' ) + ( normals ? '/' + ( indexNormals + j ) : '' ) : '' );
|
||||
|
||||
} // transform the face to export format
|
||||
|
||||
|
||||
output += 'f ' + face.join( ' ' ) + '\n';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// update index
|
||||
|
@ -521,7 +521,7 @@ class Cube extends OutlinerElement {
|
||||
var dq = new THREE.Vector3().copy(shift)
|
||||
dq.applyQuaternion(q)
|
||||
shift.sub(dq)
|
||||
shift.applyQuaternion(q.inverse())
|
||||
shift.applyQuaternion(q.invert())
|
||||
|
||||
this.moveVector(shift, null, update)
|
||||
|
||||
|
@ -288,7 +288,7 @@ class Group extends OutlinerNode {
|
||||
var dq = new THREE.Vector3().copy(shift)
|
||||
dq.applyQuaternion(q)
|
||||
shift.sub(dq)
|
||||
shift.applyQuaternion(q.inverse())
|
||||
shift.applyQuaternion(q.invert())
|
||||
this.origin.V3_set(origin);
|
||||
|
||||
function iterateChild(obj) {
|
||||
|
@ -92,7 +92,7 @@ THREE.OrbitControls = function ( object, preview ) {
|
||||
|
||||
// so camera.up is the orbit axis
|
||||
var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
|
||||
var quatInverse = quat.clone().inverse();
|
||||
var quatInverse = quat.clone().invert();
|
||||
|
||||
var lastPosition = new THREE.Vector3();
|
||||
var lastQuaternion = new THREE.Quaternion();
|
||||
|
@ -18,34 +18,6 @@ function getRescalingFactor(angle) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
function getUVArray(side, frame, stretch) {
|
||||
//Used by display preview models
|
||||
if (stretch === undefined) {
|
||||
stretch = -1
|
||||
} else {
|
||||
stretch = stretch*(-1)
|
||||
}
|
||||
var arr = [
|
||||
new THREE.Vector2(side.uv[0]/16, (side.uv[1]/16)/stretch+1), //0,1
|
||||
new THREE.Vector2(side.uv[0]/16, (side.uv[3]/16)/stretch+1), //0,0
|
||||
new THREE.Vector2(side.uv[2]/16, (side.uv[3]/16)/stretch+1), //1,0
|
||||
new THREE.Vector2(side.uv[2]/16, (side.uv[1]/16)/stretch+1) //1,1
|
||||
]
|
||||
if (frame > 0 && stretch !== -1) {
|
||||
//Animate
|
||||
var offset = (1/stretch) * frame
|
||||
arr[0].y += offset
|
||||
arr[1].y += offset
|
||||
arr[2].y += offset
|
||||
arr[3].y += offset
|
||||
}
|
||||
var rot = (side.rotation+0)
|
||||
while (rot > 0) {
|
||||
arr.push(arr.shift())
|
||||
rot = rot-90;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
const Canvas = {
|
||||
outlineMaterial: new THREE.LineBasicMaterial({
|
||||
linewidth: 2,
|
||||
@ -58,6 +30,8 @@ const Canvas = {
|
||||
}),
|
||||
solidMaterial: (function() {
|
||||
var vertShader = `
|
||||
attribute float highlight;
|
||||
|
||||
uniform bool SHADE;
|
||||
|
||||
varying float light;
|
||||
@ -82,7 +56,7 @@ const Canvas = {
|
||||
|
||||
}
|
||||
|
||||
if (color.b > 1.1) {
|
||||
if (highlight == 1.0) {
|
||||
lift = 0.12;
|
||||
} else {
|
||||
lift = 0.0;
|
||||
@ -123,7 +97,6 @@ const Canvas = {
|
||||
},
|
||||
vertexShader: vertShader,
|
||||
fragmentShader: fragShader,
|
||||
vertexColors: THREE.FaceColors,
|
||||
side: THREE.DoubleSide
|
||||
});
|
||||
})(),
|
||||
@ -520,14 +493,16 @@ const Canvas = {
|
||||
//Object handlers
|
||||
addCube(obj) {
|
||||
//This does NOT remove old cubes
|
||||
var mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1))
|
||||
var mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), emptyMaterials[0]);
|
||||
Project.nodes_3d[obj.uuid] = mesh;
|
||||
mesh.name = obj.uuid;
|
||||
mesh.type = 'cube';
|
||||
mesh.isElement = true;
|
||||
|
||||
Canvas.adaptObjectFaces(obj, mesh)
|
||||
mesh.geometry.setAttribute('highlight', new THREE.BufferAttribute(new Uint8Array(24).fill(1), 1));
|
||||
|
||||
Canvas.adaptObjectPosition(obj, mesh)
|
||||
Canvas.adaptObjectFaces(obj, mesh)
|
||||
|
||||
if (Prop.view_mode === 'textured') {
|
||||
Canvas.updateUV(obj);
|
||||
@ -559,9 +534,8 @@ const Canvas = {
|
||||
to[i] += 0.001
|
||||
}
|
||||
})
|
||||
mesh.geometry.from(from)
|
||||
mesh.geometry.to(to)
|
||||
|
||||
mesh.geometry.setShape(from, to)
|
||||
Canvas.getOutlineMesh(mesh, mesh.outline)
|
||||
mesh.geometry.computeBoundingBox()
|
||||
mesh.geometry.computeBoundingSphere()
|
||||
}
|
||||
@ -604,29 +578,30 @@ const Canvas = {
|
||||
adaptObjectFaceGeo(cube) {
|
||||
let {mesh} = cube;
|
||||
let {geometry} = mesh;
|
||||
if (!geometry.all_faces) geometry.all_faces = geometry.faces.slice();
|
||||
geometry.faces.empty()
|
||||
if (!geometry.all_faces) geometry.all_faces = geometry.groups.slice();
|
||||
geometry.groups.empty()
|
||||
|
||||
geometry.all_faces.forEach(face => {
|
||||
let bb_face = cube.faces[Canvas.face_order[face.materialIndex]];
|
||||
|
||||
if (bb_face && bb_face.texture === null && geometry.faces.includes(face)) {
|
||||
geometry.faces.remove(face);
|
||||
if (bb_face && bb_face.texture === null && geometry.groups.includes(face)) {
|
||||
geometry.groups.remove(face);
|
||||
} else
|
||||
if (bb_face && bb_face.texture !== null && !geometry.faces.includes(face)) {
|
||||
geometry.faces.push(face);
|
||||
if (bb_face && bb_face.texture !== null && !geometry.groups.includes(face)) {
|
||||
geometry.groups.push(face);
|
||||
}
|
||||
})
|
||||
if (geometry.faces.length == 0) {
|
||||
// Keek down face if no faces enabled
|
||||
geometry.faces.push(geometry.all_faces[6], geometry.all_faces[7]);
|
||||
if (geometry.groups.length == 0) {
|
||||
// Keep down face if no faces enabled
|
||||
geometry.groups.push(geometry.all_faces[6], geometry.all_faces[7]);
|
||||
}
|
||||
geometry.elementsNeedUpdate = true;
|
||||
},
|
||||
getLayeredMaterial(layers) {
|
||||
if (Canvas.layered_material && !layers) return Canvas.layered_material;
|
||||
// https://codepen.io/Fyrestar/pen/YmpXYr
|
||||
var vertShader = `
|
||||
attribute float highlight;
|
||||
|
||||
uniform bool SHADE;
|
||||
|
||||
varying vec2 vUv;
|
||||
@ -654,7 +629,7 @@ const Canvas = {
|
||||
|
||||
}
|
||||
|
||||
if (color.b > 1.1) {
|
||||
if (highlight == 1.0) {
|
||||
lift = 0.1;
|
||||
} else {
|
||||
lift = 0.0;
|
||||
@ -714,7 +689,6 @@ const Canvas = {
|
||||
vertexShader: vertShader,
|
||||
fragmentShader: fragShader,
|
||||
side: Canvas.getRenderSide(),
|
||||
vertexColors: THREE.FaceColors,
|
||||
transparent: true
|
||||
});
|
||||
Canvas.layered_material = material_shh;
|
||||
@ -769,7 +743,6 @@ const Canvas = {
|
||||
if (Prop.view_mode !== 'textured') return;
|
||||
var mesh = cube.mesh
|
||||
if (mesh === undefined || !mesh.geometry) return;
|
||||
mesh.geometry.faceVertexUvs[0] = [];
|
||||
|
||||
if (Project.box_uv) {
|
||||
|
||||
@ -803,8 +776,7 @@ const Canvas = {
|
||||
face_list[1].size = p.size.slice()
|
||||
|
||||
}
|
||||
let fIndex = 0;
|
||||
face_list.forEach(function(f) {
|
||||
face_list.forEach(function(f, fIndex) {
|
||||
|
||||
if (cube.faces[f.face].texture == null) return;
|
||||
|
||||
@ -843,18 +815,15 @@ const Canvas = {
|
||||
}
|
||||
}
|
||||
|
||||
Canvas.updateUVFace(mesh.geometry.faceVertexUvs[0], fIndex, {uv: uv}, frame, stretch)
|
||||
|
||||
fIndex += 2;
|
||||
Canvas.updateUVFace(mesh.geometry.attributes.uv, fIndex, {uv: uv}, frame, stretch)
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
var stretch = 1
|
||||
var frame = 0
|
||||
let fIndex = 0
|
||||
|
||||
Canvas.face_order.forEach(face => {
|
||||
Canvas.face_order.forEach((face, fIndex) => {
|
||||
|
||||
if (cube.faces[face].texture == null) return;
|
||||
|
||||
@ -867,67 +836,51 @@ const Canvas = {
|
||||
frame = tex.currentFrame
|
||||
}
|
||||
}
|
||||
Canvas.updateUVFace(mesh.geometry.faceVertexUvs[0], fIndex, cube.faces[face], frame, stretch)
|
||||
fIndex += 2;
|
||||
Canvas.updateUVFace(mesh.geometry.attributes.uv, fIndex, cube.faces[face], frame, stretch)
|
||||
})
|
||||
|
||||
}
|
||||
mesh.geometry.elementsNeedUpdate = true;
|
||||
mesh.geometry.attributes.uv.needsUpdate = true;
|
||||
return mesh.geometry
|
||||
},
|
||||
updateUVFace(vertex_uvs, index, face, frame = 0, stretch = 1) {
|
||||
stretch *= -1
|
||||
|
||||
if (!vertex_uvs[index]) vertex_uvs[index] = [];
|
||||
if (!vertex_uvs[index+1]) vertex_uvs[index+1] = [];
|
||||
var arr = [
|
||||
vertex_uvs[index][0],
|
||||
vertex_uvs[index][1],
|
||||
vertex_uvs[index+1][1],
|
||||
vertex_uvs[index+1][2],
|
||||
]
|
||||
for (var i = 0; i < 4; i++) {
|
||||
if (arr[i] === undefined) {
|
||||
arr[i] = new THREE.Vector2()
|
||||
}
|
||||
}
|
||||
stretch *= -1;
|
||||
var pw = Project.texture_width;
|
||||
var ph = Project.texture_height;
|
||||
|
||||
arr[0].set(face.uv[0]/pw, (face.uv[1]/ph)/stretch+1), //0,1
|
||||
arr[1].set(face.uv[0]/pw, (face.uv[3]/ph)/stretch+1), //0,0
|
||||
arr[2].set(face.uv[2]/pw, (face.uv[3]/ph)/stretch+1), //1,0
|
||||
arr[3].set(face.uv[2]/pw, (face.uv[1]/ph)/stretch+1) //1,1
|
||||
|
||||
var arr = [
|
||||
[face.uv[0]/pw, (face.uv[1]/ph)/stretch+1],
|
||||
[face.uv[2]/pw, (face.uv[1]/ph)/stretch+1],
|
||||
[face.uv[0]/pw, (face.uv[3]/ph)/stretch+1],
|
||||
[face.uv[2]/pw, (face.uv[3]/ph)/stretch+1],
|
||||
]
|
||||
if (frame > 0 && stretch !== -1) {
|
||||
//Animate
|
||||
var offset = (1/stretch) * frame
|
||||
arr[0].y += offset
|
||||
arr[1].y += offset
|
||||
arr[2].y += offset
|
||||
arr[3].y += offset
|
||||
arr[0][1] += offset
|
||||
arr[1][1] += offset
|
||||
arr[2][1] += offset
|
||||
arr[3][1] += offset
|
||||
}
|
||||
var rot = (face.rotation+0)
|
||||
while (rot > 0) {
|
||||
arr.push(arr.shift())
|
||||
let a = arr[0];
|
||||
arr[0] = arr[2];
|
||||
arr[2] = arr[3];
|
||||
arr[3] = arr[1];
|
||||
arr[1] = a;
|
||||
rot = rot-90;
|
||||
}
|
||||
vertex_uvs[index] = [
|
||||
arr[0],
|
||||
arr[1],
|
||||
arr[3]
|
||||
];
|
||||
vertex_uvs[index+1] = [
|
||||
arr[1],
|
||||
arr[2],
|
||||
arr[3]
|
||||
];
|
||||
vertex_uvs.array.set(arr[0], index*8 + 0); //0,1
|
||||
vertex_uvs.array.set(arr[1], index*8 + 2); //1,1
|
||||
vertex_uvs.array.set(arr[2], index*8 + 4); //0,0
|
||||
vertex_uvs.array.set(arr[3], index*8 + 6); //1,0
|
||||
},
|
||||
//Outline
|
||||
getOutlineMesh(mesh) {
|
||||
var vs = mesh.geometry.vertices
|
||||
var geometry = new THREE.Geometry()
|
||||
geometry.vertices = [
|
||||
getOutlineMesh(mesh, line) {
|
||||
var vs = [0,1,2,3,4,5,6,7].map(i => {
|
||||
return mesh.geometry.attributes.position.array.slice(i*3, i*3 + 3)
|
||||
});
|
||||
let points = [
|
||||
vs[2], vs[3],
|
||||
vs[6], vs[7],
|
||||
vs[2], vs[0],
|
||||
@ -936,9 +889,13 @@ const Canvas = {
|
||||
vs[5], vs[7],
|
||||
vs[6], vs[4],
|
||||
vs[1], vs[3]
|
||||
]
|
||||
var line = new THREE.Line(geometry, Canvas.outlineMaterial);
|
||||
line.no_export = true;
|
||||
].map(a => new THREE.Vector3().fromArray(a))
|
||||
if (!line) {
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
line = new THREE.Line(geometry, Canvas.outlineMaterial);
|
||||
line.no_export = true;
|
||||
}
|
||||
line.geometry.setFromPoints(points);
|
||||
return line;
|
||||
},
|
||||
buildOutline(obj) {
|
||||
|
@ -383,7 +383,7 @@ class Preview {
|
||||
if (intersect.isElement) {
|
||||
this.controls.hasMoved = true
|
||||
var obj = OutlinerNode.uuids[intersects[0].object.name]
|
||||
let face = Canvas.face_order[intersects[0].face.materialIndex];
|
||||
let face = Canvas.face_order[Math.floor(intersects[0].faceIndex / 2)];
|
||||
|
||||
return {
|
||||
event: event,
|
||||
@ -1957,7 +1957,6 @@ function initCanvas() {
|
||||
markerColors.forEach(function(s, i) {
|
||||
var thismaterial = new THREE.MeshLambertMaterial({
|
||||
color: 0xffffff,
|
||||
vertexColors: THREE.FaceColors,
|
||||
map: tex
|
||||
})
|
||||
thismaterial.color.set(s.pastel)
|
||||
@ -2045,22 +2044,17 @@ function updateCubeHighlights(hover_cube, force_off) {
|
||||
Cube.all.forEach(cube => {
|
||||
if (cube.visibility) {
|
||||
var mesh = cube.mesh;
|
||||
mesh.geometry.faces.forEach(face => {
|
||||
var b_before = face.color.b;
|
||||
if (
|
||||
Settings.get('highlight_cubes') &&
|
||||
((hover_cube == cube && !Transformer.dragging) || cube.selected) &&
|
||||
Modes.edit &&
|
||||
!force_off
|
||||
) {
|
||||
face.color.setRGB(1.25, 1.28, 1.3);
|
||||
} else {
|
||||
face.color.setRGB(1, 1, 1);
|
||||
}
|
||||
if (face.color.b != b_before) {
|
||||
mesh.geometry.colorsNeedUpdate = true;
|
||||
}
|
||||
})
|
||||
let highlighted = (
|
||||
Settings.get('highlight_cubes') &&
|
||||
((hover_cube == cube && !Transformer.dragging) || cube.selected) &&
|
||||
Modes.edit &&
|
||||
!force_off
|
||||
) ? 1 : 0;
|
||||
|
||||
if (mesh.geometry.attributes.highlight.array[0] != highlighted) {
|
||||
mesh.geometry.attributes.highlight.array.set(Array(24).fill(highlighted));
|
||||
mesh.geometry.attributes.highlight.needsUpdate = true;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -2081,15 +2075,20 @@ function buildGrid() {
|
||||
|
||||
function setupAxisLine(origin, length, axis) {
|
||||
var color = 'rgb'[getAxisNumber(axis)]
|
||||
var geometry = new THREE.Geometry();
|
||||
var material = new THREE.LineBasicMaterial({color: gizmo_colors[color]});
|
||||
var dest = new THREE.Vector3().copy(origin);
|
||||
dest[axis] += length;
|
||||
let points = [
|
||||
origin,
|
||||
dest
|
||||
];
|
||||
let geometry = new THREE.BufferGeometry().setFromPoints(points)
|
||||
|
||||
|
||||
var dest = new THREE.Vector3().copy(origin)
|
||||
dest[axis] += length
|
||||
geometry.vertices.push(origin)
|
||||
geometry.vertices.push(dest)
|
||||
//geometry.vertices.push(origin)
|
||||
//geometry.vertices.push(dest)
|
||||
|
||||
var line = new THREE.Line( geometry, material);
|
||||
var line = new THREE.Line(geometry, material);
|
||||
line.name = 'axis_line_'+axis;
|
||||
three_grid.add(line)
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -57,6 +57,8 @@ class Texture {
|
||||
img.tex.name = this.name;
|
||||
|
||||
var vertShader = `
|
||||
attribute float highlight;
|
||||
|
||||
uniform bool SHADE;
|
||||
|
||||
varying vec2 vUv;
|
||||
@ -83,7 +85,7 @@ class Texture {
|
||||
|
||||
}
|
||||
|
||||
if (color.b > 1.1) {
|
||||
if (highlight == 1.0) {
|
||||
lift = 0.1;
|
||||
} else {
|
||||
lift = 0.0;
|
||||
@ -136,7 +138,6 @@ class Texture {
|
||||
vertexShader: vertShader,
|
||||
fragmentShader: fragShader,
|
||||
side: Canvas.getRenderSide(),
|
||||
vertexColors: THREE.FaceColors,
|
||||
transparent: true,
|
||||
});
|
||||
mat.map = tex;
|
||||
|
@ -351,7 +351,7 @@ const Vertexsnap = {
|
||||
}
|
||||
|
||||
Vertexsnap.cubes.forEach(function(obj) {
|
||||
var q = obj.mesh.getWorldQuaternion(new THREE.Quaternion()).inverse()
|
||||
var q = obj.mesh.getWorldQuaternion(new THREE.Quaternion()).invert()
|
||||
var cube_pos = new THREE.Vector3().copy(global_delta).applyQuaternion(q)
|
||||
|
||||
for (i=0; i<3; i++) {
|
||||
@ -370,7 +370,7 @@ const Vertexsnap = {
|
||||
var cube_pos = new THREE.Vector3().copy(global_delta)
|
||||
|
||||
if (Format.bone_rig && obj.parent instanceof Group && obj.mesh.parent) {
|
||||
var q = obj.mesh.parent.getWorldQuaternion(new THREE.Quaternion()).inverse();
|
||||
var q = obj.mesh.parent.getWorldQuaternion(new THREE.Quaternion()).invert();
|
||||
cube_pos.applyQuaternion(q);
|
||||
}
|
||||
if (Format.rotate_cubes) {
|
||||
@ -573,7 +573,7 @@ function moveElementsInSpace(difference, axis) {
|
||||
|
||||
var rotation = new THREE.Quaternion();
|
||||
group.mesh.parent.getWorldQuaternion(rotation);
|
||||
group_m.applyQuaternion(rotation.inverse());
|
||||
group_m.applyQuaternion(rotation.invert());
|
||||
|
||||
group.forEachChild(g => {
|
||||
g.origin.V3_add(group_m.x, group_m.y, group_m.z);
|
||||
@ -639,7 +639,7 @@ function moveElementsInSpace(difference, axis) {
|
||||
} else if (el.parent instanceof Group) {
|
||||
el.parent.mesh.getWorldQuaternion(rotation);
|
||||
}
|
||||
m.applyQuaternion(rotation.inverse());
|
||||
m.applyQuaternion(rotation.invert());
|
||||
}
|
||||
}
|
||||
|
||||
@ -709,7 +709,7 @@ function rotateOnAxis(modify, axis, slider) {
|
||||
rotWorldMatrix.makeRotationAxis(normal, Math.degToRad(modify(0)))
|
||||
rotWorldMatrix.multiply(obj.matrixWorld)
|
||||
|
||||
let inverse = new THREE.Matrix4().getInverse(obj.parent.matrixWorld)
|
||||
let inverse = new THREE.Matrix4().copy(obj.parent.matrixWorld).invert()
|
||||
rotWorldMatrix.premultiply(inverse)
|
||||
|
||||
obj.matrix.copy(rotWorldMatrix)
|
||||
@ -826,7 +826,7 @@ function rotateOnAxis(modify, axis, slider) {
|
||||
rotWorldMatrix.makeRotationAxis(normal, Math.degToRad(modify(0)))
|
||||
rotWorldMatrix.multiply(mesh.matrixWorld)
|
||||
|
||||
let inverse = new THREE.Matrix4().getInverse(mesh.parent.matrixWorld)
|
||||
let inverse = new THREE.Matrix4().copy(mesh.parent.matrixWorld).invert()
|
||||
rotWorldMatrix.premultiply(inverse)
|
||||
|
||||
mesh.matrix.copy(rotWorldMatrix)
|
||||
|
1098
lib/three.min.js
vendored
1098
lib/three.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,50 +1,52 @@
|
||||
THREE.BoxGeometry.prototype.from = function(arr) {
|
||||
/*
|
||||
vertices[0] //south east up
|
||||
vertices[1] //north east up
|
||||
vertices[2] //south east down
|
||||
vertices[3] //north east down
|
||||
vertices[4] //north west up
|
||||
vertices[5] //south west up
|
||||
vertices[6] //north west down
|
||||
vertices[7] //south west down
|
||||
*/
|
||||
//X
|
||||
this.vertices[4].setX(arr[0])
|
||||
this.vertices[5].setX(arr[0])
|
||||
this.vertices[6].setX(arr[0])
|
||||
this.vertices[7].setX(arr[0])
|
||||
//Y
|
||||
this.vertices[2].setY(arr[1])
|
||||
this.vertices[3].setY(arr[1])
|
||||
this.vertices[6].setY(arr[1])
|
||||
this.vertices[7].setY(arr[1])
|
||||
//Z
|
||||
this.vertices[1].setZ(arr[2])
|
||||
this.vertices[3].setZ(arr[2])
|
||||
this.vertices[4].setZ(arr[2])
|
||||
this.vertices[6].setZ(arr[2])
|
||||
THREE.BufferGeometry.prototype.setShape = function(from, to) {
|
||||
let {position} = this.attributes;
|
||||
|
||||
this.verticesNeedUpdate = true
|
||||
}
|
||||
THREE.BoxGeometry.prototype.to = function(arr) {
|
||||
//X
|
||||
this.vertices[0].setX(arr[0])
|
||||
this.vertices[1].setX(arr[0])
|
||||
this.vertices[2].setX(arr[0])
|
||||
this.vertices[3].setX(arr[0])
|
||||
//Y
|
||||
this.vertices[0].setY(arr[1])
|
||||
this.vertices[1].setY(arr[1])
|
||||
this.vertices[4].setY(arr[1])
|
||||
this.vertices[5].setY(arr[1])
|
||||
//Z
|
||||
this.vertices[0].setZ(arr[2])
|
||||
this.vertices[2].setZ(arr[2])
|
||||
this.vertices[5].setZ(arr[2])
|
||||
this.vertices[7].setZ(arr[2])
|
||||
// East
|
||||
position.array.set([
|
||||
to[0], to[1], to[2],
|
||||
to[0], to[1], from[2],
|
||||
to[0], from[1], to[2],
|
||||
to[0], from[1], from[2],
|
||||
], 0)
|
||||
// West
|
||||
position.array.set([
|
||||
from[0], to[1], from[2],
|
||||
from[0], to[1], to[2],
|
||||
from[0], from[1], from[2],
|
||||
from[0], from[1], to[2],
|
||||
], 12)
|
||||
|
||||
this.verticesNeedUpdate = true
|
||||
// Up
|
||||
position.array.set([
|
||||
from[0], to[1], from[2],
|
||||
to[0], to[1], from[2],
|
||||
from[0], to[1], to[2],
|
||||
to[0], to[1], to[2],
|
||||
], 24)
|
||||
// Down
|
||||
position.array.set([
|
||||
from[0], from[1], to[2],
|
||||
to[0], from[1], to[2],
|
||||
from[0], from[1], from[2],
|
||||
to[0], from[1], from[2],
|
||||
], 36)
|
||||
|
||||
// South
|
||||
position.array.set([
|
||||
from[0], to[1], to[2],
|
||||
to[0], to[1], to[2],
|
||||
from[0], from[1], to[2],
|
||||
to[0], from[1], to[2],
|
||||
], 48)
|
||||
// North
|
||||
position.array.set([
|
||||
to[0], to[1], from[2],
|
||||
from[0], to[1], from[2],
|
||||
to[0], from[1], from[2],
|
||||
from[0], from[1], from[2],
|
||||
], 60)
|
||||
|
||||
position.needsUpdate = true;
|
||||
}
|
||||
Object.assign( THREE.Euler.prototype, {
|
||||
setFromDegreeArray: function ( arr, invert ) {
|
||||
@ -59,77 +61,81 @@ Object.assign( THREE.Euler.prototype, {
|
||||
|
||||
}
|
||||
})
|
||||
THREE.Euler.prototype.inverse = function () {
|
||||
THREE.Euler.prototype.invert = function () {
|
||||
|
||||
var q = new THREE.Quaternion();
|
||||
return function inverse() {
|
||||
return function invert() {
|
||||
|
||||
return this.setFromQuaternion( q.setFromEuler( this ).inverse() );
|
||||
return this.setFromQuaternion( q.setFromEuler( this ).invert() );
|
||||
|
||||
};
|
||||
}();
|
||||
THREE.Vector3.prototype.removeEuler = function (euler) {
|
||||
return function removeEuler(euler) {
|
||||
var inverse = new THREE.Euler().copy(euler).inverse();
|
||||
this.applyEuler(inverse)
|
||||
var invert = new THREE.Euler().copy(euler).invert();
|
||||
this.applyEuler(invert)
|
||||
return this;
|
||||
};
|
||||
}();
|
||||
THREE.Vector3.prototype.toString = function() {
|
||||
return `${this.x}, ${this.y}, ${this.z}`
|
||||
}
|
||||
var GridBox = function( from, to, size, material) {
|
||||
|
||||
var vertices = [];
|
||||
class GridBox extends THREE.LineSegments {
|
||||
constructor( from, to, size, material) {
|
||||
|
||||
function getVector2(arr, axis) {
|
||||
switch (axis) {
|
||||
case 0: return [arr[1], arr[2]]; break;
|
||||
case 1: return [arr[0], arr[2]]; break;
|
||||
case 2: return [arr[0], arr[1]]; break;
|
||||
}
|
||||
}
|
||||
function addVector(u, v, axis, w) {
|
||||
switch (axis) {
|
||||
case 0: vertices.push(w, u, v); break;
|
||||
case 1: vertices.push(u, w, v); break;
|
||||
case 2: vertices.push(u, v, w); break;
|
||||
}
|
||||
}
|
||||
var vertices = [];
|
||||
|
||||
for (var axis = 0; axis < 3; axis++) {
|
||||
|
||||
var start = getVector2(from, axis)
|
||||
var end = getVector2(to, axis)
|
||||
var steps = getVector2(size, axis)
|
||||
|
||||
for (var side = 0; side < 2; side++) {
|
||||
var w = side ? from[axis] : to[axis]
|
||||
|
||||
//lines
|
||||
var step = Math.abs( (end[1]-start[1]) / steps[1] );
|
||||
if (step < 0.0625) step = 0.0625;
|
||||
for (var line = start[1]; line <= end[1]; line += step) {
|
||||
addVector(start[0], line, axis, w)
|
||||
addVector(end[0], line, axis, w)
|
||||
}
|
||||
//Columns
|
||||
var step = Math.abs( (end[0]-start[0]) / steps[0] );
|
||||
if (step < 0.0625) step = 0.0625;
|
||||
for (var col = start[0]; col <= end[0]; col += step) {
|
||||
addVector(col, start[1], axis, w)
|
||||
addVector(col, end[1], axis, w)
|
||||
function getVector2(arr, axis) {
|
||||
switch (axis) {
|
||||
case 0: return [arr[1], arr[2]]; break;
|
||||
case 1: return [arr[0], arr[2]]; break;
|
||||
case 2: return [arr[0], arr[1]]; break;
|
||||
}
|
||||
}
|
||||
function addVector(u, v, axis, w) {
|
||||
switch (axis) {
|
||||
case 0: vertices.push(w, u, v); break;
|
||||
case 1: vertices.push(u, w, v); break;
|
||||
case 2: vertices.push(u, v, w); break;
|
||||
}
|
||||
}
|
||||
|
||||
for (var axis = 0; axis < 3; axis++) {
|
||||
|
||||
var start = getVector2(from, axis)
|
||||
var end = getVector2(to, axis)
|
||||
var steps = getVector2(size, axis)
|
||||
|
||||
for (var side = 0; side < 2; side++) {
|
||||
var w = side ? from[axis] : to[axis]
|
||||
|
||||
//lines
|
||||
var step = Math.abs( (end[1]-start[1]) / steps[1] );
|
||||
if (step < 0.0625) step = 0.0625;
|
||||
for (var line = start[1]; line <= end[1]; line += step) {
|
||||
addVector(start[0], line, axis, w)
|
||||
addVector(end[0], line, axis, w)
|
||||
}
|
||||
//Columns
|
||||
var step = Math.abs( (end[0]-start[0]) / steps[0] );
|
||||
if (step < 0.0625) step = 0.0625;
|
||||
for (var col = start[0]; col <= end[0]; col += step) {
|
||||
addVector(col, start[1], axis, w)
|
||||
addVector(col, end[1], axis, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
|
||||
|
||||
material = material || new THREE.LineBasicMaterial( { color: gizmo_colors.grid } );
|
||||
|
||||
//THREE.LineSegments.call( this, geometry, material );
|
||||
}
|
||||
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
|
||||
|
||||
material = material || new THREE.LineBasicMaterial( { color: gizmo_colors.grid } );
|
||||
|
||||
THREE.LineSegments.call( this, geometry, material );
|
||||
}
|
||||
/*
|
||||
GridBox.prototype = Object.assign( Object.create( THREE.LineSegments.prototype ), {
|
||||
constructor: GridBox,
|
||||
copy: function ( source ) {
|
||||
@ -141,7 +147,7 @@ GridBox.prototype = Object.assign( Object.create( THREE.LineSegments.prototype )
|
||||
clone: function () {
|
||||
return new this.constructor().copy( this );
|
||||
}
|
||||
} );
|
||||
} );*/
|
||||
THREE.GridBox = GridBox
|
||||
|
||||
THREE.Object3D.prototype.toScreenPosition = function(camera, canvas)
|
||||
@ -166,31 +172,35 @@ THREE.Object3D.prototype.toScreenPosition = function(camera, canvas)
|
||||
|
||||
};
|
||||
|
||||
THREE.AxesHelper = function( size ) {
|
||||
THREE.AxesHelper = class AxesHelper extends THREE.LineSegments {
|
||||
constructor( size ) {
|
||||
|
||||
size = size || 1;
|
||||
size = size || 1;
|
||||
|
||||
var vertices = [
|
||||
0, 0, 0, size, 0, 0,
|
||||
0, 0, 0, 0, size, 0,
|
||||
0, 0, 0, 0, 0, size
|
||||
];
|
||||
var vertices = [
|
||||
0, 0, 0, size, 0, 0,
|
||||
0, 0, 0, 0, size, 0,
|
||||
0, 0, 0, 0, 0, size
|
||||
];
|
||||
|
||||
var c = gizmo_colors
|
||||
var colors = [
|
||||
c.r.r, c.r.g, c.r.b, c.r.r, c.r.g, c.r.b,
|
||||
c.g.r, c.g.g, c.g.b, c.g.r, c.g.g, c.g.b,
|
||||
c.b.r, c.b.g, c.b.b, c.b.r, c.b.g, c.b.b,
|
||||
]
|
||||
var c = gizmo_colors
|
||||
var colors = [
|
||||
c.r.r, c.r.g, c.r.b, c.r.r, c.r.g, c.r.b,
|
||||
c.g.r, c.g.g, c.g.b, c.g.r, c.g.g, c.g.b,
|
||||
c.b.r, c.b.g, c.b.b, c.b.r, c.b.g, c.b.b,
|
||||
]
|
||||
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
|
||||
var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
|
||||
|
||||
THREE.LineSegments.call( this, geometry, material );
|
||||
super(geometry, material);
|
||||
|
||||
//THREE.LineSegments.call( this, geometry, material );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
THREE.AxesHelper.prototype = Object.create( THREE.LineSegments.prototype );
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user