0

Making sure I'm going in the right direction

Hi.  I was making some objects with the main editor, and realized to make changes I was going to have to ungroup, change things, regroup in the original order, etc.  I decided I could do it better programmatically.  I have some JavaScript experience, so this looks like fun.

I started making some shapes that are basically tubes.  I made my own tube mesh, and was able to make one of a given size, subtract another from the middle.  I made a ledge around the inside by making another shorter tube with smaller radius and translating it to where it should go, and used unite to put together, all good.

Since then, I've graduated to make "crescent tubes".  Imagine  a cylinder and subtract a same-size cylinder centered on the edge of the first.  Then I make a smaller similar shape and subtract from that to make it all hollow.  That all works.

But then as I try to add a similar crescent-shaped ledge as I did with the cylinders, the output of unite sometimes produces nothing, or a corrupted mesh that looks like one of parts put all mangled.

(Sorry, it is going to get complicated from here.)

Questions:
Does Mesh3D.transform function produce a new Mesh3D, or transform the original and return a reference to the original?

Does Mesh3D.subtract return a mesh with correct windings?

I imagine these crescent shapes are more complex than the cylinders, but I can make these in the editor just fine.

 

Let me show how I have been using these things.  I wanted to make the synchronous and asynchronous operations as similar as possible so that I didn't have to do some operations one way and others another way.  I came up with the following.  The idea is that I will define objects as functions that take a callback.  They may create a mesh or perform an operation on one or more meshes, but they always return using callbacks.  Those objects as functions are the A and B below.

function unite(A,B,callback) {
    B(function(meshB) {
        A(function(meshA) {
            meshA.unite(meshB, callback);
        });
    });
}

function subtract(A,B,callback) {
    B(function(meshB) {
        A(function(meshA) {
            meshA..subtract(meshB, callback);
        });
    });
}

function transform(A, M, callback) {
    A(function(meshA) {
        callback(meshA.transform(M));
    });
}

So a Crescent is defined as follows.  (Cylinder is a function that creates a mesh.)

function Crescent(height, radius, cutRadius, centerDist, numSides, callback) {
    var main = function(callback) { // Define a main part of crescent as a function.
        Cylinder(height, radius, numSides, callback);
    };
    var cut = function(callback) {  // Define the hole as a function.
        Cylinder(height, cutRadius, numSides, callback);
    };
    var xCut = function(callback) {  // Define translated hole as a function.
        var tm = new Core.Matrix3D();
        tm.translation(centerDist, 0, 0);
        transform(cut, tm, callback);
    };
    subtract(main, xCut, callback); // Call this to subtract one part from the other, return through callback.
}

I can build hierarchically, with one object creating functions for several subobjects, and one function call at the end to put together.

I know I have not browsed lots of shape generators, so I have not looked to see how other people do it.  Maybe there is an easier way to use both synchronous and asynchronous operations in similar ways.  If there is a better way to do it, please point me.  But is there something wrong with this approach?

Here are two pictures of the parts, and a picture of the result of doing unite on them.  What went wrong?

 

 

thanks

andy

 

2 comments

Please sign in to leave a comment.