Logo
Toggle Menu
  • home
  • blog
  • about
    • about this site
    • contact
    • privacy policy
  • cinema 4d
    • plugins
    • creating c4d plugins
    • plugin cookbook
    • software
  • models
    • nodes
    • plants 1
    • other models - 1
    • other models - 2
  • osl
    • writing osl shaders
    • osl shaders for download

Creating a new plugin: 7

Making bonds

In the previous article, we finished with two arrays of vectors, named 'splPoints' and 'pepPoints'. Now we need to make those into a single spline. We are also, at some point, going to have to deal with proteins with multiple chains, but for the moment let's get something generated so we can see what it looks like.

The first thing we'll do is add the peptide bond points to the main points array as it's easier to deal with one array rather than two. If we wanted - and we might at some point - to display peptide bonds separately, we can do that, but for the moment one array is enough. But there's another issue. If you think about any polypeptide chain, the amino group of the first amino acid is not involved in the chain at all, and neither is the carboxyl group of the last residue in the chain. Currently our peptide points array contains those two atoms, but we need to exclude both. The code would look like this:

We still have an even number of points in the array, but we don't include the first or last entries in 'pepPoints'. Now we have one array of points, we can call a separate function to create the spline, like so:

In this snippet, 'retNull' is a pointer to a null object which was declared earlier in the function. This null object will be returned to GetVirtualObjects and returned by it to the scene. The reason for doing this is in case we want this function to generate more than one spline and return them both at the same time. I can't tell yet if this is going to be needed, but I'm just thinking ahead.

Creating the spline

The core of the function looks like this:

What this does is create a SplineObject. Although we know the number of points (the number of entries in the array 'splPoints' passed to the function) we already know that this has to be a multi-segment spline, it can't be one long chain - and we can't specify the number of segments when creating the spline. However, it's easy to work out how many we'll need, since each segment must contain two points - so the number required is the number of points divided by two. Then we can call the SDK function SplineObject::ResizeObject() with the number of points and segments we need.

The rest is easy. Get the writable points array from the spline, copy the vectors from 'splPoints' into it, then get the writable segments array and for each one set the segment to contain two points and not to be closed.

We could return the spline at this point and it would work, but there's a bit more we should do. I won't bother showing code for this, it's all straightforward stuff, but if we want to generate geometry the steps are:

  1. create a Circle spline primitive to be a profile spline
  2. create a Sweep object and set its properties, including colour
  3. insert the Circle and our created spline under the Sweep object
  4. return the Sweep object to the calling function

We might want the spline to be rendered without adding geometry, but that is rather more complex so we can add that later if necessary.

The result

Here's our glucagon molecule including bonds:

Glucagon including bonds.

There's a problem here. Take a close look at the end of the chain in the bottom right-hand corner. There's an oxygen atom (red sphere) which isn't connected to anything! There's a reason for that which we need to fix, and we also need to handle multi-chain proteins. Plus there are also a couple of other issues which need to be dealt with. We'll do that in the next two articles.

Page last updated May 31st 2026

Blog articles

Creating a new plugin: 8 (June 4th 2026)

Creating a new plugin: 7 (May 31st 2026)

Creating a new plugin: 6 (May 28th 2026)

Creating a new plugin: 5 (May 26th 2026)

Creating a new plugin: 4 (May 23rd 2026)

Creating a new plugin: 3 (May 22nd 2026)

Creating a new plugin: 2 (May 20th 2026)

Creating a new plugin: 1 (May 17th 2026)

The 'Space' plugins (May 7th 2026)

Creating PBR materials (March 24th 2026)

Data Storage - Then and Now (March 6th 2026)

Old Poser assets (March 2nd 2026)

More Noise, please (January 18th 2026)

Using GIT in VS 2022 (December 26th 2025)

Handling missing plugins (December 12th 2025)

Plugin compatibility with R2026 (November 24th 2025)

Affinity is now free! (November 3rd 2025)

World Creator 2025.1 (October 10th 2025)

So that was Cinema R2026? (September 19th 2025)

How to browse 3D assets (August 24th 2025)

Using Unity assets in Cinema 4D (August 15th 2025)

Plant Factory->Cinema 4D->World Creator (August 12th 2025)

Viewing glTF files (August 9th 2025)

Tessellation part 2 (August 5th 2025)

Shader writing with OSL - 3 (July 11th 2025)

Tessellation (June 23rd 2025)

Creating plants for C4D (June 15th 2025)

Adobe alternatives (May 28th 2025)

Using Graswald assets in C4D (May 7th 2025)

Which Mac for plugin development? (May 3rd 2025)

Why do plugin writers do it? (April 11th 2025)

Updating StarScape (February 26th 2025)

Using Cinema 4D shaders in Redshift (January 31st 2025)

PHP and MySQL (December 19th 2024)

Shader writing with OSL - 2 (November 11th 2024)

Shader writing with OSL (October 29th 2024)

StarScape (September 25th 2024)

Converting plugins from C4D 2024 to 2025 (September 16th 2024)

Cinema 4D 2025 and macOS plugins (September 15th 2025)

© 2021-2025 Microbion. All Rights Reserved.