What is the process for transferring `Parentobject1` to `childobject2` and `childobject3` in Three.js?

I have created two objects doubleSquare and doubleSquare1. I was expecting the output to be Double Line Square Object, but I have tried two different formats and have not achieved the desired output. Can someone please provide me with a solution? I have looked at many examples while analyzing websites. What mistake have I made in the code?

Type 1 (In the code below, the doubleSquare closepath starts with another object draw. How can I split it?)

function doubleSquareDemoDraw(startX, startY, endX, endY, color){
var widthLength = Math.round(Math.abs(endX - startX));
         var heightLength = Math.round(Math.abs(endY - startY));
         console.log(widthLength+'::'+heightLength);

         var combined = new THREE.Geometry(); 
         var doubleSquare = new THREE.Geometry();
          doubleSquare.vertices.push(new THREE.Vector3(startX, startY, 0));
          doubleSquare.vertices.push(new THREE.Vector3(endX, startY, 0));
          doubleSquare.vertices.push(new THREE.Vector3(endX, endY, 0));
          doubleSquare.vertices.push(new THREE.Vector3(startX, endY, 0));
          doubleSquare.vertices.push(new THREE.Vector3(startX, startY, 0));
          doubleSquare.vertices.push(new THREE.Vector3(startX, startY, 0)); //closepath

        var doubleSquare1 = new THREE.Geometry();
        doubleSquare1.vertices.push(
            new THREE.Vector3(startX + 4, startY- 4 , 0),
            new THREE.Vector3(endX -4, startY- 4, 0),
            new THREE.Vector3(endX - 4, endY +4, 0),
            new THREE.Vector3(startX + 4, endY + 4, 0),
            new THREE.Vector3(startX + 4, startY -4 , 0)
        );

        THREE.GeometryUtils.merge( combined, doubleSquare );
        THREE.GeometryUtils.merge( combined, doubleSquare1 );

        var display = new THREE.Line(combined, new THREE.LineBasicMaterial({ color: color }));

        return display;
}

Type 2 (In the code below, only a single object is visible instead of two)

function doubleSquareDraw(startX, startY, endX, endY, color){

       var combined = new THREE.Geometry(); 
       var square1 = new THREE.Shape();
       square1.moveTo(startX, startY, 0);
       square1.lineTo(endX, startY, 0);
       square1.lineTo(endX, endY, 0);
       square1.lineTo(startX, endY, 0);
       square1.lineTo(startX, startY, 0);

       var square2 = new THREE.Path();
       square2.moveTo(startX + 4 , startY  - 4  , 0);
       square2.lineTo(endX - 4  , startY - 4  , 0);
       square2.lineTo(endX - 4 , endY + 4  , 0);
       square2.lineTo(startX + 4  , endY + 4  , 0);
       square2.lineTo(startX + 4  , startY  - 4  , 0);
       square1.holes.push( square2);

       var geometry = new THREE.BufferGeometry().setFromPoints(square.getPoints());  
      var square = new THREE.Line(geometry, new THREE.MeshBasicMaterial({
            color: color
        })); 
        return display;
    }

Answer №1

Upon closer examination of the source code in this particular example, it becomes evident that the shapes and their corresponding holes are drawn independently.

Take, for instance, the arcShape:

  1. The definition of the shape and its hole can be found here

  2. We then pass this shape into the function

    addShape( arcShape, extrudeSettings, 0x804000,  150, 0, 0, 0, 0, 0, 1 );

  3. Within addShape, the

    addLineShape( shape, color, x, y, z, rx, ry, rz, s );
    function is called, which draws the outer boundary line of the shape;

  4. To draw the hole within the circle, addLineShape() is again invoked, with the hole's path as the first parameter. Details can be found here.

Based on your code, it seems like you believe that defining a shape and its holes, followed by creating a buffer geometry using

new THREE.BufferGeometry().setFromPoints(shape.getPoints())
, would generate the contour line of the shape and its holes. However, this assumption is incorrect as the process operates differently.

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 is the best way to replicate the functionality of AngularJS decorators in pure vanilla JavaScript (ES6)?

Using AngularJs Decorators offers a convenient method to enhance functions in services without altering the original service. How can a similar approach be implemented with javascript classes? In my current project, I have two libraries - one containing g ...

Is it feasible to choose the component generated by this element?

