08-ArcGIS For JavaScript-通過Mesh繪制幾何體(Cylinder,Circle,Box,Pyramid)

目錄

  • 概述
  • 代碼實現
    • 1、Mesh.createBox
    • 2、createPyramid
    • 3、Mesh.createSphere
    • 4、Mesh.createCylinder
  • 完整代碼

概述

對于三維場景而言,二位的點、線、面,三維的圓、立方體、圓柱等都是比較常見的三維對象,在ArcGIS For JavaScript中我們知道點、線、面可以直接通過Geometry的Point、Polyline和Polygon去繪制,而立方體的幾何繪制則需要通過Mesh對象提供的方法去繪制,這怕文章主要講解Mesh下的幾何體繪制。

代碼實現

在這里插入圖片描述

1、Mesh.createBox

Box幾何體的繪制:

function createBox(center, width) {// Place of placementconst point = new Point({// x: center[0],// y: center[1],longitude: center[0],latitude: center[1],z: center[2],spatialReference: SpatialReference.WebMercator});// Boxconst boxMesh = Mesh.createBox(point, {size: { width: width, depth: width, height: width * 5 },material: {color: [58, 38, 0, 1]}});// Empty symbolconst emptyMeshSymbol = new MeshSymbol3D({symbolLayers: [new FillSymbol3DLayer({})]});const box = new Graphic({geometry: boxMesh,symbol: emptyMeshSymbol});view.graphics.add(box);return box;
}

結果:
在這里插入圖片描述

2、createPyramid

金字塔幾何的繪制,其繪制相對復雜:

function createPyramid(center) {// Place of placementconst point = new Point({// x: center[0],// y: center[1],longitude: center[0],latitude: center[1],z: center[2],spatialReference: SpatialReference.WebMercator});// Pyramidfunction createPyramid(location, { material, size }) {const { height, width, depth } = size;const halfWidth = width / 2;const halfDepth = depth / 2;const origin = [location.x + 10, location.y, location.z]; // adding 10 to the placement position to create the pyramid next to the boxconst position = [0,0,height,-halfWidth,-halfDepth,0,halfWidth,-halfDepth,0,halfWidth,halfDepth,0,-halfWidth,halfDepth,0];const uv = [0.5, 0, 0, 1, 1, 1, 0, 1, 1, 1];const pyramid = new Mesh({vertexSpace: new MeshLocalVertexSpace({ origin }),vertexAttributes: { position, uv },components: [{ faces: [0, 1, 2], material },{ faces: [0, 2, 3], material },{ faces: [0, 3, 4], material },{ faces: [0, 4, 1], material }],spatialReference: location.spatialReference});return pyramid;}const pyramidMesh = createPyramid(point, {size: { width: 350, depth: 350, height: 300 },material: new MeshMaterial({color: [60, 87, 49, 1]})});// Empty symbolconst emptyMeshSymbol = new MeshSymbol3D({symbolLayers: [new FillSymbol3DLayer({})]});const pyramid = new Graphic({geometry: pyramidMesh,symbol: emptyMeshSymbol});view.graphics.add(pyramid);return pyramid;
}

結果:
在這里插入圖片描述

3、Mesh.createSphere

球體的繪制:

