Set Splinepoint Coordinates
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/02/2008 at 12:05, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R10
Platform: Windows ;
Language(s) : C++ ;---------
Hi everyone. I am new to Cinema4D plugin development... I tried a few things with the SDK and started now with a spline object.
The following code belongs to the Class "My Spline" which owns the Funtion "MakeSpline". It inserts a spline with five lines in the structure manager of Cinema 4D. Now i want to set values for the X-Y-Z-Positions of the points the spline is made of. Any ideas how this works?
SplineObject* MySpline::MakeSpline(BaseDocument *doc)
{
SplineObject *spline = SplineObject::Alloc(5,Tcubic);
doc->InsertObject(op,NULL,NULL);
return op;
}
Thx for your help. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/02/2008 at 12:25, xxxxxxxx wrote:
Splines need both points added and a VariableTag:
>
BaseObject\* spline = SplineObject::Alloc(spnum, Tbspline); \> if (!spline) return FALSE; \> baseDocument->InsertObject(spline, NULL, NULL, FALSE); \> baseDocument->AddUndo(UNDO_NEW, spline); \> BaseTag\* tag = spline->MakeVariableTag(Tsegment, lnum); \> if (!tag) return FALSE; \> // This spline is closed (not open-ended) \> spline->GetDataInstance()->SetBool(SPLINEOBJECT_CLOSED,FALSE); \> baseDocument->AddUndo(UNDO_NEW, tag); \> Vector\* vertex = (Vector\* )GeAlloc(spnum\*sizeof(Vector)); \> if (!vertex) return FALSE; \> Vector\* padr = ToPoint(spline)->GetPointW(); \> Segment\* sadr = ToSpline(spline)->GetSegmentW(); \> if (!(sadr && padr)) return FALSE;
From there, you set the xyz values of padr points. Don't forget to all spline->Message(MSG_UDPATE);
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/02/2008 at 13:04, xxxxxxxx wrote:
Man your as fast as lightning Thx for that.
But i don't understand some parts of the source:
1st thing: lnum = The size of the variable tags data? Which value do i have to choose here?
2nd: vertex is a vector and you allocate the number of elements of the spline * size of vector, correct?
3rd: Segments are the parts of a spline between the points, is this correct?
4th: in which of the elements are the coordinates of the points saved now?
Great homepage by the way ... -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/02/2008 at 14:00, xxxxxxxx wrote:
1. lnum is the number of segments for the spline. You can probably get away with 1 segment. In my case, I was adding a set of hair guides to a single spline object - each hair guide as a segment.
2. Yes. Each point is a Vector. Looking at this again, I don't think that that allocation is necessary for you. The point Vectors you need are created by the SplineObject::Alloc() and retrieved into padr.
3. No. Think of Segments as individual 'lines' within the Spline object.
4. padr
So, my code reads 'lines' as segments from a file like this:
>
for (n = 0; subreader->SetLine(treader->GetTokenBuffer()); ++n) \> { \> p = subreader->GetTokenLong(DELIM_FACET); \> if (p > 0L) --p; \> else p += vnum; \> padr->x = vertex[p].x; \> padr->y = vertex[p].y; \> padr->z = vertex[p].z; \> ++padr; \> } \> sadr->closed = FALSE; \> sadr->cnt = n; \> sadr++;
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/02/2008 at 14:41, xxxxxxxx wrote:
Ok sorry, i can't find the functions GetTokenBuffer() and GetTokenLong() and i don't know what kind of object subreader is. As i understand i set the coordinates of the points that belong to the spline with
padr->x = vertex[p].x;
padr->y = vertex[p].y;
padr->z = vertex[p].z;
and this works, but the only result i get is an empty cubic volume, that is limited by the maxima and minima of padr.
So can you please describe me what
subreader->SetLine(treader->GetTokenBuffer()); and
p = subreader->GetTokenLong(DELIM_FACET);
does? -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/02/2008 at 16:10, xxxxxxxx wrote:
Ok this works so far, but it crashes when i change the type of the spline interpolation in the container.
I'll post my code tomorroe. Maybe you have an idea. Have to go to sleep now. It's 1am in Italy
Thx a lot Robert -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/02/2008 at 16:20, xxxxxxxx wrote:
GetTokenBuffer(), GetTokenLong(), subreader are all my own methods/classes for parsing a file buffer (I'm importing a Wavefront .obj file in my code).
Where do you get your input x,y,z point coordinates to set on the spline? That is what padr->x/y/z need to equal. Make sure you are using Real value inputs here.
For changing spline interpolation type, you'll probably need to use:
spline- >SetParameter(DescLevel(SPLINEOBJECT_INTERPOLATION), GeData(SPLINEOBJECT_INTERPOLATION_ADAPTIVE), 0L);
Change SPLINEOBJECT_INTERPOLATION_ADAPTIVE accordingly (see ospline.res in resource:res:description). It may also be that certain interpolations are not possible for certain spline types.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/02/2008 at 05:40, xxxxxxxx wrote:
Hi Robert,
i tried a lot the last day, but it still crashes if i change the interpolation type in the description. I generate a spline with cubic interpolation. If i change the value to linear in the description while runtime, everything is ok, but when i change it back to cubic, the Cinema4D crashes without an error message.
In the following code n is the number of coordinates, so n/3 is the number of points, the spline is generated of and splinecoord[i] is the array where the coordiantes are buffered.> SplineObject* MySpline::MakeSpline(BaseDocument *doc)
>
> {
>
>> SplineObject *spline = SplineObject::Alloc(n/3,Tcubic);
>>
>> doc->InsertObject(spline,NULL,NULL);
>>
>> BaseTag* tag = spline ->MakeVariableTag(Tsegment, n/3);
>>
>> spline->SetParameter(DescLevel(SPLINEOBJECT_INTERPOLATION), GeData(SPLINEOBJECT_INTERPOLATION_ADAPTIVE), 0L);
>>
>> Vector* padr = ToPoint(spline)->GetPointW();
>>
>> Segment* sadr = ToSpline(spline)->GetSegmentW();
>>
>> int i = 0;
>>
>> while(i<n)
>>
>> {
>>
>>> padr->x = splinecoord[i]; spline->Message(MSG_UPDATE);
>>>
>>> i++;
>>>
>>> padr->y = splinecoord[i]; spline->Message(MSG_UPDATE);
>>>
>>> i++;
>>>
>>> padr->z = splinecoord[i]; spline->Message(MSG_UPDATE);
>>>
>>> i++;
>>>
>>> padr++;
>>>
>>> sadr->closed = FALSE;
>>>
>>> sadr->cnt = n/3;
>>>
>>> sadr++;
>>
>> }
>>
>> return spline;
>
> }
Any ideas?
br
Peter -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/02/2008 at 14:17, xxxxxxxx wrote:
Try it like this instead. Note that you only need to call Message(MSG_UPDATE) once after making the changes. I am assuming that splinecoord[] contains an array of component values in the form x,y,z,x',y',z',x'',y'',z''...
>
SplineObject\* spline = SplineObject::Alloc(n/3,Tcubic); \> doc->InsertObject(spline,NULL,NULL); \> spline->MakeVariableTag(Tsegment, 1L); \> spline->SetParameter(DescLevel(SPLINEOBJECT_INTERPOLATION), GeData(SPLINEOBJECT_INTERPOLATION_ADAPTIVE), 0L); \> Vector\* padr = ToPoint(spline)->GetPointW(); \> Segment\* sadr = ToSpline(spline)->GetSegmentW(); \> for (LONG i = 0L; i < n; i += 3) \> { \> padr->x = splinecoord[i]; \> padr->y = splinecoord[i+1]; \> padr->z = splinecoord[i+2]; \> padr++; \> } \> sadr->closed = FALSE; \> sadr->cnt = n/3; \> spline->Message(MSG_UPDATE); \>
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/02/2008 at 00:48, xxxxxxxx wrote:
Yeah thx Robert, now it works. I think the problem was in line
> BaseTag* tag = spline ->MakeVariableTag(Tsegment, n/3);
instead of
> spline->MakeVariableTag(Tsegment, 1L);
But can you explain me the "1L" for the size of the variable tags data? -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/02/2008 at 01:01, xxxxxxxx wrote:
Segments are the number of 'separate' splines in the Spline object. By separate, I conjure the image of a Spline object representing a head of hair (splines) with each hair being a spline segment with its own points (although all the points are stored in the same Vector array). That type of situation is probably the only one inwhich you'd need more than one segment.
For most splines (Spline objects), you'll only need one (1L) segment to contain all of the spline points.
In a round-about way, you could consider the spline segments as polygons and the points those that define each polygon. If you need multiple polygons, you still have one array of points, but organized into a super-structure of multiple polygons, organized into a complete Polygon object. In the same way, a Spline object has one array of points which can be organized into a super-structure of multiple segments and organized into a complete Spline object. It isn't a requirement to divide the points into segments unless it has a structural meaning (hair or a 3D spline patch for instance). In other words, one segment represents a continuous spline made up of the points along it.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/02/2008 at 04:15, xxxxxxxx wrote:
THX !!!