Looking to conceal the edges of a ThreeJS box primitive

I'm trying to figure out how to hide the edges displayed in a box primitive using ThreeJS. The edges only appear when I apply a texture to the faces.

I've attempted various options such as setting wireframe=false, but the edges persist.

Here's the code snippet:

        var container, stats;
        var camera, scene, renderer;

        var canvasWidth = 500; 
        var canvasHeight = 500;
        var windowHalfX = 100;
        var windowHalfY = 100;

        container = document.createElement( 'div' );
        document.body.appendChild( container );

        // Camera
        camera = new THREE.OrthographicCamera( canvasWidth / - 2, canvasWidth / 2, canvasHeight / 2, canvasHeight / - 2, - 500, 5000 );

        // Scene
        scene = new THREE.Scene();

        camera.position.x = 200;
        camera.position.y = 200;
        camera.position.z = 200;

        camera.lookAt( scene.position );

        // Renderer
        renderer = new THREE.CanvasRenderer();
        renderer.setClearColor( "#fff" );
        renderer.setSize( canvasWidth, canvasHeight );

        container.appendChild( renderer.domElement );

        var size = 100;
        geometry = new THREE.BoxGeometry( size, size, size ); 

        material = new THREE.MeshBasicMaterial({ 
            color: "#0000ff", 
            side: THREE.DoubleSide,
            wireframe: false
        });

        // Comment this line to paint a single color cube
        material = new THREE.MeshLambertMaterial({ map: THREE.ImageUtils.loadTexture("http://upload.wikimedia.org/wikipedia/commons/8/81/Color_icon_black.png") });

        mesh = new THREE.Mesh( geometry, material );
        scene.add( mesh );

        var draw = function() {
            requestAnimationFrame( draw );
            renderer.render( scene, camera );
        }

        draw();

Here's a link to the example:

http://jsfiddle.net/gyss/qg4x9/

Thanks!

Answer №1

After some troubleshooting, I managed to resolve my issue by making a simple adjustment:

renderer = new THREE.WebGLRenderer();

Replacing the previous line with the above code snippet did the trick for me.

Another suggestion, mentioned by user TechDude, is to modify this line while still using the CanvasRenderer:

material.overdraw = 0.3; // or any value between 0 and 1

Answer №2

When you create a new THREE.CanvasRenderer using

renderer = new THREE.CanvasRenderer();
to get rid of the edges, make sure to include the parameter overdraw:true in the material definition like this:

var material = new THREE.MeshBasicMaterial( { map: texture, overdraw: true } );

Afterwards, simply add the material to the 3D object like so:

mesh = new THREE.MeshBasicMaterial( geometry, material );

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

Guide to changing the checkbox value using JavaScript

Describing the Parent Element: <span style="background: yellow; padding: 50px;" onClick="setCheckBox()"> <span> </span> <input type="checkbox" name="f01" value="100"> </span> ...

What is the best way to format and return a result object list in JavaScript or Angular?