function createShpere(centerPos, radius) {let viewPointHeight = centerPos[2];const snowManLocation = new Point({longitude: centerPos[0],latitude: centerPos[1],z: (radius * -1) + centerPos[2],spatialReference: SpatialReference.WebMercator,});point = snowManLocation;// const sphere = Mesh.createSphere(snowManLocation, {const sphere = Mesh.createSphere(snowManLocation, {size: radius * 2,material: { color: 'rgba(255,255,0,0.2)' },densificationFactor: 1,vertexSpace: 'local',});const symbol = {type: 'mesh-3d',symbolLayers: [{ type: 'fill' }],};// const graphic = new Graphic(sphere, symbol);const graphic = new Graphic({geometry: sphere,symbol: symbol});view.graphics.add(graphic);return graphic;}

結果:
在這里插入圖片描述

4、Mesh.createCylinder

圓柱體的繪制:

function createCylinder(centerPos, radius) {let viewPointHeight = centerPos[2];const snowManLocation = new Point({longitude: centerPos[0],latitude: centerPos[1],z: (radius * -1) + centerPos[2],spatialReference: SpatialReference.WebMercator,});point = snowManLocation;// const sphere = Mesh.createSphere(snowManLocation, {const sphere = Mesh.createCylinder(snowManLocation, {size: radius * 2,material: { color: 'rgba(255,0,0,0.2)' },densificationFactor: 1,vertexSpace: 'local',});const symbol = {type: 'mesh-3d',symbolLayers: [{ type: 'fill' }],};// const graphic = new Graphic(sphere, symbol);const graphic = new Graphic({geometry: sphere,symbol: symbol});view.graphics.add(graphic);return graphic;}

結果:
在這里插入圖片描述

完整代碼

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" /><script src="https://js.arcgis.com/4.30/"></script><style>html,body,#viewDiv {height: 100%;width: 100%;margin: 0;padding: 0;}</style><script>require(['esri/geometry/Point',"esri/geometry/SpatialReference","esri/geometry/Mesh","esri/views/SceneView","esri/Map","esri/Graphic","esri/symbols/FillSymbol3DLayer","esri/symbols/MeshSymbol3D","esri/geometry/support/MeshMaterial","esri/geometry/support/MeshLocalVertexSpace",], (Point, SpatialReference, Mesh, SceneView, Map,Graphic, FillSymbol3DLayer, MeshSymbol3D, MeshMaterial, MeshLocalVertexSpace) => {let map = new Map({basemap: 'satellite'})let center = [116.4074, 39.9042, 300];let view = new SceneView({container: 'viewDiv',map,camera: {position: {longitude: center[0],latitude: center[1],z: 1000,spatialReference: {wkid: 4326}}}})let point = null;function createShpere(centerPos, radius) {let viewPointHeight = centerPos[2];const snowManLocation = new Point({longitude: centerPos[0],latitude: centerPos[1],z: (radius * -1) + centerPos[2],spatialReference: SpatialReference.WebMercator,});point = snowManLocation;// const sphere = Mesh.createSphere(snowManLocation, {const sphere = Mesh.createSphere(snowManLocation, {size: radius * 2,material: { color: 'rgba(255,255,0,0.2)' },densificationFactor: 1,vertexSpace: 'local',});const symbol = {type: 'mesh-3d',symbolLayers: [{ type: 'fill' }],};// const graphic = new Graphic(sphere, symbol);const graphic = new Graphic({geometry: sphere,symbol: symbol});view.graphics.add(graphic);return graphic;}function createCylinder(centerPos, radius) {let viewPointHeight = centerPos[2];const snowManLocation = new Point({longitude: centerPos[0],latitude: centerPos[1],z: (radius * -1) + centerPos[2],spatialReference: SpatialReference.WebMercator,});point = snowManLocation;// const sphere = Mesh.createSphere(snowManLocation, {const sphere = Mesh.createCylinder(snowManLocation, {size: radius * 2,material: { color: 'rgba(255,0,0,0.2)' },densificationFactor: 1,vertexSpace: 'local',});const symbol = {type: 'mesh-3d',symbolLayers: [{ type: 'fill' }],};// const graphic = new Graphic(sphere, symbol);const graphic = new Graphic({geometry: sphere,symbol: symbol});view.graphics.add(graphic);return graphic;}function createBox(center, width) {// Place of placementconst point = new Point({// x: center[0],// y: center[1],longitude: center[0],latitude: center[1],z: center[2],spatialReference: SpatialReference.WebMercator});// Boxconst boxMesh = Mesh.createBox(point, {size: { width: width, depth: width, height: width * 5 },material: {color: [58, 38, 0, 1]}});// Empty symbolconst emptyMeshSymbol = new MeshSymbol3D({symbolLayers: [new FillSymbol3DLayer({})]});const box = new Graphic({geometry: boxMesh,symbol: emptyMeshSymbol});view.graphics.add(box);return box;}function createPyramid(center) {// Place of placementconst point = new Point({// x: center[0],// y: center[1],longitude: center[0],latitude: center[1],z: center[2],spatialReference: SpatialReference.WebMercator});// Pyramidfunction createPyramid(location, { material, size }) {const { height, width, depth } = size;const halfWidth = width / 2;const halfDepth = depth / 2;const origin = [location.x + 10, location.y, location.z]; // adding 10 to the placement position to create the pyramid next to the boxconst position = [0,0,height,-halfWidth,-halfDepth,0,halfWidth,-halfDepth,0,halfWidth,halfDepth,0,-halfWidth,halfDepth,0];const uv = [0.5, 0, 0, 1, 1, 1, 0, 1, 1, 1];const pyramid = new Mesh({vertexSpace: new MeshLocalVertexSpace({ origin }),vertexAttributes: { position, uv },components: [{ faces: [0, 1, 2], material },{ faces: [0, 2, 3], material },{ faces: [0, 3, 4], material },{ faces: [0, 4, 1], material }],spatialReference: location.spatialReference});return pyramid;}const pyramidMesh = createPyramid(point, {size: { width: 350, depth: 350, height: 300 },material: new MeshMaterial({color: [60, 87, 49, 1]})});// Empty symbolconst emptyMeshSymbol = new MeshSymbol3D({symbolLayers: [new FillSymbol3DLayer({})]});const pyramid = new Graphic({geometry: pyramidMesh,symbol: emptyMeshSymbol});view.graphics.add(pyramid);return pyramid;}let radius = 200;let graphic = createShpere(center, radius);let cylinderCenter = center;cylinderCenter[1] += 0.005;let cylinderRadius = 100;createCylinder(cylinderCenter, cylinderRadius);let boxCenter = center;boxCenter[0] += 0.005;createBox(boxCenter, 50);let pyramidCenter = center;pyramidCenter[0] -= 0.01;createPyramid(pyramidCenter);})</script>
</head><body><div id="viewDiv"></div>
</body></html>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/66935.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/66935.shtml
英文地址,請注明出處:http://en.pswp.cn/web/66935.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Linux中page、buffer_head、bio的關系

在Linux中&#xff0c;page、buffer_head、bio這三個概念緊密相關&#xff0c;共同構成了塊設備I/O和內存管理的重要部分&#xff0c;它們的聯系主要體現在以下方面&#xff1a; page與buffer_head 基于page構建&#xff1a;buffer_head通常是基于page來構建的&#xff0c;一…

直線擬合例子 ,嶺回歸擬合直線

目錄 直線擬合,算出離群點 嶺回歸擬合直線&#xff1a; 直線擬合,算出離群點 import cv2 import numpy as np# 輸入的點 points np.array([[51, 149],[122, 374],[225, 376],[340, 382],[463, 391],[535, 298],[596, 400],[689, 406],[821, 407] ], dtypenp.float32)# 使用…

SpringCloud兩種注冊中心

SpringCloud 基本概念 系統架構 我們之前做的所有的項目都屬于單體架構&#xff0c;下面我們將要學習更適合大型項目的分布式架構 單體架構&#xff1a; 將業務的所有功能幾種在一個項目中開發&#xff0c;打成一個包部署。 優點&#xff1a;架構簡單、部署成本低 缺點&am…

SpringAI 搭建智能體(二):搭建客服系統智能體

在現代人工智能應用中&#xff0c;智能體&#xff08;Agent&#xff09; 是一個重要的概念&#xff0c;它的核心能力是自主性與靈活性。一個智能體不僅能夠理解用戶的需求&#xff0c;還能拆解任務、調用工具完成具體操作&#xff0c;并在復雜場景中高效運行。在本篇博客中&…

SVN客戶端使用手冊

目錄 一、簡介 二、SVN的安裝與卸載 1. 安裝&#xff08;公司內部一般會提供安裝包和漢化包&#xff0c;直接到公司內部網盤下載即可&#xff0c;如果找不到可以看下面的教程&#xff09; 2. 查看SVN版本 ?編輯 3. SVN卸載 三、SVN的基本操作 1. 檢出 2. 清除認證數據 3. 提交…

HTML 文本格式化詳解

在網頁開發中&#xff0c;文本內容的呈現方式直接影響用戶的閱讀體驗。HTML 提供了多種文本格式化元素&#xff0c;可以幫助我們更好地控制文本的顯示效果。本文將詳細介紹 HTML 中的文本格式化元素及其使用方法&#xff0c;幫助你輕松實現網頁文本的美化。 什么是 HTML 文本格…

衡量算法性能的量級標準:算法復雜度

今天開始數據結構的學習&#xff01;作為一大重點&#xff0c;拿出態度很重要&#xff0c;想要真實掌握&#xff0c;博客筆記自然少不了&#xff01;重點全部上色&#xff01;避免疏忽 下面我們從0基礎開始學習今天的第一節&#xff01;不用擔心看不懂&#xff0c;拒絕枯燥的理…

Spring Boot Starter介紹

前言 大概10來年以前&#xff0c;當時springboot剛剛出現并沒有流行&#xff0c;當時的Java開發者們開發Web應用主要是使用spring整合springmvc或者struts、iBatis、hibernate等開發框架來進行開發。項目里一般有許多xml文件配置&#xff0c;其中配置了很多項目中需要用到的Be…

Java面試題2025-Spring

講師&#xff1a;鄧澎波 Spring面試專題 1.Spring應該很熟悉吧&#xff1f;來介紹下你的Spring的理解 1.1 Spring的發展歷程 先介紹Spring是怎么來的&#xff0c;發展中有哪些核心的節點&#xff0c;當前的最新版本是什么等 通過上圖可以比較清晰的看到Spring的各個時間版本對…

Linux 切換到 Root 用戶的方式及差異詳解

在 Linux 系統中&#xff0c;切換到 root 用戶進行管理和操作是常見需求。不同的切換方法會影響環境變量、工作目錄以及加載的配置文件。本文將介紹幾種常用的切換方式及它們的特點。 切換到 Root 用戶的主要方式 1. sudo su 這是通過 sudo 提權后調用 su 切換到 root 用戶的…

虹科分享 | 汽車NVH小課堂之聽音辨故障

隨著車主開始關注汽車抖動異響問題&#xff0c;如何根據故障現象快速診斷異響來源&#xff0c;成了汽修人的必修課。 一個比較常用的方法就是靠“聽”——“聽音辨故障”。那今天&#xff0c;虹科Pico也整理了幾個不同類型的異響聲音&#xff0c;一起來聽聽看你能答對幾個吧 汽…

淺談Redis

2007 年&#xff0c;一位程序員和朋友一起創建了一個網站。為了解決這個網站的負載問題&#xff0c;他自己定制了一個數據庫。于2009 年開發&#xff0c;稱之為Redis。這位意大利程序員是薩爾瓦托勒桑菲利波(Salvatore Sanfilippo)&#xff0c;他被稱為Redis之父&#xff0c;更…

element tbas增加下拉框

使用Tabs 標簽頁的label插槽&#xff0c;嵌入Dropdown 下拉菜單&#xff0c;實現Tabs 標簽頁增加下拉切換功能 Tabs 標簽頁 tab-click"事件"&#xff08;這個事件當中到擁有下拉框的tab里時&#xff0c;可以存一下Dropdown 第一個菜單的id&#xff0c;實現點擊到擁有…

SQL-leetcode—1179. 重新格式化部門表

1179. 重新格式化部門表 表 Department&#xff1a; ---------------------- | Column Name | Type | ---------------------- | id | int | | revenue | int | | month | varchar | ---------------------- 在 SQL 中&#xff0c;(id, month) 是表的聯合主鍵。 這個表格有關…

【Address Overfitting】解決過擬合的三種方法

目錄 1. 收集更多數據實踐方法&#xff1a;適用場景&#xff1a;優缺點&#xff1a; 2. 特征選擇方法介紹&#xff1a;實踐示例&#xff1a;適用場景&#xff1a;優缺點&#xff1a; 3. 正則化&#xff08;Regularization&#xff09;正則化類型&#xff1a;實踐示例&#xff1…

面向通感一體化的非均勻感知信號設計

文章目錄 1 非均勻信號設計的背景分析1.1 基于OFDM波形的感知信號1.2 非均勻信號設計的必要性和可行性1.2 非均勻信號設計的必要性和可行性 3 通感一體化系統中的非均勻信號設計方法3.1 非均勻信號的設計流程&#xff08;1&#xff09;均勻感知信號設計&#xff08;2&#xff0…

【深度學習】搭建PyTorch神經網絡進行氣溫預測

第一步 數據加載與觀察 ①導包 import numpy as np import pandas as pd import matplotlib.pyplot as plt import torch import torch.optim as optim import warnings warnings.filterwarnings("ignore") %matplotlib inline ②加載數據 features pd.read_csv(…

ESP8266 NodeMCU與WS2812燈帶:實現多種花樣變換

在現代電子創意項目中&#xff0c;LED燈帶的應用已經變得極為廣泛。通過結合ESP8266 NodeMCU的強大處理能力和FastLED庫的高效功能&#xff0c;我們可以輕松實現多達100種燈帶變換效果。本文將詳細介紹如何使用Arduino IDE編程&#xff0c;實現從基礎到高級的燈光效果&#xff…

pycharm踩坑(1)

由于我重裝系統&#xff0c;導致我的pycharm需要進行重裝&#xff0c;因此我覺得需要記錄一下&#xff0c;pycharm的正確使用方法 漢化 漢化很重要&#xff0c;除非你從小就雙語教學&#xff0c;不然你看著那些英文就是會消耗大量的精力 我使用的pycharm版本是pycharm-commun…

#HarmonyOS篇:build-profile.json5里面配置productsoh-package.json5里面dependencies依賴引入

oh-package.json5 用于描述包名、版本、入口文件和依賴項等信息。 {"license": "","devDependencies": {},"author": "","name": "entry","description": "Please describe the basic…