Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3c756564ef | ||
![]() |
7119006072 |
@ -93,6 +93,7 @@ function animateTexture() {
|
|||||||
}
|
}
|
||||||
animateTexture()
|
animateTexture()
|
||||||
function createGeo(geoJson) {
|
function createGeo(geoJson) {
|
||||||
|
console.log(geoJson);
|
||||||
|
|
||||||
const group = new THREE.Group()
|
const group = new THREE.Group()
|
||||||
group.info = geoJson
|
group.info = geoJson
|
||||||
@ -122,6 +123,8 @@ function createGeo(geoJson) {
|
|||||||
else if (info.geometry.type === 'Polygon') info.geometry.coordinates.forEach((j) => areaGroup.add(createShapeWithCoord(j, materials)))
|
else if (info.geometry.type === 'Polygon') info.geometry.coordinates.forEach((j) => areaGroup.add(createShapeWithCoord(j, materials)))
|
||||||
|
|
||||||
if (info.properties.adcode === 330000) {
|
if (info.properties.adcode === 330000) {
|
||||||
|
console.log(info.properties.name, areaGroup);
|
||||||
|
|
||||||
// 获取区域的边界框
|
// 获取区域的边界框
|
||||||
const box = new THREE.Box3().setFromObject(areaGroup);
|
const box = new THREE.Box3().setFromObject(areaGroup);
|
||||||
const minX = box.min.x;
|
const minX = box.min.x;
|
||||||
@ -168,6 +171,52 @@ function createGeo(geoJson) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info.properties.adcode > 330000 && info.properties.adcode < 340000) {
|
||||||
|
console.log(info.properties.name, areaGroup);
|
||||||
|
const box = new THREE.Box3().setFromObject(areaGroup);
|
||||||
|
const minX = box.min.x;
|
||||||
|
const maxX = box.max.x;
|
||||||
|
const minY = box.min.y;
|
||||||
|
const maxY = box.max.y;
|
||||||
|
const zhejiangTexture = new THREE.TextureLoader().load(zhejiang);
|
||||||
|
|
||||||
|
areaGroup.children.forEach(mesh => {
|
||||||
|
if (mesh.geometry instanceof THREE.ExtrudeGeometry) {
|
||||||
|
const geometry = mesh.geometry;
|
||||||
|
const positions = geometry.attributes.position.array;
|
||||||
|
const uvs = new Float32Array(positions.length / 3 * 2);
|
||||||
|
|
||||||
|
// 计算UV坐标
|
||||||
|
for (let i = 0; i < positions.length; i += 3) {
|
||||||
|
const x = positions[i];
|
||||||
|
const y = positions[i + 1];
|
||||||
|
uvs[i / 3 * 2] = (x - minX) / (maxX - minX);
|
||||||
|
uvs[i / 3 * 2 + 1] = (y - minY) / (maxY - minY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置UV属性
|
||||||
|
geometry.setAttribute('uv', new THREE.BufferAttribute(uvs, 2));
|
||||||
|
|
||||||
|
// 创建新的材质数组,包含原有材质和顶面材质
|
||||||
|
const materials = [
|
||||||
|
new THREE.MeshStandardMaterial({
|
||||||
|
map: zhejiangTexture,
|
||||||
|
metalness: 0.5,
|
||||||
|
roughness: 0.5
|
||||||
|
}),
|
||||||
|
new THREE.MeshBasicMaterial({
|
||||||
|
map: texture,
|
||||||
|
color: 0xffffff * Math.random()
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
// 更新网格的材质
|
||||||
|
mesh.material = materials;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
const div = document.createElement('div')
|
const div = document.createElement('div')
|
||||||
div.innerHTML = info.properties?.name
|
div.innerHTML = info.properties?.name
|
||||||
div.style.color = '#dbdbdb'
|
div.style.color = '#dbdbdb'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user