I have a question regarding the use of for loops in JavaScript or utilizing Angular to output the resulting object list. Here is an example of an object list: var alist = []; alist = [ { 'code': 1000, 'type': 'C' ...

Using PHP and MySQL to handle data submission through the POST method

When I send data to post[submit] and post[request], it's coming from two separate buttons. Even though I successfully submitted user_id to post[submit], I'm encountering difficulty in echoing the user_id in the request portion (post[request]). ...

Utilize a display value while maintaining the v-model binding in Vue.js

Can't seem to figure this one out. I'm using Quasar Framework, but it seems like more of a Vue issue. I have a multiple-select UI component with a list of objects as options that I want to display. The v-model will bind to the currently selected ...

When I set the width of my script to 100% in CSS, it causes the width to become distorted

I encountered an issue with my Div Slider that swaps out Divs on click. When I modified the CSS to include the following: .hslide-item {width: 100%}; The script started ignoring the entire div width. I am looking for a solution where the .hslide-item ca ...

Should You Ajaxify Your Website?

Absolutely loving the way Ajax can transform a web app into something that performs like a desktop application. The concern, however, arises when dealing with high volume sites. Currently working on an intranet-based database app meant for only 2-4 users a ...

What strategies can be used to steer clear of overhyped products after adjusting state?

I have a function that retrieves data from Firebase. After getting the data, I want to set it into a state. So, I create an array and push all the data into it. Then, I update my state with this array. However, when I log or render this state, I encounter ...

Guide on How to Show Only the Initial Word of an H2 Header Using JavaScript or CSS

Is there a way to display only the first word from an h2 heading? For instance: In the website's source code, it would appear like this <h2> Stackoverflow is an Ideal Place</h2> But on the live website, it should be displayed like this ...

What is the process for extracting components from a JSON file using an observable in Angular?

Take a look at this snippet of code: response: any; fetchData(url: any) { this.response = this.http.get(url); } ngOnInit(): void { fetchData("url.com/data.json"); console.log(this.response) } When I check the console, I see Obser ...

Is the conditional module require within an "If" statement always executed in nuxt.config.js?

Despite the missing file mod.json, the "require" statement is still executed leading to an error. The condition should have prevented it from entering the "if" block: const a = 1; if(a === 2){ const mod = require('./scripts/mod ...

Tips for effectively passing "this" to direct the event initiator in react js?

I'm facing an issue where I am attempting to send a buttons object to a function and then access its properties within that function. Here's my button : <RaisedButton label="Primary" id = "1" onTouchTap={()=>this.buttonPress(this)} prima ...

NodeJS - Issue: The procedure specified could not be located in the bcrypt_lib.node

After upgrading from Node.js 0.12.7 to 4.2.1, I encountered an error when attempting to start my server: $ node server.js C:\Users\me\documents\github\angular-express-auth\node_modules\bcrypt\node_modules\bindi ...

Adding a Fictitious Pair to a JavaScript Object Literal

When I work with object literals in JavaScript, I often encounter syntax errors when adding a new label / value pair without including the trailing comma. This can be frustrating as it's easy to forget to include the necessary delimiter. .draggable({ ...

Firebase and React are having trouble communicating because it is unable to access the properties of 'auth'

The issue with the 'Cannot read properties of undefined (reading 'auth')' error in login.js may be related to where it is coming from. Login.js: import { useContext, useState, useEffect } from "react"; import { Link, useNavigate } f ...

Discover the method for creating URLs that are relative to the specific domain or server on which they are hosted

I need to adapt my menu bar to cater for different server environments: <a href="http://staging.subdomain.site.co.uk/search/page">Menu</a> The main source site is hosted on an external subdomain from an API service, and I want the URLs in my ...

Conflicting events arising between the onMouseUp and onClick functions

I have a scrollbar on my page that I want to scroll by 40px when a button is clicked. Additionally, I want the scrolling to be continuous while holding down the same button. To achieve this functionality, I implemented an onClick event for a single 40px s ...

Reactjs encountering issues loading css file

Currently, I am working on a project in Reactjs with Nextjs. To add CSS to my project, I have stored my CSS files in the 'styles' folder. In order to include them, I created a file called '_document.js' and implemented the following cod ...

When I remove a user as admin, I am unable to retrieve all users to update the data table

I am currently working on an Admin Dashboard that includes a section for users. This section features a simple table displaying all the users in the MongoDB database along with some information. Additionally, there are functionalities to add a new user and ...

Is there a method to delay HTTP requests until the number of pending requests drops below a certain threshold (N)?

I'm in the midst of a project that involves allowing users to upload multiple files simultaneously. However, sending out numerous requests all at once can overwhelm the server and trigger a 429 (Too Many Requests) error for those requests. Is there a ...

Troubleshooting the non-functional asynchronous function

After starting to use redis with node (specifically the node_redis module), I decided to wrap my retrieval code for debugging and DRY principles. However, I encountered an issue where my new function wasn't working as expected. As someone who is stil ...