Using Three.js to create a variety of distinct lines

When creating maps using three.js, we typically incorporate dashed lines for borders and isolines. However, I am interested in exploring different line patterns for added visual interest. Does texturing offer a better approach to achieve this?

UPD: The map will be presented in 3D, with the ability to rotate and zoom. It utilizes the WebGl renderer.

Answer №1

To explain exactly how to achieve this would require extensive tutorials, so I'll provide you with some helpful links.

You can start by visiting: ... where you will find instructions on creating a basic page with a canvas for drawing shapes. Drawing these shapes may be challenging as it involves multiple draw calls and precise positioning. It's recommended to create functions for each shape and utilize 2D math in these functions, which may warrant separate questions on platforms like SO.

If you want to create dashed lines like the ones in your example picture, check out . For more complex shapes, you'll need to combine different shapes on the canvas manually.

Remember to use a canvas size with dimensions that are power of two, such as 512x512 or 1024x1024, before using it as a texture.

Once you have your canvas set up as desired, integrating it into a three.js scene is straightforward:

var texture = new THREE.Texture( canvas );
var material = new THREE.MeshBasicMaterial({ map: texture });
var geometry = new THREE.PlaneGeometry( 10, 10 );
var plane = new THREE.Mesh( geometry, material );
scene.add( plane );

If you're not copying the map onto the canvas first, you'll need to use a more advanced material since only limited textures can be applied to a single surface. Focus on mastering 2D drawing first, as it's the most challenging aspect of this process.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing Vue Router to only load after I click a link and then refresh the entire webpage?

I have a file called components.js filled with Vue.component instances. Then I have a main.js where I implement a router using these components to create different pages. In index.html, I have links to the router pages. The issue is that on the initial ...

The discrepancy in the array leads to a result of either 1 or an undetermined

Array x = [3,5,7,9,1] Array y = [3,7,8] z = x - y this should result in z = [5,9,1] (7 is common but I want it excluded) Below is the code snippet: function arrayDifference(x, y) { var arr = []; var difference = []; for (var i = 0; i<x.length& ...

Creating a filter using radio input in HTML and CSS is a simple and

Currently, I am delving into the world of Javascript and React, but I have hit a roadblock. My goal is to create a Pokedex, yet I am encountering some difficulties. I have implemented Radio Inputs to filter Pokemon by generation, but I am struggling with ...

Loading `.obj` and `.mtl` files in THREE.js with accompanying PNG textures

I am facing an issue while attempting to load an mtl file with reference to png textures for my obj model. The error I am encountering is as follows: TypeError: manager.getHandler is not a function Below is the snippet of my three.js code: var loadOBJ = ...

Tutorial: Creating Camera.lookAt Animation in Three JS

In my project, I have a dynamic scene that displays a board with various objects. When a user clicks on an object, I am able to use object picking to select it and smoothly animate the camera to an 'overhead' view of the object. By utilizing the ...

Exploring AngularJS: Retrieving data based on a specific ID from a JSON document

Within my controller class, I extract the ID of a specific user from the URL and pass it on to the OrderService. My goal now is to fetch the data associated with this ID from a JSON file. How can I accomplish this task? OrderCtrl 'use strict'; ...

Formatting JSON Date Output in a Unique Style

I am sending an api request and I would like to present the date in a similar format to what can be seen at this link: Here is the json data I am receiving: dates: { start: { localDate: "2017-04-06", localTime: "19:31 ...

Is there a way to ensure that a statement will not execute until the completion of a preceding function?

I am encountering an issue where the window.open function is being called too quickly, causing my other function not to finish and post in time within my onclick event. I attempted to address this by setting a timeout on the trackData() function, but it o ...

Unusual sequence of JQuery Ajax calls

Within my website, there is a project div that is displayed using EJS. The data for the projects in EJS are rendered using a forEach loop, resulting in multiple similar divs appearing on the page. Each project div is assigned an id for identification pur ...

Disordered dropdown display

I've implemented a class that conceals the 2nd and 3rd dropdown options until there's a click or change in the 1st selection. Current Behavior After choosing "regular" from the dropdown, the execution of $(".dropdown").removeClass(&quo ...

Preventing Jquery Append from Adding Previous Elements

I am struggling to figure out how to display the star rating for each hotel individually. I have 5 hotels, each with a different star rating. Here is my Javascript code: function GetStarHotel() { var parent = $(' p.star '), imagePat ...

Issue with Loading Data on AJAX Causing Scrolling Difficulties

Currently, I am in the midst of website development using PHP, MySQL, and JavaScript (JQuery + Ajax). One issue that has arisen is with the customer scroll function and scrollbars. When loading data via ajax, the scroll function is generating numerous erro ...

The function is not explicitly declared within the instance, yet it is being cited during the rendering process in a .vue

import PageNav from '@/components/PageNav.vue'; import PageFooter from '@/components/PageFooter.vue'; export default { name: 'Groups', components: { PageNav, PageFooter, }, data() { return { groups: ...

ClientScript call fails to store values in controls of a web page

I encountered an issue with preserving the value of a TextBox when the page is refreshed using F5. It seems that if I include the // Loading(); function call in the Page_Load(), the TextBox retains its old value. However, as soon as I remove this comment, ...

Positioning the close button on the top right edge of a Material-UI Dialog: A step-by-step guide

https://i.sstatic.net/ARTtq.png How can I include a close icon in the top right corner of the header section? I'm using the Material UI Dialog and everything works well, but I need a close button in the top section. Can anyone assist me with this? ...

Extract the href value from an element and append it to the src attribute of an image

How can I extract the href link from the .image1 div class? <div class="image1"> <a href="/images/productA.jpg"> </a> </div> Then, how do I insert it into the image src shown below? <ul class="example"> <li class ...

Clicking on multiple instances of the same Vue.js component (popover) results in displaying identical data

Attempting to display an AJAX response in a popover shown by clicking an icon (a custom Vue component) brings about a challenge. The issue arises when there are multiple instances of this component, dynamically rendered through the v-for directive within a ...

Customize nestjs/crud response

For this particular project, I am utilizing the Nest framework along with the nestjs/crud library. Unfortunately, I have encountered an issue where I am unable to override the createOneBase function in order to return a personalized response for a person e ...

JavaScript: Different ways to utilize the reduce method

Creating an array for search purposes based on a string like BBC Sport, the desired output array will be: [ 'BBC', 'BB', 'B', 'Sport', 'Spor', 'Spo', 'Sp', 'S' ] An implement ...

Making changes to a JSON file using JavaScript

Hello everyone, I am a beginner in Javascript and have successfully created a system that allows me to search and filter users in my data.json file. However, I am now looking to develop an application that can add users to the data.json file. Any advice or ...