Hi!
I have a code, following by this topic: ( Click ).
My code:
function addObject3D( Object )
{
var AllFaces = new THREE.Group();
for(var f=0; f < Object.Faces.length; f++)
{
var points = [];
Object.Faces[f].Vertices3D.forEach(r => {
points.push(new THREE.Vector3(r.x, r.y, r.z));
});
var tri = new THREE.Triangle(points[2], points[1], points[0]);
var normal = new THREE.Vector3();
tri.getNormal(normal);
var baseNormal = new THREE.Vector3(0, 0, 1);
var quaternion = new THREE.Quaternion().setFromUnitVectors(normal, baseNormal);
var tempPoints = [];
points.forEach(p => {
tempPoints.push(p.clone().applyQuaternion(quaternion));
})
var shape = new THREE.Shape(tempPoints);
var shapeGeom = new THREE.ShapeGeometry(shape);
var Texture = new THREE.TextureLoader().load( 'graphic/3D/wood2.jpg' );
var Material = new THREE.MeshBasicMaterial( { map: Texture } );
Material.side = THREE.DoubleSide;
var mesh = new THREE.Mesh( shapeGeom, Material ) ;
mesh.geometry.vertices = points;
AllFaces.add(mesh);
}
return AllFaces;
}
And it’s work fine, when I use THREE.MeshBasicMaterial, but when I try to use a texture, the object has a solid color.
How to fix it?
How to use a texture on object created by vertices?
Without this line, the resulting shape will be at the plane, parallel to XY-plane.
The idea is, using a quaternion, put points to a plane, parallel to XY-plane, build a shape and a geometry of THREE.ShapeGeometry() and apply original points, as we have a set of faces, we just use old points instead of current ones in the geometry.
Hey, Im also trying to apply a texture on a ShapeGeometry. The shape is flat on the y axes, y = 0. When I run the following code, the shape gets white because of the color change, but there is no texture showing, but it is there.
@prisoner849
I am using THREE.ExtrudeGeometry some how manage to add texture but the frequency of the texture is not constant is changing according to the area of shape
Is there any way to make it constant ?
Please see the difference in ground floor and first floor
@abdulqadir I’ve often seen especially new users who struggle with the build-in geometry generators like ExtrudeGeometry. If you need vertex data which can’t be generated by default, I highly suggest you use a tool like Blender to author your models if possible. Otherwise you have to invest a certain amount of time to better understand how vertex data like texture coordinates can be generated.
It is not easy at first to generate such data correctly. But I myself was just interested in it and it is possible with some commitment. The exercise does it then.