My current dilemma involves a component that renders a form, however, it also has its own form "catcher". var FormUpload = React.createClass({ submit : function(){ var formdata =new FormData(); ...

The print preview displays a single div in an incorrect location

I have successfully created a javascript plot and wanted to incorporate a legend that overlaps the plot. Unfortunately, the function I used does not support directly overlapping legends, but it does allow for placing the legend in a separate div. To work a ...

Change the function from onLoad to onClick exclusively

I'm experiencing a particle explosion on my webpage due to this code. I connected the onClick function to a button in my HTML so it executes only when that specific button is clicked. However, the function automatically runs when I load the HTML and ...

What is the best way to update specific values in a react multiselect component?

Within my modal, I have a form where I can edit my model. One of the fields in this form is a multi-select tag field called "tags", which is an array of objects consisting of labels and values as illustrated below. To populate this tag field, I have a dum ...

Retrieve data from a JSON file to assign to a variable, then access another API to retrieve a second

I am completely new to the world of javascript and json. My previous experience with javascript was quite minimal, about 12 years ago. So, please bear with me as I try to explain my current issue. The problem I am facing involves retrieving a second API UR ...

NodeJS video streaming feature does not close the connection when the user disconnects or navigates to a different page

Currently, I'm in the process of developing a video streaming server using nodeJS with express. To monitor the progress status, I am utilizing the "request-progress" module. So far, everything pertaining to video streaming is working perfectly. Howev ...

Creating mock implementations using jest in vue applications

I have been experimenting with testing whether a method is invoked in a Vue component when a specific button is clicked. Initially, I found success using the following method: it('should call the methodName when button is triggered', () => { ...

Dealing with checked input type='checkbox' in React - A guide

Having a set of checkboxes, some already checked and some to be updated by the user. The issue here is that while the checkboxes render correctly initially, they do not change upon clicking. The 'checked' value does get updated when onChange is t ...

Implementing AJAX in Rails for the new/create action can greatly enhance the user

I have a timeline with event sections on it that allow you to create, view, update, and delete events directly on the timeline page. Currently, the functionality for deleting an event is working smoothly as the delete section refreshes along with the timel ...

Selenium Python not generating event when clicking on element (Key event missing from datafile)

One issue I am facing is that clicking on a button element does not trigger the event. Specifically, while attempting to add an item to the cart, a size must be selected before clicking the "add to cart" button. This problem occurs when using the Chrome he ...

Challenge with timing in slideUp and slideDown animations (jQuery)

The element with the class "heady" is designed to slide up when the document height percentage is below 25%. If you scroll back up, it should reappear after a delay of 1400ms. The problem arises when this action needs to repeat, as the class does not sli ...

Using JavaScript or TypeScript to locate the key and add the value to an array

My dilemma involves an object structured as follows: [{ Date: 01/11/2022, Questionnaire: [ {Title: 'Rating', Ans: '5' }, {Title: 'Comment', Ans: 'Awesome' } ] }, { Date: 01/11/2022, Questionnaire ...

Discover the worth within the outcome obtained from the AJAX request

I have an action that returns a tuple containing a boolean value and a string. How can I retrieve the first boolean value from the result, which could be either true or false? This is the action: public Tuple<bool, string> Check This is the AJAX c ...

Utilize vue.js to cache and stream videos

I'm new to the world of vue.js and I'm facing a certain dilemma. I implemented a caching system using resource-loader that preloads my images and videos and stores the data in an array. Everything is functioning correctly, but now I'm unsur ...

The information from the textarea and select option is not getting through to the email

Despite following suggestions, I am still unable to figure out why my form is not functioning properly. The form I have collects various information such as name, email, phone number, a select option, and a message in a textarea input. I dynamically change ...

Top spot for locating resolve functions in AngularJS

I'm currently in the process of setting up resolves for my admin panel routes and I'm pondering the best way to store them without cluttering my router with methods. Here's what I have so far: when('/admin', { templateUrl: &ap ...

Exploring angularjs and the concept of variable scoping in relation to

Struggling with variable binding in my angularjs/javascript code for uploading images. Can someone help me out? Here is the snippet of my code: var image_source; $scope.uploadedFile = function(element) { reader.onload = function(event) { image_sourc ...

Exploring the characteristics of images in Javascript

I've gone through my code multiple times but I just can't figure out why it's not functioning correctly... Could someone shed some light on this? What am I missing here? The purpose of the code is to allow users to input different values i ...

Timer Tool: JavaScript Countdown Application

I am currently working on a JavaScript countdown timer, but I need help with setting it to only run for 48 hours every time the page is submitted. Right now, when I enter a time, the timer counts down to that specified time. Can someone please assist me ...